DLL Not Found?
Hi guys,
I am in the process of converting one of my linux applications to windows, as part of the application, I require loading of DLLs at run time from a set folder.
I have not been able to get this to work as LoadLibrary keeps failing with error code 126....after looking this up, it seems to mean that a dependency is missing.
I have created a very small program in order to see if I can get loading of DLLs at runtime working, and yet, it still does not work, even with the very small number of dependencies (I have used depends.exe), all of which exist on the system
I dont know if there is a problem with my code, so I would appreciate you taking a look
------------------------------------TestDLL/Main.h------------------------------
#ifndef MAIN_H
#define MAIN_H
class __declspec(dllexport) Something
{
public:
int add( int one, int two );
};
#endif
-----------------------------------TestDLL/Main.cpp----------------------------
#include "Main.h"
#include <windows.h>
BOOL APIENTRY DllMain(HANDLE, DWORD, LPVOID)
{
return TRUE;
}
int Something::add( int one, int two )
{
return ( one + two );
}
-----------------------------------UseDLL/Driver.cpp---------------------------
#include <windows.h>
#include <iostream>
int main( int argc, char **argv )
{
// load the library
HINSTANCE hinst = LoadLibrary( LPCWSTR( "TestDLL.dll" ) );
if( hinst == NULL )
{
std::cout << "noooooooooo" << std::endl;
std::cout << GetLastError( ) << std::endl;
}
char c;
std::cin >> c;
return 0;
}
-------------------------------------------------------------------------------
TestDLL is the project building the very simple DLL, and UseDLL will use it. I have checked that TestDLL.dll is in the same directory as UseDLL.exe, and I have also run depends on TestDLL.dll which gives the following:
KERNEL32.DLL
MSVCR90.DLL
NTDLL.DLL
TESTDLL.DLL
I have checked that these all exist, and they do, in directories on the PATH
I am not sure what else the problem could be here to be honest, my application works perfectly under linux, but I have not had much experience building DLLs in windows, so it may be a problem with the way I have done it that causes the LoadLibrary function to fail with that error code
Thanks
Quote:Original post by ForgottenMasterError 126 actually means "The specified module could not be found. "
I have not been able to get this to work as LoadLibrary keeps failing with error code 126....after looking this up, it seems to mean that a dependency is missing.
Quote:Original post by ForgottenMasterRead This. You can't do that any more than you can do:// load the libraryHINSTANCE hinst = LoadLibrary( LPCWSTR( "TestDLL.dll" ) );
float f = 123.456;LPCWSTR s = LPCWSTR(f);
Quote:Original post by Evil Steve
You can't do that any more than you can do:
<nitpick>Bad phrasing here. Since his code will compile and your example won't, he can, in fact, do that more than you could do a floating point to pointer cast. :)</nitpick>
Quote:Original post by SiCraneAh yes - somewhere in my brain I thought that'd compile, obviously not. Ok, pretend f is a pointer to a float then [smile]Quote:Original post by Evil Steve
You can't do that any more than you can do:
<nitpick>Bad phrasing here. Since his code will compile and your example won't, he can, in fact, do that more than you could do a floating point to pointer cast. :)</nitpick>
Quote:Original post by ForgottenMaster
HINSTANCE hinst = LoadLibrary( LPCWSTR( "TestDLL.dll" ) );
A typical approach to dealing with string literals is to wrap them in the TEXT macro.
HINSTANCE hinst = LoadLibrary( TEXT( "TestDLL.dll" ) );
When compiling with UNICODE defined, the TEXT macro prefixes an "L" to the string, which tells the compiler to treat the string as UNICODE. When compiling with UNICODE not defined, the TEXT macro leaves the string as is, so the compiler treats the string as ANSI. The TEXT macro is defined in winnt.h, which should automatically be included in your project when windows.h is included.
One thing to note. LoadLibrary is usually used in conjunction with GetProcAddress, which expects an ANSI string argument. So don't wrap that argument with TEXT.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement