home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.ms-windows.programmer.misc
- Path: sparky!uunet!microsoft!hexnut!matts
- From: matts@microsoft.com (Matt Saettler)
- Subject: Re: Weird problem with MMAPI and STRICT
- Message-ID: <1992Aug27.230524.19845@microsoft.com>
- Date: 27 Aug 92 23:05:24 GMT
- Organization: Microsoft Corporation
- References: <6447@kielouta.fi>
- Lines: 52
-
- In article <6447@kielouta.fi> jere@uta.fi (Jere K{pyaho) writes:
- >Can anyone figure out what is happening here:
- >
- >This is Win3.1, Borland C++ 3.1. I have the following, very
- >simple piece of code, written in straight C, which uses the
- >Windows 3.1 Multimedia API:
- >
- >#include <windows.h>
- >#include <mmsystem.h>
- >...
- >HMIDIOUT hMidiOut; /* handle to MIDI output device */
- >UINT uiMidiOut; /* MIDI output device ID */
- >int iReturn; /* call return value */
- >
- >iReturn = midiOutOpen( (LPHMIDIOUT) &hMidiOut, uiMidiOut,
- > (DWORD) hwnd, 0L, CALLBACK_WINDOW );
- >
- >Here, uiMidiOut has been initialized to a valid MIDI device ID -
- >this I checked. The hwnd is just a window handle -- I don't
- >think it makes any difference even if it is actually a dialog:
- >a window is a window, right? So I could direct the MIDI messages
- >to a scrollbar if I felt like it. ;-)
- >
- >Anyway, what happens is that when I compile this stuff with
- >WIN31 and STRICT, the midiOutOpen() call bombs, giving me
- >an Error 11: Invalid parameter passed to a system function.
- >The funny thing is that when I compile it _without_ STRICT,
- >the call works OK.
- >
- >So what's the invalid parameter? The obvious workaround is
- >to compile without STRICT, but then you lose many other
- >nice checks for stupid errors.
- >
- If you compile with MSC 7.00 with warnings on, you will get a warning:
- "converting near pointer to long integer". Looks like the Borland
- compiler does not give similar warnings.
-
- The near pointer is the hwnd. To allow type checking, STRICT defines
- the types as pointers so that the C compiler can do parameter and other
- type checking. When you cast the near pointer to a DWORD, the compiler
- (correctly) first casts it to a far pointer. This results in the hiword
- containing DS instead of NULL, as you intended. The solution is to
- cast the hwnd first to a UINT (to be portable to 32-bit windows) and
- then to the DWORD like this:
-
- iReturn = midiOutOpen( (LPHMIDIOUT) &hMidiOut, uiMidiOut,
- (DWORD) (UINT) hwnd, 0L, CALLBACK_WINDOW );
-
-
- Matt Saettler/Microsoft Multimedia
- ----------------
- I speak only for myself....
-