I made a dll in VC 2003 .
When I load this dll the first time using Loadlibrary API I get an error ,
but if I try to load the dll again the Loadlibrary work !
I tried also to load the dll using VB declaring the functions in a module
( and so without using the api Loadlibrary ) but I get the same problem. In
the first access to a dll function I get an error and the second time it
works.
I tried also in VC using the api LoadlibraryEx and if I disable the
entrypoint call it works , but if I compile the dll without and entrypoint
function and I try to load it using the Loadlibrary ( with the call to the
entrypoint) it does not work.
So my suspect is there is a problem in some global vars in the dll ,pheraps
a problem with some constructors, but I don't know how to identify it .
Any suggestion?
Above there is the code I use to load the dll.
int main(int argc, char* argv[])
{
void *h;
//h=LoadLibraryEx(EdtFile->Text.c_str(),0,1);
h=LoadLibrary("Test.dll");
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
// Display the string.
MessageBox( NULL, (char *)lpMsgBuf, "GetLastError",
MB_OK|MB_ICONINFORMATION );
// Free the buffer.
LocalFree( lpMsgBuf );
ShowMessage(AnsiString((long)h));
//secondo tentativo---------------------------
h=LoadLibrary("Test.dll");
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
// Display the string.
MessageBox( NULL, (char *)lpMsgBuf, "GetLastError",
MB_OK|MB_ICONINFORMATION );
// Free the buffer.
LocalFree( lpMsgBuf );
ShowMessage(AnsiString((long)h));
return 0;
}
//---------------------------------------------------------------------------
Thank you , Denis.