Passing session to DLL? Error "Not logged on"?

rakgol_a

Member²
when I pass a session from the exe form to a DLL for.

I use C++ Builder 5 Update Pack 1 on Windows 2000.

Sample DLL code I use.

#pragma argsused
extern "C" void __declspec(dllexport) __stdcall ShowDiscrepancyQueueHandler(TOracleSession *globalSession);

void __stdcall ShowDiscrepancyQueueHandler(TOracleSession *globalSession)
{
TfrmDQHandler *frmDQHandler = new TfrmDQHandler(NULL);
frmDQHandler->OracleSession1->Connected = false;
frmDQHandler->OracleSession1 = globalSession;
frmDQHandler->Show();
}

int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
return 1;
}
//---------------------------------------------------------------------------

I call the ShowDiscrepancyQueueHandlerin the main exe that has a session that has logged on.
In formshow of the DLL(frmDQHandler) I tested the connection which return true.

TCheckConnectionResult r = OracleSession1->CheckConnection(false);
switch(r)
{
case ccOK: ShowMessage("OK");break;
case ccError: ShowMessage("Error");break;
case ccReconnected: ShowMessage("Reconnect");break;
}

When I try to reference any dataset/query I get the error.

Thanks in advance...
 
The problem may not be in your dll, but the application that contains the call to your dll. I have great success using the following to pass connected sessions to dlls.
Make sure dll is in path or directory app can find.

//Oracle session that connected
TOracleSession *OSession;

//Forward reference to dll function
int (__stdcall* FMTEventEmail)(TOracleSession *pDbSession);

//name of dll
char pszSecDLL[] = "FMTEmail";
//dll method name
char pszSecFunc[] = "_FMTEventEmail";

if (OSession->CheckConnection(false) == ccError) {
strcpy(Buff,"Database connection error.");
AddToLogFile(Buff);
istatus = 1;
}else {

HINSTANCE hSecDLL;

//Get the handle of the DLL module
hSecDLL = LoadLibrary(pszSecDLL);
//if handle is valid, get the function address.
if (hSecDLL != NULL)
{
istatus = 98;
FMTEventEmail = (int(__stdcall*)(TOracleSession *)) GetProcAddress(hSecDLL, pszSecFunc);

//if function address is valid, call the function.
if (FMTEventEmail != NULL)
istatus = FMTEventEmail(OSession);
else
istatus = 97; //invalid function address

}else
istatus = 98; //invalid dll handle

FreeLibrary(hSecDLL); //Free the DLL module

}//end connection check
 
Back
Top