Loadlibrary Error 126

For discussion of the xlw project for producing xlls.

Loadlibrary Error 126

Postby SeanKw » Tue Oct 15, 2013 9:14 am

Hi everyone,
I created a test xll which references a dll. The xll and dll files are both in the same folder. This is the c++ function I'm trying to call in Excel
Code: Select all
double // squares a number using the dll
squareInCpp(double &arg)
   libHandle = LOADLIB("the_DLL_Name.dll"); // LOADLIB = LoadLibraryA
   if (!libHandle) {
      double err = GetLastError();  // <---------------- ERROR -------------------------
      return err;
   //You can stop reading here, since this code won't be reached
   typedef double (*PtrFunc_square_in_Cpp) (double &arg);
   PtrFunc_square_in_Cpp squareInCpp = (PtrFunc_square_in_Cpp)LOADSYMBOL(libHandle, "square_in_Cpp"); // LOADSYMBOL = GetProcAdress
   if( !squareInCpp )
      return -1;
      double res = squareInCpp(arg);
      return res;

Code: Select all
   #include <windows.h>
   #include <direct.h>
   HINSTANCE libHandle;
   #define LOADLIB(X) LoadLibraryA(X)  // <------
   #define LOADSYMBOL GetProcAddress // <--------
   #define LASTERROR() GetLastError()
   #define CLOSELIB(X) FreeLibrary(X)

- The function always returns with error code 126. But the dll is in the same folder together with the xll, how can he not find the file?
- I analysed the xll with DependancyWalker, it says that MSVCR90D.DLL is missing. I don't know if this is important, since DependancyWalker always claims that - even when I analyse the example xlls delivered by the xlw download and which are working fine.
- By the way, I tried using my posted code with an exe file, it worked. Do I have to use loadlibrary in a different way in the xlw framework?

Thanks and best regards
Posts: 4
Joined: Fri Oct 04, 2013 1:51 pm

Re: Loadlibrary Error 126

Postby SeanKw » Wed Oct 23, 2013 7:53 am

The error only occurs, when I'm working with the debug version of the dll. If I use the release version, loadlibrary works fine.
Posts: 4
Joined: Fri Oct 04, 2013 1:51 pm

Return to xlw

Who is online

Users browsing this forum: No registered users and 1 guest