XLL Internittently Fails to Load

G

Guest

I have a very simple XLL which I am trying to load in Excel 2007 on Windows
Vista. I have found that the problem occurs also in Excel 2003 on Vista, but
not in 2007 on XP. More accurately, this problem is not 100% consistent, but
occurs dramatically more often under Vista than under XP. Version of Excel
does not seem to matter.

When loading the XLL, I get a "The file you are trying to open,
'test_addxll.xll', is in a different format than specified by the file
extension." error. Having used Dependency Walker to profile Excel while
loading, I see that the sequence of events is as follows:
Excel loads without resolving dependencies test_addxll.xll.
Excel unloads test_addxll.xll.
Excel loads without resolving dependencies test_addxll.xll.
Excel checks for XlAutoOpen in test_addxll.xll.
Excel unloads test_addxll.xll.
Excel loads without resolving dependencies test_addxll.xll.
Excel unloads test_addxll.xll.
Excel loads without resolving dependencies test_addxll.xll.
Excel checks for XlAutoOpen in test_addxll.xll.
Excel unloads test_addxll.xll.
Excel loads test_addxll.xll.
DllMain in test_addxll.xll is called.
test_addxll.xll is unloaded.
LoadLibrary returns NULL, reporting an Invalid access to memory location
(998) error.
Specifically,
LoadLibraryW ("C:\Users\rich\Documents\Calc4Web\test_addxll.xll") called
from "EXCEL.EXE" at address 0x2FF08667.
Loaded "TEST_ADDXLL.XLL" at address 0x03440000. Successfully hooked module.
DllMain (0x03440000, DLL_PROCESS_ATTACH, 0x00000000) in "TEST_ADDXLL.XLL"
called.
Unloaded "TEST_ADDXLL.XLL" at address 0x03440000.
LoadLibraryW (C:\Users\rich\Documents\Calc4Web\test_addxll.xll") returned
NULL. Error: Invalid access to memory location (998).

This seems to indicate that an access violation is occurring inside DllMain.
However, the DllMain is this:
BOOL WINAPI DllMain (HANDLE hDLL, DWORD dwReason, LPVOID lpReserved)
{

switch (dwReason)
{
case DLL_PROCESS_ATTACH:
break;

case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}

Further, while this error occurs consistently when the XLL is compiled using
the MinGW toolkit (gcc 3.4.2, dlltool 2.16.91, dllwrap 2.16.91), I have not
been able to produce the error if I compile the XLL using Visual Studio (98,
2003, or 2005). Additionally, by using a fake XLCALL32.DLL file that does
not require Excel to be running, I was able to successfully load the XLL in a
standalone C++ program (compiled with Visual Studio 2005).

With more complex examples (the XLL statically linked to a DLL file
statically linked to another DLL file, all compiled with MinGW), the same
failure can occur, typically in one of the two DLL files. The same DLL files
could be accessed via standalone C++ or VB6, but trying to access them via VB
inside Excel failed much as loading the XLL fails. The problem only occurs
when the library is loaded from within Excel.

Again this problem does not occur when the XLL is compiled with Visual C++,
but I need to be able to generate working add-ins using MinGW as well as
using Visual C++.

Does anybody have experience with a problem like this, or information on
what we might do to solve it? If needed, I should be able to provide the
XLL, the code for the XLL, and a Dependency Walker profile.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top