Calling DLL Functions (Interfacing with LabJack Drivers)
Posted: Mon Jul 31, 2006 8:06 pm
I am trying to call some driver functions for a LabJack UE9 USB/Ethernet data acquisition device. So far I have been successful with the simple GetDriverVersion function, but when I try to call OpenLabJack I get "[ERROR] Invalid memory address". Probably something wrong with the string parameter or the handle pointer.
Here are the C-prototypes for the 2 functions I am trying to call so far:
double _stdcall GetDriverVersion(void);
LJ_ERROR _stdcall OpenLabJack(long DeviceType, long ConnectionType, const char *pAddress, long FirstFound, LJ_HANDLE *pHandle);
Here is my PureBasic code:
OpenConsole()
ConsoleTitle ("LabJackUD PureBasic Example:")
EnableGraphicalConsole(0)
Prototype.d ProtoGetDriverVersion()
Prototype.l ProtoOpenLabJack(DeviceType.l, ConnectionType.l, Address$, FirstFound.l, *pHandle.l)
If OpenLibrary(0,"labjackud.dll")
fGetDriverVersion.ProtoGetDriverVersion = GetFunction(0, "GetDriverVersion")
driverVersion.d = fGetDriverVersion()
PrintN(StrD(driverVersion.d))
fOpenLabJack.ProtoOpenLabJack = GetFunction(0, "OpenLabJack")
errorcode.l = fOpenLabJack( 9, 1, "1", 1, *pHandle)
Else
PrintN("Open Library Failed")
EndIf
Print ("Press <Enter> to exit: ")
name$=Input()
CloseLibrary(0)
CloseConsole()
End
Here are the C-prototypes for the 2 functions I am trying to call so far:
double _stdcall GetDriverVersion(void);
LJ_ERROR _stdcall OpenLabJack(long DeviceType, long ConnectionType, const char *pAddress, long FirstFound, LJ_HANDLE *pHandle);
Here is my PureBasic code:
OpenConsole()
ConsoleTitle ("LabJackUD PureBasic Example:")
EnableGraphicalConsole(0)
Prototype.d ProtoGetDriverVersion()
Prototype.l ProtoOpenLabJack(DeviceType.l, ConnectionType.l, Address$, FirstFound.l, *pHandle.l)
If OpenLibrary(0,"labjackud.dll")
fGetDriverVersion.ProtoGetDriverVersion = GetFunction(0, "GetDriverVersion")
driverVersion.d = fGetDriverVersion()
PrintN(StrD(driverVersion.d))
fOpenLabJack.ProtoOpenLabJack = GetFunction(0, "OpenLabJack")
errorcode.l = fOpenLabJack( 9, 1, "1", 1, *pHandle)
Else
PrintN("Open Library Failed")
EndIf
Print ("Press <Enter> to exit: ")
name$=Input()
CloseLibrary(0)
CloseConsole()
End