home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / os / mswindo / programm / misc / 1540 < prev    next >
Encoding:
Text File  |  1992-08-27  |  2.4 KB  |  63 lines

  1. Newsgroups: comp.os.ms-windows.programmer.misc
  2. Path: sparky!uunet!microsoft!hexnut!matts
  3. From: matts@microsoft.com (Matt Saettler)
  4. Subject: Re: Weird problem with MMAPI and STRICT
  5. Message-ID: <1992Aug27.230524.19845@microsoft.com>
  6. Date: 27 Aug 92 23:05:24 GMT
  7. Organization: Microsoft Corporation
  8. References: <6447@kielouta.fi>
  9. Lines: 52
  10.  
  11. In article <6447@kielouta.fi> jere@uta.fi (Jere K{pyaho) writes:
  12. >Can anyone figure out what is happening here:
  13. >
  14. >This is Win3.1, Borland C++ 3.1. I have the following, very
  15. >simple piece of code, written in straight C, which uses the
  16. >Windows 3.1 Multimedia API:
  17. >
  18. >#include <windows.h>
  19. >#include <mmsystem.h>
  20. >...
  21. >HMIDIOUT hMidiOut;    /* handle to MIDI output device */
  22. >UINT uiMidiOut;        /* MIDI output device ID */
  23. >int iReturn;        /* call return value */
  24. >
  25. >iReturn = midiOutOpen( (LPHMIDIOUT) &hMidiOut, uiMidiOut,
  26. >            (DWORD) hwnd, 0L, CALLBACK_WINDOW );
  27. >
  28. >Here, uiMidiOut has been initialized to a valid MIDI device ID -
  29. >this I checked. The hwnd is just a window handle -- I don't
  30. >think it makes any difference even if it is actually a dialog:
  31. >a window is a window, right? So I could direct the MIDI messages
  32. >to a scrollbar if I felt like it. ;-)
  33. >
  34. >Anyway, what happens is that when I compile this stuff with
  35. >WIN31 and STRICT, the midiOutOpen() call bombs, giving me
  36. >an Error 11: Invalid parameter passed to a system function.
  37. >The funny thing is that when I compile it _without_ STRICT,
  38. >the call works OK.
  39. >
  40. >So what's the invalid parameter? The obvious workaround is
  41. >to compile without STRICT, but then you lose many other
  42. >nice checks for stupid errors.
  43. >
  44. If you compile with MSC 7.00 with warnings on, you will get a warning:
  45. "converting near pointer to long integer".  Looks like the Borland
  46. compiler does not give similar warnings.
  47.  
  48. The near pointer is the hwnd.  To allow type checking, STRICT defines
  49. the types as pointers so that the C compiler can do parameter and other
  50. type checking.  When you cast the near pointer to a DWORD, the compiler
  51. (correctly) first casts it to a far pointer.  This results in the hiword
  52. containing DS instead of NULL, as you intended.  The solution is to
  53. cast the hwnd first to a UINT (to be portable to 32-bit windows) and
  54. then to the DWORD like this:
  55.  
  56. iReturn = midiOutOpen( (LPHMIDIOUT) &hMidiOut, uiMidiOut,
  57.             (DWORD) (UINT) hwnd, 0L, CALLBACK_WINDOW );
  58.  
  59.  
  60. Matt Saettler/Microsoft Multimedia
  61. ----------------
  62. I speak only for myself....
  63.