Calling DLL fucn with ShortString param fails
From: Muzzy (leyandrew_at_yahoo.com)
Date: 12/31/03
- Previous message: Les Pawelczyk: "Re: Make a program unkillalbe"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 31 Dec 2003 02:17:01 -0500
Hi,
I have a .DLL library providing me with a function which returns false
or true depending on some conditions. It's declared in DLL as:
//----------------------
extern "C" __declspec(dllexport) _stdcall bool VPNStart();
//----------------------
And i call it from an app (using func Start):
//----------------------
typedef bool (*HVPNSTART)(void);
bool Start()
{
HINSTANCE hLib = LoadLibrary("MyDLL.DLL");
if (hLib == NULL) {
MessageBox(0, "Unable to Load MyDLL.DLL", "Error", MB_OK);
return false;
}
HVPNSTART vs = (HVPNSTART)GetProcAddress(hLib, "VPNStart");
if (vs == NULL) {
MessageBox(0, "Failed calling VPNStart", "Error", MB_OK);
FreeLibrary(hLib);
return false;
}
bool result = vs();
//MessageBox(0, "VPNStart Loaded!", "SUCCESS", MB_OK);
if (result) MessageBox(0, "TRUE", "RESULT", MB_OK);
else MessageBox(0, "FALSE", "RESULT", MB_OK);
FreeLibrary(hLib);
return result;
}
//----------------------
Everything works perfect until... i add an argument to the DLL fucn
VPNStart:
//----------------------
extern "C" __declspec(dllexport) _stdcall bool VPNStart();
//----------------------
So i change the main app code:
//----------------------
typedef bool (*HVPNSTART)(ShortString);
bool Start( ShortString s ) {...}
It starts to act WEIRD!!! When i trace (F8 -:)) thru the 'Start()' func
i see the following - after i load library, i write down it's address,
say ':013A000'.
But after the line 'result = vs(s)', the hLib address changes to
':8000004', and of course after i 'FreeLibrary' and return, it gives me
an access violation... How come the address of library handle could change?
I also tried to pass char* instead of ShortString, doesn't work also...
Any ideas, PLEASE!!!
Thank you,
Andrey
- Previous message: Les Pawelczyk: "Re: Make a program unkillalbe"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|