Sign in to follow this  
Gr1ph00n

dll function not found

Recommended Posts

Hello, i am working on a lua module, i need to load a function from another dll which is already loaded. 'GetModuleHandle' returns a not NULL value, so i guess the dll is found, but when i call 'GetProcAddress' it returns a NULL value so i cannot call my function. Of course, i know the function is there and exported, but i cannot understand why 'GetProcAddress' does not find it. Could You help me?

Share this post


Link to post
Share on other sites
It's possible that the function has a decorated name (its name has been changed by the compiler / linker). The only way to ensure that a function's name is preserved (in C++) is to do the following:


extern "C" void DontChangeMyNamePlease()
{

}


..And then use GetProcAddress("DontChangeMyNamePlease").

Share this post


Link to post
Share on other sites
Tried, but it's the same, the function i want to call is still not found. Here is my code:


typedef void (*PTR_FUNCTION_ADDRESS)(const char *, ...);
PTR_FUNCTION_ADDRESS func = NULL;



HMODULE dll = GetModuleHandle("my dll");
if (dll == NULL)
{
lua_pushstring(L, "dll is NULL");
lua_error(L);
return -1;
}
func = (PTR_FUNCTION_ADDRESS)GetProcAddress(dll, "Msg");


The dll is loaded, since no error is given, but if when i want to call the function, this condition is not met: (func != NULL). Maybe do i have this issue 'cause i am working on a 3rd part dll and i do not have neither an header nor a .lib file ??

Share this post


Link to post
Share on other sites
If you're using someone else's DLL, and the function has a decorated name, then you have a problem. You're either going to have to find what its decorated name is (using a debugger or a hex editor) OR find out what its proc address is manually (you're going to have to do this if the function hasn't been exported).

Share this post


Link to post
Share on other sites
Hi, thanks to the tool posted by plastique, i found that the decorated name of my function is
?Msg@@YAXPBDZZ
instead its undecorated name is
void Msg(char const *,...)

How should i proceed to make it working ?

Share this post


Link to post
Share on other sites
Quote:
Original post by Gr1ph00n
Hi, thanks to the tool posted by plastique, i found that the decorated name of my function is
?Msg@@YAXPBDZZ
instead its undecorated name is
void Msg(char const *,...)

How should i proceed to make it working ?


That's bad. If the dll gets updated then the decoration will change.
This is why the old "C" style is good.
Also, COM was invented for this reason (1 of the reasons).

Share this post


Link to post
Share on other sites
The DLL's entry points are decorated because it has an accompanying LIB file which the OP does not have access to (since the DLL wasn't made to be used by him). One can only speculate what he's trying to do ;)

Share this post


Link to post
Share on other sites

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