Thread: Using custom made DLLs

  1. #1
    Codebot
    Join Date
    Jun 2004
    Location
    Toronto
    Posts
    195

    Using custom made DLLs

    Hi. Im having a bit of trouble getting into my owkr DLLs from other programs. Here is one of the functions i use inside teh DLL:

    Code:
    #define DllExport   __declspec( dllexport )
    
    DllExport void SetHandle(HWND App)
    {
    ...some code....
    }
    Here is my main program where i load the DLL and try to use the funciton above:

    Code:
    typedef void (WINAPI *SDKSETHANDLE)(HWND);
    
    .....
    
    SDKSETHANDLE SetHandle;
    
    SDKModule = LoadLibrary("MyDLL.dll");
    SetHandle = (SDKSETHANDLE) GetProcAddress(SDKModule, "SetHandle");
    SetHandle(Hwnd);
    the variable SetHandle is returning as NULL, so theres something weird happening in between the two. SDKModule is not null, so it obviously loaded it correctly. The DLL is in the same directory as my EXE.

    Cany anyone shed some light on this, im stumped!!!
    Founder and avid member of the Internationsl Typo Associateion

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    In the DLL, try defining your function as:
    Code:
    extern "C" __declspec(dllexport) void SetHandle(HWND App)
    {
    }
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Alternatively, you can use a .def file, which IIRC should look something like:
    Code:
    LIBRARY MyLibraryName
    EXPORTS
      SetHandle
      MyOtherFunction
      //etc.
    In visual studio, at least, there's a linker option to specify the .def file the project should use.

    I think someone gave me an example a while ago of a .def file, so you might want to search the board.
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  4. #4
    Codebot
    Join Date
    Jun 2004
    Location
    Toronto
    Posts
    195
    The .def file worked.
    Thanks
    Founder and avid member of the Internationsl Typo Associateion

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need someone familiar with DLLs
    By Kurisu33 in forum Windows Programming
    Replies: 9
    Last Post: 09-14-2006, 02:01 AM
  2. standart dlls
    By keeper in forum C++ Programming
    Replies: 3
    Last Post: 07-05-2006, 07:32 PM
  3. accessing a DLL's resources...
    By dug in forum Windows Programming
    Replies: 9
    Last Post: 12-13-2005, 05:04 AM
  4. Can't load string from resource DLL's string table
    By s_k in forum Windows Programming
    Replies: 4
    Last Post: 07-15-2003, 06:43 AM
  5. question about DLL's and class functions
    By btq in forum Windows Programming
    Replies: 2
    Last Post: 02-25-2003, 06:08 AM