I’m discovering just how many errors and problems masquerade as “function not found” errors
I’m working on a windows 64bit app declaring a function in an external library.
*** it works fine for compiling as a Windows 32bit app ***
So, I’ve looked at:
the version of the library, I’ve confirmed that I’m using the 64bit version (at least as supplied)
the calling convention, thinking 32bit integers vs 64bit integers, etc but then I tried:
the location of the library. things might be different under 64bit, so I move the library to the root folder of the app, but then I think
is it finding the library at all? I remove the library entirely and get the same error
So where to go from here? Don’t forget that it all worked fine in 32bit. The parameters to be sent & returned are all explicitly Int32-type stuff and all docs suggest nothing about any 64bit differences with the library… help…
aer you sure its not a 32 bit DLL ?
a 64 bit app wont load a 32 bit DLL and a 32 bit one obviously cannot load a 64 bit one
And that will give you errors like function not found becuase the dll isnt open or loaded
Assuming it’s not 32 vs 64 bit mismatch, try dumping a list of the DLL’s exported functions using a tool like DLL Export Viewer. This will let you see all the functions in the DLL and their true names.
First, yes, it appears to be a 64bit DLL. I downloaded Dependency Walker and it claims the DLL is 64bit
Second, I used the DLL Export Viewer and it states the function name I’m using is correct
So I’m still at a loss. I expect the “function not found” error is in response to something returned from the OS but it’s a pain that I can’t tell the difference between a DLL being unavailable or using the wrong function name or…
when you debug quite literally WHERE is the DLL relative to the EXE being built for debugging ?
how do you get it there ?
maybe its not there at the right time (if you copy it manually after starting to debug or something ?)
You CAN - just then you dont use a declare as it doesnt tell you this
If you resorted to the lower level Windows API’s for loading a library and getting access to its entry points that could tell you all these details
Declares dont - they spare you the gorey details (but also hide some things as you’ve seen)
at first it was in a libs subfolder, then I tried putting it right beside the executable
copied via build automation
It should be fine as it’s a soft declare and it’s not required until I interact with the app’s UI after launch.
Also, don’t forget that this all works fine for 32bit compile (and is shipping today) - so most of the fiddly things that could happen have likely been solved
soft declare Function theFunction lib "theLib.dll" ( theList as ptr, byref foundCount as UInt32, listLength as ptr ) as Int32
[code]
Declare Function LoadLibraryW Lib “Kernel32” (LibName As WString) As Ptr
Declare Function GetProcAddress Lib “Kernel32” (hModule As Ptr, ProcName As CString) As Ptr
Dim library As Ptr = LoadLibraryW(“MyLib.dll”)
If library = Nil Then MessageBox(“DLL not found”)
Dim procedure As Ptr = GetProcAddress(library, “MyFunctionName”)
If procedure = Nil Then MessageBox(“Function not found”)[/code]
Unfortunately I got “DLL not found” no matter what I tried.
I ensured that the DLL was in the same folder as the executable and that it was properly named in the LoadLibraryW call
I reviewed it again with the Dependency Walker utility and found the following errors:
Error: At least one required implicit or forwarded dependency was not found.
Error: At least one module has an unresolved import due to a missing export function in an implicitly dependent module.
Error: Modules with different CPU types were found.
Warning: At least one delay-load dependency module was not found.
Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module.
There are about 12 dlls that make up this library but I did confirm that the function I’m attempting to call is within the dll file I reference in the LoadLibraryW call
So, I tried an earlier version of the manufacturer’s library to see if it was a bad build or something… no dice (same errors in Dependency Walker as well)
I should mention that I can successfully call a dll from a different manufacturer, so it would appear I’m doing something correctly…
Also, do recall that this all works when compiling for 32bits with the 32bit set of dlls that are supplied
These problem dlls are included with working sample C++ code (they claim, I did not compile it myself) and a working build of their demo app…
It sounds like the interdependencies are flummoxing the loading of the library… any ideas?
ERROR_MOD_NOT_FOUND
126 (0x7E)
The specified module could not be found.
Which sounds like it could be useful and yet sounds about as generic as the error message from Xojo - I can’t tell if it’s referring to the DLL or something internal…
You might have a missing 64bit runtime library that the dll depends on, check where you got the app/dll from to see if they have a pre-requisite for the 64bit version of the app/dll, try it after installing the 64bit version of that. Failing that see the following on how to deubg the load failure:
[quote=476241:@Norman Palardy]do they also provide all the dependent dll’s ?
if so make sure those are all next to the built exe a well [/quote]
they seem to provide them (and I locate them all in the same place - beside the exe)
it’s the same group of DLLs (by name at least) supplied with the 32bit set, that all load fine (not to beat a dead horse, just trying to provide A/B comparison info)
Agreed.
In the Dependency Walker utility there’s a long list of DLLs listed (and I mean VERY long - about 500 items), each of which has “Error opening file. The system cannot find the file specified (2)”
I’ve been reading the links that Julian suggested as well as I did a search on the first DLL in the list “API-MS-WIN-CORE-APIQUERY-L1-1-0.DLL” and found some interesting bits:
Dependency Walker utility is old and doesn’t handle the levels of call indirection occurring today