views:

915

answers:

6

I have a JD Edwards business function, which is written in Microsoft Visual C++ as a C module. I'm using LoadLibrary to access a third party DLL. In a standalone test program, the code runs just fine. When I run it from within JDE, LoadLibrary returns NULL and GetLastError returns 126, which means The specified module could not be found according to MSDN. I've tried putting in the full path to the DLL, and yes I've remembered to double up the \ characters in the path. No difference.

I've checked to make sure there are no dependencies that would keep the DLL from loading; DUMPBIN /DEPENDENTS returns the following:

WSOCK32.dll
USER32.dll
GDI32.dll
WINSPOOL.DRV
ADVAPI32.dll
KERNEL32.dll

These look like standard Windows DLLs, so I'm at a loss.

+2  A: 

A missing dependency? Have you checked with Dependency Walker that all referenced libraries are found?

0xA3
It's been a very long time since I needed it, I completely forgot about Dependency Walker. It says I'm missing a delay loaded DLL dwmapi.dll, which I understand is Vista only. I don't think that's the problem, but thanks for the pointer.
Mark Ransom
How about moving the dll to a folder which is on your path like %windir%\system32?
0xA3
A: 

You might try testing while ProcMon is running and see if any errors are visible in it while file monitoring is enabled.

sean e
+2  A: 

If you attach a debugger during the LoadLibrary call, it may spew error info to debug output. In addition to the other suggestions here, if the manifest has an error in it this issue will occur.

I'm pretty sure its a dependency issue for you though. Try the ProcMon thing, and also try running on Vista to see if that solves the problem. You can get a test VPC image here.

jeffamaphone
I am having a DLL problem right now, and this answer helped me. I am getting error 126 and I saw in the debugger that the symbols for my DLL were loaded and then immediately unloaded. I suspect I have a dependency issue that I haven't figured out, and not a DLL path issue.
Michael Mathews
+1  A: 

I went once into the same nightmare. It was impossible to diagnose anything, I just found out that reseting the dll search list order path (the keyword here is probably 'list', not 'order') fixed the issue.

SetDllDirectory(NULL);

The explanation is that a third-party DLL in the middle was probably messing with it, without restoring its original state. This could explain why only your test application was working.

Jem
I didn't know about SetDllDirectory, thanks for the pointer. In this case it should have been redundant, since I had the full path to the DLL in the filename.
Mark Ransom
In my particular case, it was not even working with a full path to the dll, because it was itself again dependent to other DLLs.
Jem
+1  A: 

In addituion the Dependency walker can be run using the profile option. In this case the exe has to be loaded in dependency walker. Afetrwards the menu "Profile" can be used.

The application is started then and the dll tree is filled. This will also show if a delay loading dll is missing and other stuff.

Totonga
A: 

If you don't find an answer by checking dependencies, I would suggest concentrating on possible issues due to the architecture.

You mentioned that you're using a standalone test environment, but when you try it in a regular environment it doesn't work. Is the Business Function setup to run in the server?

It's been quite a while since I last worked with JDE. I remember that one time I wrote a BSFN in C to call several UBEs in a sort of synchonization and it worked fine on my local machine and didn't work when I was testing on the server. There was something about the server not being able to find the DLL (even though I was providing a path) and some settings that were required. Also, there was a difference that was critical in my case: on my machine, the BSFN would wait for the completion of the UBEs and would capture the status, on the server it wouldn't and it also had to do with settings on objects.

Again, if you don't find anything usefull, try asking for help on www.jdelist.com.

ezingano