Ive been just learning how to make/use dll files and Ive come up with thiss error (through getLastError() func). The code which creates the dll is almost the same as the IDE generated, I just changed the function name and what the function does, this is the code:
/* To use this exported function of dll, include this header
* in your project.
#define DLL_EXPORT __declspec(dllexport)
int DLL_EXPORT getDungeonsNumber();
#endif // __MAIN_H__
// a sample exported function
int DLL_EXPORT getDungeonsNumber()
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
// attach to process
// return FALSE to fail DLL load
// detach from process
// attach to thread
// detach from thread
return TRUE; // succesful
this makes the MW.dll file (CodeBlocks IDE used here).
Then the main program code is made in Qt IDE:
int main(int argc, char *argv)
QApplication a(argc, argv);
MainWindow w; //creates the main window of the app
//heres the c´tor of the main window where Im trying to load the dll and there comes the error
MainWindow::MainWindow(QWidget *parent) :
/*getDungeonsNumber is pointer to func of type FUNCPTgetDungeonsNumber which I have defined in another header included in the mainwindow.h
its defined like this typedef int (*FUNCPTgetDungeonsNumber)(); */
hinstDLL = LoadLibrary((LPCWSTR)"MW.dll");
getDungeonsNumber = (FUNCPTgetDungeonsNumber)GetProcAddress(hinstDLL, "getDungeonsNumber");
Error::cannotLoadDLL(); //just my function to handle the error
Error::nullFunction(); //just another my function to handle the error
DungeonsNumber = getDungeonsNumber();
QMessageBox::information(this, "a", QString::number(DungeonsNumber));
int e = GetLastError();
QString str = "Your DLLs seems to be broken... ";
str += "getLastError() returned value: ";
str += QString::number(e);
QMessageBox::critical(NULL, "Error", str);
the function Error::cannotLoadDLL() is called and the messagebox sais the getLastError returned value 126.
I have the dll file in the axact place as the executable. Also i have tried to load some profi made dlls like msvcr100d.dll and get the same error. This is very frustating, hope someone can help :D
The cast here is absolutely wrong. It will cause LoadLibrary to always fail. Either use LoadLibraryW directly and L"" prefix for literal strings if you must pass a Unicode string or use _T() macro and include <tchar.h>.
oh yees, god I hate microsoft and their redefined variable names.
in the tutorial there was only hinstDLL = LoadLibrary("MW.dll"); and it worked but I get the error that I canoot pass char* to LoadLibrary that there must be LPCWSTR so I just used the cast and I forget the L, thank you so much :D