Types...

This is a discussion on Types... within the Windows Programming forums, part of the Platform Specific Boards category; I'm trying to make my own short version of the windows header stuff I use, like this for an MessageBox ...

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    70

    Types...

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

    Code:
    #ifdef strict
    struct handtp { int unused; };
    typedef struct handtp* hand;
    #else
    #define hand void*
    #endif
    
    #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
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    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
    Posts
    70
    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, 02:16 PM
  3. The Interactive Animation - my first released C program
    By ulillillia in forum A Brief History of Cprogramming.com
    Replies: 48
    Last Post: 05-10-2007, 03: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, 07:39 AM

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