Thread: Types...

  1. #1
    Registered User
    Join Date
    Jan 2005


    I'm trying to make my own short version of the windows header stuff I use, like this for an MessageBox app:

    #ifdef strict
    struct handtp { int unused; };
    typedef struct handtp* hand;
    #define hand void*
    #define wusr __declspec(dllimport)
    #define wapi __stdcall
    #define pch const char *
    #define uint unsigned int
    wusr int wapi MessageBoxA (hand, pch, pch, uint);
    int __stdcall WinMain (hand hInstance, hand hPrev, pch cmdline, uint showhow)
    	uint unsg = 0;
    	hand hnul = 0;
    	pch myadr;
    	char mystr[] = "mycapt";
    	myadr = &mystr[0];
    	MessageBoxA(hnul, myadr, myadr, unsg);
    	return 0;
    Why does it not work? I'm getting an unresolved external for the MessageBoxA.

  2. #2
    Join Date
    Jan 2002
    If you're not linking the required libs at build time then you need to get a pointer to the dll function at runtime. For that, you need LoadLibrary (to load the dll into your exe address space - don't forget to FreeLibrary when done) and GetProcAddress to return a pointer to the function you need; forward declaration is not enough, you should typedef a MessageBoxA function pointer.

    There's an example of runtime dynamic linking here.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Registered User
    Join Date
    Jan 2005
    The right lib User32.lib is attached, the problem was my wusr definition didn't include extern "c". Now it works. However, there are debug symbols for my app but not for the DLLs. Where do debug symbols come from?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. invalid types 'int[int]' for array subscript
    By kolistivra in forum C++ Programming
    Replies: 6
    Last Post: 12-11-2010, 12:57 PM
  2. Replies: 6
    Last Post: 08-23-2008, 01:16 PM
  3. The Interactive Animation - my first released C program
    By ulillillia in forum A Brief History of
    Replies: 48
    Last Post: 05-10-2007, 02:25 AM
  4. Types, Integral Types, Bytes?!?!?!
    By Kaidao in forum C++ Programming
    Replies: 3
    Last Post: 03-21-2006, 08:15 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM