warning: assignment from a incompatible pointer type

This is a discussion on warning: assignment from a incompatible pointer type within the C Programming forums, part of the General Programming Boards category; This: Code: #include <mmsystem.h> ... MMRESULT (_stdcall *fpMidiOutOpen)(LPHMIDIOUT,unsigned int,unsigned long,unsigned long,unsigned long); MMRESULT (_stdcall *fpMidiOutShortMsg)(HMIDIOUT, DWORD); MMRESULT (_stdcall *fpMidiOutClose)(HMIDIOUT); ... ...

  1. #1
    Registered User
    Join Date
    Sep 2007
    Location
    Omaha, NE
    Posts
    4

    warning: assignment from a incompatible pointer type

    This:

    Code:
    #include <mmsystem.h>
    ...
    MMRESULT (_stdcall *fpMidiOutOpen)(LPHMIDIOUT,unsigned int,unsigned long,unsigned long,unsigned long);
    MMRESULT (_stdcall *fpMidiOutShortMsg)(HMIDIOUT, DWORD);
    MMRESULT (_stdcall *fpMidiOutClose)(HMIDIOUT);
    ...
        fpMidiOutOpen=GetProcAddress(hLibrary,"midiOutOpen");
        fpMidiOutShortMsg = GetProcAddress(hLibrary,"midiOutShortMsg");
        fpMidiOutClose= GetProcAddress(hLibrary,"midiOutClose");
    Produces "warning: assignment from a incompatible pointer type"

    I Googled, and apparently I'm not supposed to point to DWORD or ULONG because of the fixed width? I'm a little lost with pointers.

    I found an article that said you should use INT_PTR, UINT_PTR, DWORD_PTR, etc. instead, but that hasn't helped.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You probably want to typedef your pointer types - here's some that I made for a MS Cards library, then you cast the result of GetProcAddress to the type you expect.
    Code:
    typedef bool (__stdcall *CDTInit)(int *width, int *height);
    typedef void (__stdcall *CDTTerm)(void);
    typedef bool (__stdcall *CDTDraw)(HDC hdc, int x, int y, int index, int style, int color );
    ...
    	cardFuncs.cdtInit = (CDTInit)GetProcAddress(h, "cdtInit");
    	cardFuncs.cdtTerm = (CDTTerm)GetProcAddress(h, "cdtTerm");
    	cardFuncs.cdtDraw = (CDTDraw)GetProcAddress(h, "cdtDraw");
    ...
    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Sep 2007
    Location
    Omaha, NE
    Posts
    4
    Quote Originally Posted by matsp View Post
    You probably want to typedef your pointer types - here's some that I made for a MS Cards library, then you cast the result of GetProcAddress to the type you expect.
    Code:
    typedef bool (__stdcall *CDTInit)(int *width, int *height);
    typedef void (__stdcall *CDTTerm)(void);
    typedef bool (__stdcall *CDTDraw)(HDC hdc, int x, int y, int index, int style, int color );
    ...
    	cardFuncs.cdtInit = (CDTInit)GetProcAddress(h, "cdtInit");
    	cardFuncs.cdtTerm = (CDTTerm)GetProcAddress(h, "cdtTerm");
    	cardFuncs.cdtDraw = (CDTDraw)GetProcAddress(h, "cdtDraw");
    ...
    --
    Mats
    gcc is telling me I can't declare a bool before *

    Also, to do this, won't I also then need to declare something like cardFuncs as a structure?

    How you declare void cdtTerm in a struct? I thought you couldn't have void in a struct.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by enderandrew View Post
    gcc is telling me I can't declare a bool before *

    Also, to do this, won't I also then need to declare something like cardFuncs as a structure?

    How you declare void cdtTerm in a struct? I thought you couldn't have void in a struct.
    Well, I was just meaning that to be used as a example of using typedef for function pointers, not that you should copy and paste that into your code.

    I have no idea why gcc is complaining about bool - are you sure that __stdcall is correct?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Jul 2007
    Posts
    151
    what are those codes for . I am wondering.

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    osumzafa, can you be a bit more precise?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User
    Join Date
    Sep 2007
    Location
    Omaha, NE
    Posts
    4
    I tried the following:

    Code:
    typedef bool (_stdcall *fpMidiOutOpen)(LPHMIDIOUT,unsigned int,unsigned long,unsigned long,unsigned long);
    typedef bool (_stdcall *fpMidiOutShortMsg)(HMIDIOUT, DWORD);
    typedef bool (_stdcall *fpMidiOutClose)(HMIDIOUT);
    Except, gcc threw an error that I could declare bool before *

    I've got a fresh install of MinGW, and I have no reason to thing that _stdcall would be somehow screwed up.

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by enderandrew View Post
    I tried the following:

    Code:
    typedef bool (_stdcall *fpMidiOutOpen)(LPHMIDIOUT,unsigned int,unsigned long,unsigned long,unsigned long);
    typedef bool (_stdcall *fpMidiOutShortMsg)(HMIDIOUT, DWORD);
    typedef bool (_stdcall *fpMidiOutClose)(HMIDIOUT);
    Except, gcc threw an error that I could declare bool before *

    I've got a fresh install of MinGW, and I have no reason to thing that _stdcall would be somehow screwed up.
    But fpMidiOutShort, according to your previous declaration:
    Code:
    MMRESULT (_stdcall *fpMidiOutOpen)...
    doesn't return a bool, but an MMRESULT - not that I think that will change anything. However, chaning __stdcall to _stdcall (single underscore instead of double) would potentially make a difference.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    Registered User
    Join Date
    Jul 2007
    Posts
    151
    Yes I can , what is mmsystem.h library for?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 07-10-2008, 04:45 PM
  2. Incompatible Pointer Type warnings
    By trillianjedi in forum C Programming
    Replies: 3
    Last Post: 06-11-2008, 05:16 PM
  3. Incompatible Pointer Type Warning
    By kwikness in forum C Programming
    Replies: 5
    Last Post: 10-30-2007, 07:14 PM
  4. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 04:36 AM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 06:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21