Sign in to follow this  

A mess with DLLs

This topic is 4858 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, Im working on some registration stuff with Wise Installation System. In their scripting, you are allowed to call DLL functions written in C. I know very little about Dynamic Link Libraries. I'm trying to just call a simple function right now from the sample dll that comes with Dev-C++ which looks like this thedll.h
#ifndef _DLL_H_
#define _DLL_H_

#if BUILDING_DLL
# define DLLIMPORT __declspec (dllexport)
#else /* Not BUILDING_DLL */
# define DLLIMPORT __declspec (dllimport)
#endif /* Not BUILDING_DLL */

//changed from DLLIMPORT so I know what it does
__declspec(dllexport) void HelloWorld();


#endif /* _DLL_H_ */

thedll.c
/* Replace "dll.h" with the name of your header */
#include "dll.h"
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>

__declspec (dllexport) void HelloWorld()
{
    MessageBox (0, "Hello!\n", "Hi", MB_ICONINFORMATION);
}


BOOL APIENTRY DllMain (HINSTANCE hInst     /* Library instance handle. */ ,
                       DWORD reason        /* Reason this function is being called. */ ,
                       LPVOID reserved     /* Not used. */ )
{
    switch (reason)
    {
      case DLL_PROCESS_ATTACH:
        break;

      case DLL_PROCESS_DETACH:
        break;

      case DLL_THREAD_ATTACH:
        break;

      case DLL_THREAD_DETACH:
        break;
    }

    /* Returns TRUE on success, FALSE on failure */
    return TRUE;
}

If you look in thedll.c it has a big DllMain thing, I have no idea what that is even for...but anyway In Wise the script command I use is 'Call DLL Function' But when testing I get the following error: "Could not Load the DLL Library, c:\THEPATH\thedll.dll (HelloWorld()). The specified procedure couldn't be found" I'm wondering if this is because HelloWorld is not actually a procedure.. Well if anyone has any idea on where I should start or where to go for some more info on such things, don't hesitate to post :-)

Share this post


Link to post
Share on other sites
I'm going to guess that you're suffering from a name-mangling problem. That is to say, that the name you specified in your GetProcAddress() call doesn't match with the actual symbol name exported by the DLL, which is probably decorated like _HelloWorld@0 or something like that (depends on the compiler). The usual response to to declare the exported function as extern "C" or to use a .DEF file when creating the DLL to specify the export name.

Share this post


Link to post
Share on other sites

This topic is 4858 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this