dll entry point not found [Solved]

Windows specific questions.
BasicScience
Posts: 489
Joined: Apr 18, 2008 4:09
Location: Los Angeles, CA
Contact:

Re: dll entry point not found

Post by BasicScience »

@Joshy,

Thanks!!!! I can now access all the functions in AxoClampDriver.dll. Now I just need to figure out how to use it with essentially no documentation.

Also, thanks for correcting my pointer error in the nError parameter. BTW for your example, I think Len(SerialNum) needs to be SizeOf(SerialNum). Len() returns 0 before a value has been assigned to SerialNum.

For the dependency on AxHIDManager.Dll, I simply use:

Code: Select all

DIM as any ptr L = DyLibLoad("AxHIDManager.dll")
if L=0 then print "unable to load dll":sleep:end 
This should work, right?

This project is for DIY data acquisition system at a university lab (UCLA). I've happily used FB for 13 years for data acquisition / analysis. Now, I'm just trying to keep up with hardware changes to the AxoClamp amplifiers.

The offer of Johnnie Walker Black still stands.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: dll entry point not found

Post by D.J.Peters »

BasicScience wrote:I think Len(SerialNum) needs to be SizeOf(SerialNum). Len() returns 0 before a value has been assigned to SerialNum.
No Sir, you are totally wrong :-)

SerialNum is a char buffer allocate by Space(16) len() returns in this case 16.
SizeOf() would return the size of an FreeBASIC string descriptor.

AXC_GetSerialNumber() does not allocate space for the serial number it fills the space you allocated and maximal with 16 chars.
BasicScience wrote:For the dependency on AxHIDManager.Dll, I simply use: DyLibLoad("AxHIDManager.dll")
This should work, right?
The dynamic loader (a part of the OS) will resolve open references from your created and executed program .
The loader "looks" in a import section of the exe witch *.dll are involved to replace open references (addresses to functions or to resources in the dll).
So it reads "AxoclampDriver.dll" (your interface to the device stack) if this dll was loaded from other task before
the dynamic loader can replace all open references with virtual addresses.
The translation of virtual address to physical memory addresses
are done by a MMU (memory management unit) and a MPU (memory protection unit) are involved also.
Of course both units are a part of the CPU today (no physical chips)
so the slower bottleneck CPU -> BUS -> RAM -> BUS -> CPU comes after the address translation.

If AxoclampDriver.dll was not loaded in RAM before it loads the dll and resolves open references from this dll to "open-device" "close-device" ...
So it reads "AxHIDManager.dll" from the import section of "AxoclampDriver.dll" and loads the dll and replace open references and so on.

This steps are repeated for all open references and involved dll's
version.dll ->user.dll -> system32.dll -> gdi32.dll ... (there are more but not shown on the picture)
Image

If we would talk about "normal" stuff that runs in user space like SDL or GTK+ using DyLibLoad("") would be a handy solution.

But in this special case (if AxHIDManager.Dll is a part of a driver stack/layer) for the acquisition system
it's more safe to let the job done by the OS and it's driver stack.
BasicScience wrote:Now I just need to figure out how to use it with essentially no documentation.
If "AxoclampDriver.h" is a part of the SDK you should find documentation or other C/C++ examples that used this lib also.

By the way this is one point why I like to translate include files by hand and not by fbfrog or h_to_bi.

If you do it by hand you knows witch data types (often structs with more or less meaningful member names) are used by witch functions.
Often I sort the declarations in a logical order that makes any sense for me.
(GetVersion, InitLib, Exitlib, OpenDevice, CloseDevice, Device->feature.a, feature.b,feature.c ...)

So for me a self translated *.bi file is more than a half of the documentation.

bla bla bla :-)

Joshy
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: dll entry point not found

Post by dodicat »

D.J.Peters
I assumed that you used fbfrog, I see some hanging TODO's :
('' TODO: __attribute__((dllimport)) BOOL WINAPI for example)
Or do you insert your own TODO?

Most of the declared functions end up a TODO in the .bi with my version of fbfrog.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: dll entry point not found

Post by D.J.Peters »

dodicat wrote:I assumed that you used fbfrog, I see some hanging TODO's:
Yes I use tools also
but they remove copyrights and the most important documentation in the comments made by humans for humans :-)
By the way if you get 80 TODO's by 100 declares it tells me don't trust a translator do it by hand ;-)

For big packages like SDL,GTK+,ODE ... with a bunch of include files of course I would use a translator also.

Try to create AxoclampDriver.bi from AxoclampDriver.h and compare your result with my hand written stuff.

The looks in many parts totally different.

Using extern "C" by stdcall it must crash !

Joshy
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: dll entry point not found

Post by dodicat »

Yea, thanks D.J.Peters.
I had a bash behind the scenes at this dll also.
I used gendef and dlltool for an import library.
I used dylibload and took a few declarations from AxoclampDriver.bi.
I got stuck with AXC_GetSerialNumber, it just wouldn't work, I was at it for half an hour.
In the end, you had it all up and running anyway and BasicScience was on his way to the off license for whisky.
BasicScience
Posts: 489
Joined: Apr 18, 2008 4:09
Location: Los Angeles, CA
Contact:

Re: dll entry point not found

Post by BasicScience »

@Joshy,

Yeah, the C header provides a lot of hints at how to use Axoclampdriver.dll, but there are remaining challenges that I have taken up with the vendor. For example, I can successfully get the handle and serial number of the device using the dll, but if I try to open the device an error code of 9304 is returned. Based on the C header, the error codes should be from 9001 to 9026.

I really appreciate your comments to help users (like me) learn more about FB. It still seems that because SerialNum is defined as a fixed-length zstring*16, then SizeOf(SerialNum)-1 would be OK. (This would not work for variable-length strings, because as you say the size of the descriptor is returned by SizeOf). To use Len(), it's necessary to remember the additional step of allocating characters (e.g. spaces) to SerialNum before using Len(SerialNum).
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: dll entry point not found

Post by D.J.Peters »

What does returns AXC_BuildErrorText() ?

How do you call AXC_OpenDevice()

Show me your complete code
you don't need to publish your real serial numer here
replace it with any chars but the same size as your original serial number (it's important)

Joshy
BasicScience
Posts: 489
Joined: Apr 18, 2008 4:09
Location: Los Angeles, CA
Contact:

Re: dll entry point not found

Post by BasicScience »

Ah, progress using AXC_BuildErrorText()

Code: Select all

#include once "AxoclampDriver.bi"

DIM hAXC as HAXC
DIM as zstring*16 SerialNum, AltSerialNum
DIM as Double dGain
DIM as long nError
DIM as uinteger uMode, uChannel
DIM as boolean bReadHardware = TRUE
 
SUB Error_Mssg(hAXC as HAXC, byval nError as long)
    DIM as zstring*AXC_STRSIZE_ERR sErrMssg
    Print "Error code: " & nError
    AXC_BuildErrorText(hAXC, nError, sErrMssg, AXC_STRSIZE_ERR)
    Print "Error mssg: " & sErrMssg    
END SUB

IF AXC_CheckAPIVersion(AXC_APIVERSION_STR)then
    print "Correct API Version: " & AXC_APIVERSION_STR
    print
ELSE
    Print "Wrong API version"
    sleep
    end
END IF

hAXC = AXC_CreateHandle(FALSE, @nError)
print "Handle: " & hAXC
IF nError then Error_Mssg(hAXC, nError)
print

IF AXC_FindFirstDevice(hAXC, strptr(SerialNum), AXC_STRSIZE_SN, @nError) then
    Print "FindFirstDevice Serial Number: " & SerialNum
    If nError then Error_Mssg(hAXC, nError)
    print
ELSE
    Print "Error finding first device"  'If no hardward connected, program aborts here
    sleep
    end
END IF


'IF AXC_FindNextDevice(hAXC, strptr(AltSerialNum), AXC_STRSIZE_SN, @nError) = 0 then
'    Print "No more devices found."
'    If nError then Error_Mssg(hAXC, nError)
'    print
'ELSE
'    print "AltSerialNum " & AltSerialNum
'END IF
'print "FindNextDevice error code: " & nError
'print

IF AXC_OpenDevice(hAXC, strptr(SerialNum), bReadHardware, @nError) then
    Print "Device opened"
    IF nError then Error_Mssg(hAXC, nError)
ELSE
    Print "Error returned on AXC_OpenDevice"
    IF nError then Error_Mssg(hAXC, nError)
    sleep
    end
END IF


'Attempt to read gain
umode    = 5   'Two-electrode voltage-clamp
uChannel = 0   'channel 0
print
IF AXC_GetScaledOutputGain(hAXC, @dGain, uChannel, uMode, @nError) then
    print "AXC_GetScaledOutputGain returned a value"
    Print "Gain: " & dGain
ELSE
    Print "AXC_GetScaledOutputGain failed"
    IF nError then Error_Mssg(hAXC, nError)
END IF

sleep
Output:
Correct API Version 1.0.0.56

Handle: 39461184

FindFirstDevice Serial Number: ********

Error returned on AXC_OpenDevice
Error code: 9304
Error mssg: AXCAPI: HID device not found.
BasicScience
Posts: 489
Joined: Apr 18, 2008 4:09
Location: Los Angeles, CA
Contact:

Re: dll entry point not found

Post by BasicScience »

BTW, the correct serial number is returned.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: dll entry point not found

Post by D.J.Peters »

D.J.Peters wrote:I needed it only to test my hand created *.bi file may be you have to remove AxHIDManager.dll from fbAxoclampDriver folder.
Do you removed the *.dll from your test folder so it's loaded from original place ?
From with folder do you got AxHIDManager.dll ?

Joshy
BasicScience
Posts: 489
Joined: Apr 18, 2008 4:09
Location: Los Angeles, CA
Contact:

Re: dll entry point not found

Post by BasicScience »

AxHIDManager.dll
AxoClampDriver.dll

Both in folder with BAS and BI code. System is finding these Dlls because if I move either one out of folder -> error.
BasicScience
Posts: 489
Joined: Apr 18, 2008 4:09
Location: Los Angeles, CA
Contact:

Re: dll entry point not found

Post by BasicScience »

The full download package for Axoclamp is here:

http://mdc.custhelp.com/app/answers/detail/a_id/18959

Drivers are freely available, since it's useless without their hardware.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: dll entry point not found

Post by D.J.Peters »

BasicScience wrote:Drivers are freely available, since it's useless without their hardware.
But it's useful to test the API !

Try "test.bas" from zip file if you like ;-)

first run it without any changes

if the result looks ok
change bStartAsDemo = 1 to bStartAsDemo = 0

If it makes trouble with your real hardware connected post the error text please.

Joshy
Image
BasicScience
Posts: 489
Joined: Apr 18, 2008 4:09
Location: Los Angeles, CA
Contact:

Re: dll entry point not found

Post by BasicScience »

It works in DemoMode.

When bStartDemo = 0, however, it has the same HID device not found error message.

Also, FYI, AXC_GetSerialNumer does not assign the serial number to SN (remains spaces). Curiously nError = 0

Here's the full output

API version 1.0.0.56
serial number:
first device SN: ******** (correct 8 digits)
found: 1 device
error in AXC_OpenDevice() code: 9304 error text: AXCAPI: HID device not found

BTW, I tried this with AxoClamp Commander 1.2 running or not running -> same error message.
BasicScience
Posts: 489
Joined: Apr 18, 2008 4:09
Location: Los Angeles, CA
Contact:

Re: dll entry point not found

Post by BasicScience »

@ Joshy,

One last thought. I disassembled AxoClamp.EXE (which does run properly and communicates with the device). It appears there is only one section of code that calls AXC_OpenDevice(), AKA SUB_L00405260 . Perhaps by looking at the ASM it will be possible to determine what must precede AXC_OpenDevice() in order for the device to be found?

If you're up for the challenge, I put the ASM listing here:
https://www.dropbox.com/s/6m0zruzbbxcef ... t.rtf?dl=0
Post Reply