Thread: Callback functions from dll

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    10

    Question Callback functions from dll

    Hi.

    I've been trying to load a function from a dll, what I did was this:

    Code:
    typedef LRESULT (CALLBACK *pfKeyProc)(int code, WPARAM wParam, LPARAM lParam);
    HINSTANCE dll = LoadLibrary(someLib.dll);
    pfKeyProc pfKey;
    pfKey = (pfKeyProc)GetProcAddress((HMODULE)(dll), "KeyboardProc");
    And the definition in the .dll looked like this :
    Code:
    extern "C" __declspec(dllexport) LRESULT CALLBACK KeyboardProc(int code, WPARAM wParam, LPARAM lParam);
    It didn't load correctly, but if I removed CALLBACK from the definition in the .dll it did. Should I define my typedef in some other way or could I just omit 'CALLBACK' from the defintion ?
    (Or am I doing it all wrong ?)
    Using : MSVS .NET 2003
    OS : Windows XP

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    One possible solution is to replace CALLBACK with __stdcall.

    Kuphryn

  3. #3
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Why can't I GetProcAddress a function I dllexport'ed?

    You need to compile your DLL with a DEF file. Otherwise, function names will be decorated.

    Alternatively, you can use (not preferred, processor dependent):
    Code:
    pfKey = (pfKeyProc) GetProcAddress(dll, "_KeyboardProc@12");

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. non-MFC DLL with MFC app question.
    By Kempelen in forum Windows Programming
    Replies: 10
    Last Post: 08-20-2008, 07:11 AM
  2. Replies: 16
    Last Post: 03-08-2008, 05:42 AM
  3. gluTess functions and callback problems
    By uldaman in forum Game Programming
    Replies: 5
    Last Post: 02-28-2008, 09:24 AM
  4. dll communicating between each other
    By cloudy in forum C++ Programming
    Replies: 5
    Last Post: 06-17-2005, 02:20 AM
  5. Knowing the Functions a DLL is offering
    By vsriharsha in forum Windows Programming
    Replies: 1
    Last Post: 04-10-2002, 05:16 AM