Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
Hello , once again i need some help.
So i have few dlls in one solution each of them exports some functions , which are declared with
C++
extern "C" <type> __stdcall <name>(<params>)
and each of them uses .def file for the exports.
The pointers are
C++
typedef <type> (CALLBACK * <name> )(<type of params>)


The problem is with one of the dlls , which are loaded with LoadLibrary.
I know the signatures of the functions ,i use GetProcAddress() , i used the right number and types of paramethers , no errors are thrown but the functions of the dll arent't executed. The other which are using the same methods of creating function pointers and using them described above are working properly.

Because i have some old versions of the dlls i used dumpbin /export and i saw something strange.
In the older version of the dll there is a

name of the function = @ILT+some number(_name of the function@number)

and for the new dll i see only <name of="" the="" function=""> without the rest
I know that the function pointer should get that _name of the function @ number which is some encoding of the function's name in the memory but it doesn't.

I think maybe i did something wrong with the creation of the dll maybe a option or something but i have no idea what .
Any ideas are welcome.
Thanks a lot for the help ... again :)

P.S
When i checked the dll with dumpbin /headers i noticed that 2 header sections are missing : .idata and .textbss can someone give me more info about what exactly is a header in a dll and how should it be created

P.S 2
 HMODULE hDllHandle = LoadLibrary(TEXT(strDllName));
 if (hDllHandle != NULL)
 {
      //declarations of few local variables  
      
     PFuncA  pFunctionA = (PFuncA)GetProcAddress(hDllHandle, TEXT("FunctionA"));
     DWORD errSetParam = GetLastError(); 
	
     PFuncB pFunctionB = (PFuncB)GetProcAddress(hDllHandle, TEXT("FunctionB"));
     DWORD errExecute = GetLastError();

     ASSERT(pFunctionA != NULL);
     ASSERT(pFunctionB != NULL);
 //some initialization
 
    pFunctionA((char* const)ParamName.GetString(), (char* const)ParamValue.GetString());
 
    nFileUpdated = pFunctionB((char* const) param1.GetString(),(char* const)param2.GetString(), (char* const)param3.GetString(),(char* const)param4.GetString(),(char* const)param5.GetString(),
(char* const)param6.GetString(),(char* const)param7.GetString(),(char* const)param8.GetString(),param9);
 
// and the definition which are before this code are :
 
typedef int (CALLBACK* PFuncA)(LPCSTR, LPCSTR);

 typedef int (CALLBACK* PFuncB) (LPCSTR, LPCSTR, LPCSTR, \
                             LPCSTR, LPCSTR, \
                             LPCSTR, LPCSTR, LPCSTR, bool); 
 }
Posted
Updated 2-Aug-12 3:09am
v3
Comments
enhzflep 2-Aug-12 5:36am    
Looks like name mangling to me. That is to say - it sounds like the offending dll may not have the extern "C" prefacing it. When compiled with a c++ compiler, the function names are altered internally by either the compiler/linker - I forget.

Can you check the source of the dlls to ensure that the way the functions are declared is consistent?
Argonia 2-Aug-12 5:45am    
yes i am sure i just checked it
Malli_S 2-Aug-12 6:35am    
Check for any overloaded function of the same name. Or there could be error/mismatch in the def file.
Argonia 2-Aug-12 6:46am    
Checked nothing . I tried to enumerate the functions in .def file with @1-N where N is the number of the exported functions . Still GetProcAddress() returns invalid not null address with no function in it
GetLastError() returns 0
pasztorpisti 2-Aug-12 8:36am    
If the function declaration and calling convenction is the same in your dll and in your pointer declaration, then all you have to do is fixing the name of the function either on the DLL side or on the user side wher you call GetProcAddress().
_<funcname>@number is the name mangling used for stdcall functions - the number is the size of the parameters that is cleant up from the stack by the function, since its stdcall.
I think using such a name with GetProcAddress() is self suicide (because of maintenance) especially if oyu have lot of function calls so use extern "C" when you are loading the DLL by yourself. With static linking its ok to use stdcall name mangling.

Anyway, what language do you use and how many exported functions do you have?

You probably have to declare type like this
C++
extern "C" {
typedef <type> (CALLBACK * <name> )(<type of="" params="">)
}
 
Share this answer
 
v3
Comments
Argonia 2-Aug-12 6:21am    
still the same . The functions doesn't get called
armagedescu 2-Aug-12 8:22am    
If function does not get called, then there is other problem. If the signature is wrong, then function usually get called, but it crashes at runtime. But if it does not get called, then problem is elsewhere. The dll have to declare function with __declspec(dllexport) but application which loads the dll have to declare it as __declspec(dllimport).
Anyway, try to debug and see if dll is still loaded when you want to call the function, and what exactly is called when you call the function. Try to debug in disassembly, and see what happens after ASM call is instruction is executed. You also can open memory window and enter the address of function.
In many times GetProcAddress can get the address of a jmp instruction. In that case you have to see where this it jumps, what is on the memory.
Refresh your workspace using you CVS client. ;-)
 
Share this answer
 
Comments
Argonia 3-Aug-12 2:13am    
I am an absolute idiot . The problem was in the post build events . We are using env folder and in these events the built dlls were copied into the folder with the old names.Thanks to all who answered my question espetially pasztorpisti :)
Malli_S 3-Aug-12 3:08am    
lol !
But it was nice discussion.
pasztorpisti 3-Aug-12 7:22am    
:-) this happens sometimes, especially with multiple workspaces and complex build systems.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900