this is my first post at stackoverflow and i`m starting with a problem.
Im writing a gui application with qt in c++. At the moment I'm stuck on loading and saving dlls which were passed to me. For loading and saving i decided to set functions for load- and save- tasks. But the main problem is the loading of different DLL files.
i have the following code at the moment for loading and saving, but getting errors when i'm switching from loading to saving. i know it have something to do with "FreeLibrary()" function. But in case FreeLibrary(hDLLimp) is executed i cannot repeat loading my "implib.dll". The returned hDLLimp is 0. In case i comment FreeLibrary out, the loading function can be re-executed several times. But saving function dont work. hDLLexp becomes "0" and the handle is gone.
// Load function
HINSTANCE hDLLimp = 0;
GETCOUNTS fncgetcounts;
GETITEM fncgetitem;
IMPEXPINTERFACE fncimportinterface;
TProcLib *proclib;
TNativeSurface nativesurface;
char filepath[_MAX_PATH];
hDLLimp = LoadLibrary(TEXT("implib.dll"));
DWORD Error = GetLastError();
if( hDLLimp == 0 )
{
QMessageBox *msgBox = new QMessageBox;
msgBox->setText("implib.dll konnte nicht geladen werden");
msgBox->exec();
return;
}
fncgetcounts = (GETCOUNTS) GetProcAddress(hDLLimp, "GetCounts");
fncgetitem = (GETITEM) GetProcAddress(hDLLimp, "GetItem");
fncimportinterface = (IMPEXPINTERFACE) GetProcAddress(hDLLimp, "ImportInterface");
for (long i=0; i<fncgetcounts()-1; i++) {
if ((proclib = fncgetitem(i))==NULL) break;
if (strcmp(proclib->ResName, "SDFIMPORT")==0) {
strcpy(filepath, "test.sdf");
fncimportinterface(filepath, _MAX_PATH, &(proclib->PrgId), 2, &nativesurface, 0, 0, NULL, NULL, 1);
break;
}
}
//FreeLibrary(hDLLimp);
//Export/Save function
HINSTANCE hDLLexp = 0;
GETCOUNTS fncgetcounts;
GETITEM fncgetitem;
IMPEXPINTERFACE fncexportinterface;
TProcLib *proclib;
TNativeSurface nativesurface;
char filepath[_MAX_PATH];
hDLLexp = LoadLibrary(TEXT("explib.dll"));
if( hDLLexp == 0 )
{
QMessageBox *msgBox = new QMessageBox;
msgBox->setText("explib.dll konnte nicht geladen werden");
msgBox->exec();
return;
}
fncgetcounts = (GETCOUNTS) GetProcAddress(hDLLexp, "GetCounts");
fncgetitem = (GETITEM) GetProcAddress(hDLLexp, "GetItem");
fncexportinterface = (IMPEXPINTERFACE) GetProcAddress(hDLLexp, "ExportInterface");
for (long i=0; i<fncgetcounts()-1; i++) {
if ((proclib = fncgetitem(i))==NULL) break;
if (strcmp(proclib->ResName, "SDFEXPORT")==0) {
strcpy(filepath, "test.sdf");
fncexportinterface(filepath, _MAX_PATH, &(proclib->PrgId), 2, &nativesurface, 0, 0, NULL, NULL, 1);
break;
}
}
//FreeLibrary(hDLLexp);