这是我在stackoverflow的第一篇文章,我开始遇到问题。
我在c ++中用qt编写了一个gui应用程序。 目前我仍然坚持加载和保存传递给我的dll。 为了加载和保存,我决定设置加载和保存任务的功能。但主要问题是加载不同的DLL文件。
我目前有以下代码用于加载和保存,但是当我从加载切换到保存时出现错误。我知道它与“FreeLibrary()”功能有关。但是如果FreeLibrary(hDLLimp)被执行,我无法重复加载我的“implib.dll”。返回的hDLLimp为0。 如果我评论FreeLibrary,加载函数可以重新执行几次。但保存功能不起作用。 hDLLexp变为“0”并且句柄消失。
// 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);