linking to dll's [unofficial]

Miscellaneous Forums/Win32 Discussion/linking to dll's [unofficial]

This needs some work and I'm not sure if it trashes the stack but I think the theory is sound. And no I'm not going to try implementing a com interface so the DirectDraw handle shown here is a pretty useless example but the call does seems to be working.

' testdll.bmx

strict

Import pub.win32

Extern "win32"
Global DirectDrawCreate(guid:Byte Ptr,IDirectDraw Ptr,pUnkOuter)="bb__DirectDrawCreate"
End Extern

Function DllLink(dll$,name$,func Ptr)
	Local lib,proc:Byte Ptr
	lib=LoadLibraryA(dll$)
	proc=GetProcAddress(lib,name)
	func[0]=Int(proc)
End Function

Global _DirectDrawCreate

DllLink("ddraw","DirectDrawCreate",Varptr _DirectDrawCreate)

Function InitDDraw()
	Local res,ddraw
	res=DirectDrawCreate(Byte Ptr(0),Varptr ddraw,0)
	Print "res="+res
	Print "ddraw="+ddraw
End Function

InitDDraw


interesting... confusing but interesting.

I'll have to run through this after I fully wake up. :)

an easier way to do this, if you have minGW is to use 2 little tools that comes with minGW *note* still needs the DLL though.

"pexports"
and
"dlltool"

for example you have a dll called mydll.dll
the first step is to go, (from a command window)
pexports mydll.dll >mydll.def

then
dlltool -d mydll.def -l libmydll.a

then you have a libmydll.a file you can put into the blitzmax lib dir.

and can make a module out of it, but REMEMBER it still requires you to have the dll though.

*edit* better mention how to make a mod
make a new dir in the mod directory
for example dragos.mod
in there you can create another dir called for example mymod.mod MAKE SURE IT IS IN LOWERCASE or it wont build it fully.
inside there you create a file called mymod.bmx
which could look like

Import "-lmydll" ' this tells the linker to link with libmydll.a

extern "win32"
   Function MyFunction:int(myvar:int)
end extern


Oh, and a little add on to drago's thing - he's been helping me on irc with using a dll, you need to have MingW for compiling modules.

Then, you've gotta set your enviornment paths for it. Go to control panel, System, Advanced tab, click "Enviornment variables", in the new window that pops up there is a listbox labeled "System Variables". Within this, scroll down to a variable named "Path". Select it, click edit. Move to the end of the text, and add a semicolon (;), and paste in the path to your mingw bin directory.

I added ;C:\MinGW\bin to the end of my path variable. Then, create a new dos prompt (not an old... this was one of my probs for a while), change your dir to bmax bin dir, and call:

BMK makemods brl

If for instance you want to recompile blitz research modules.

heh, yeah, that sort of helps if you want to actually compile and use the module :)

I should have mentioned that.

Environment paths... pah! -I- use Protean =]

the environment path still needs to be set or your module can't be build! ( Protean isn't god as well, it just calls the BlitzMax compiler which relates to the path )

Hmm. I'm getting problems with my mod - here's an verview of what i did

Ok, I used drago's procedure to produce a .a file and put it in my lib directory. Then, I made my module folder in mod:

C:\BlitzMaxBeta101\mod\bot.mod

Then I made a folder within that for the mod I'm going to make:

C:\BlitzMaxBeta101\mod\bot.mod\p5.mod

Here's my bmx file:

'Actually the fraction of an inch units are measured in, not the Head Separation.
Public Const P5HEAD_SEPARATION:Float = 51.2

'fingers definitions
Const P5_THUMB = 0
Public Const P5_INDEX = 1
Public Const P5_MIDDLE = 2
Public Const P5_RING = 3
Public Const P5_PINKY = 4

'filter modes definitions
Public Const P5_FILTER_NONE = 0
Public Const P5_FILTER_DEADBAND = 1
Public Const P5_FILTER_AVERAGE = 2

' [sic]
Public Const P5_FILTER_DEADBEND = 1



'Error Codes
Public Const P5ERROR_NONE = 0
Public Const P5ERROR_NOP5DETECTED = 1
Public Const P5ERROR_P5DISCONNECTED = 2
Public Const P5ERROR_P5CONNECTED = 3
Public Const P5ERROR_INVALID_P5ID = 4
Public Const P5ERROR_INVALID_P5GLOVETYPE = 5
Public Const P5ERROR_WRONGFIRMWAREVER = 6
Public Const P5ERROR_EXCEPTION = 7
Public Const P5ERROR_GETTIME = 8
Public Const P5ERROR_PARSEBEND = 9
Public Const P5ERROR_PARSEBUTTONS = 10
Public Const P5ERROR_PARSELEDNUM = 11
Public Const P5ERROR_PARSELED = 12
Public Const P5ERROR_UNWARP = 13
Public Const P5ERROR_PROCESS = 14
Public Const P5ERROR_PROCESSROTATION = 15
Public Const P5ERROR_PROCESSRELATIVEPOSITION = 16
Public Const P5ERROR_PROCESSRELATIVEAVGPOSITION = 17
Public Const P5ERROR_PROCESSROTATIONREAL = 18
Public Const P5ERROR_PROCESSABSOLUTEPOSITION = 19
Public Const P5ERROR_PROCESSLEDPOSITIONS = 20
Public Const P5ERROR_INTERNAL = 21

'Glove types
Public Const P5GLOVETYPE_RIGHTHAND = 0
Public Const P5GLOVETYPE_LEFTHAND = 1


'Glove backwards
Public Const P5GLOVEBACKWARDS_NOT = 0
Public Const P5GLOVEBACKWARDS_THUMBLITTLE = 1
Public Const P5GLOVEBACKWARDS_NOTHUMB = 2
Public Const P5GLOVEBACKWARDS_UPSIDEDOWN = 3
Public Const P5GLOVEBACKWARDS_DONTWORRY = 4


' Distance units
Public Const P5_UNITS = 1
Public Const P5_CM:Float = 2.54 / 51.2
Public Const P5_MM:Float = P5_CM * 10
Public Const P5_INCHES:Float = 1 / 51.2
Public Const P5_FEET:Float = 1 / 51.2 / 12
Public Const P5_M:Float = P5_CM / 100
Public Const P5_KM:Float = P5_M / 1000
' Time Units
Public Const P5_SECONDS:Float = 1
Public Const P5_MINUTES:Float = P5_SECONDS / 60
Public Const P5_HOURS:Float = P5_MINUTES / 60
Public Const P5_FRAME:Float = 1# * P5_SECONDS / 41.7
' Velocity Units
Public Const P5_KPH:Float = P5_KM / P5_HOURS
Public Const P5_MPS:Float = P5_M / P5_SECONDS
' Acceleration Units
Public Const P5_MPSPS:Float = P5_M / P5_SECONDS / P5_SECONDS
' Rotation Units
Public Const P5_DEGREES:Float = 1
Public Const P5_RADIANS:Float = 3.14159 / (180 * P5_DEGREES)
Public Const P5_REVOLUTIONS:Float = P5_DEGREES / 360


' What position to return via the old interface
Public Const P5MODE_RELATIVE = 0
Public Const P5MODE_ABSOLUTE = 1
Public Const P5MODE_RELATIVEAVG = 2
Public Const P5MODE_FILTERED = 3
Public Const P5MODE_LED0 = 4
Public Const P5MODE_LED1 = 5
Public Const P5MODE_LED2 = 6
Public Const P5MODE_LED3 = 7
Public Const P5MODE_LED4 = 8
Public Const P5MODE_LED5 = 9
Public Const P5MODE_LED6 = 10
Public Const P5MODE_LED7 = 11
Public Const P5MODE_LED8 = 12
Public Const P5MODE_LED9 = 13
Public Const P5MODE_LEDBRIGHT = 14
Public Const P5MODE_LEDBEST = 15

' What rotation to return via the old interface
Public Const P5MODE_ORIGINAL_PYR = 256 * 0

Public Const P5MODE_BETTER_PYR = 256 * 10
Public Const P5MODE_BETTER_YPR = 256 * 11
Public Const P5MODE_BETTER_RYP = 256 * 12
Public Const P5MODE_BETTER_RPY = 256 * 13
Public Const P5MODE_BETTER_YRP = 256 * 14
Public Const P5MODE_BETTER_PRY = 256 * 15
Public Const P5MODE_BETTER_MIX = 256 * 16

Public Const P5MODE_FILTERED_PYR = 256 * 20
Public Const P5MODE_FILTERED_YPR = 256 * 21
Public Const P5MODE_FILTERED_RYP = 256 * 22
Public Const P5MODE_FILTERED_RPY = 256 * 23
Public Const P5MODE_FILTERED_YRP = 256 * 14
Public Const P5MODE_FILTERED_PRY = 256 * 15
Public Const P5MODE_FILTERED_MIX = 256 * 24

Extern "Win32"

'Close function
Function P5_Close()

'Init function - required on start of program
Function P5_Init:Byte()

Function P5_SetClickSensitivity(P5Id:Long, leftvalue:Byte, rightvalue:Byte, middlevalue:Byte)
Function P5_GetClickSensitivity(P5Id:Long, leftclick:Long Ptr, rightclick:Long Ptr, middleclick:Long Ptr)

Function P5_SaveBendSensors(P5Id:Long = -1)
Function P5_CalibrateBendSensors(P5Id:Long = -1)
Function P5_CalibratePositionData(P5Id:Long = -1)

Function P5_GetMouseState:Byte(P5Id:Long = 0)
Function P5_SetMouseState(P5Id:Long, state:Long)

Function P5_SetMouseStickTime(P5Id:Long, time:Byte)
Function P5_GetMouseStickTime:Long(P5Id:Long = 0)
Function P5_GetMouseButtonAllocation(P5Id:Long, leftclick:Long Ptr, rightclick:Long Ptr, middleclick:Long ptr)
Function P5_SetMouseButtonAllocation(P5Id:Long, leftclickfinger:Long, rightclickfinger:Long, middleclickfinger:Long)

Function P5_GetLastError:Byte(P5Id:Long Ptr, ErrorCode:Long ptr)

Function P5_GetCount:Long()


' AC Adaptor
Function P5_GetACAdaptorStatus:Long(P5Id:Long = 0)

' Bend Sensors
Function P5_GetBendCalibration(P5Id:Long, ThumbStraight:Long Ptr, ThumbBent:Long Ptr, IndexStraight:Long Ptr, IndexBent:Long Ptr, MiddleStraight:Long Ptr, MiddleBent:Long Ptr, RingStraight:Long Ptr, RingBent:Long Ptr, PinkyStraight:Long Ptr, PinkyBent:Long ptr)
Function P5_GetRawFingerBends(P5Id:Long, thumb:Long Ptr, index:Long Ptr, middle:Long Ptr, ring:Long Ptr, pinky:Long Ptr)

' Space Warp
Function P5_SetUnits(units:Float = 1)
Function P5_SetForwardZ(z:Long = 1)

Function P5_SetTowerPos(P5Id:Long, x:Float, y:Float, z:Float)
Function P5_TiltTowerForward(P5Id:Long, degrees:Float)
Function P5_SplongowerRight(P5Id:Long, degrees:Float)
Function P5_TiltTowerRight(P5Id:Long, degrees:Float)

Function P5_SetSensitivity(P5Id:Long, multiplier:Float)

' Glove configuration
Function P5_SetLedPos(P5Id:Long, led:Long, x:Float, y:Float, z:Float)
Function P5_SetGlovePos(P5Id:Long, x:Float, y:Float, z:Float)
Function P5_PitchGlove(P5Id:Long, theta:Float)
Function P5_YawGlove(P5Id:Long, theta:Float)
Function P5_RollGlove(P5Id:Long, theta:Float)


' Filters
Function P5_SetInterfaceMode(mode:Long)
Function P5_SetFilterMode(filters:Long)
Function P5_SetFilterAmount(ExtraFrames:Long, DeadDistance:Float)
Function P5_ClearArchive(P5Id:Long = -1)
Function P5_SetRequiredAccuracy(accuracy:Float = 10)
Function P5_SetPrediction(prediction:Long = 1)

' Mouse
Function P5_RestoreMouse(P5Id:Long = -1)
Function P5_UnRestoreMouse(P5Id:Long = -1)

' Get values stored in structures
Function P5_GetAbsolutePos(P5Id:Long, x:Float Ptr, y:Float Ptr, z:Float ptr)
Function P5_GetRelativePos(P5Id:Long, x:Float Ptr, y:Float Ptr, z:Float ptr)
Function P5_GetRelativeAvgPos(P5Id:Long, x:Float Ptr, y:Float Ptr, z:Float ptr)
Function P5_GetRotation(P5Id:Long, yaw:Float Ptr, pitch:Float Ptr, roll:Float ptr)
Function P5_GetFingerBends(P5Id:Long, thumb:Float Ptr, index:Float Ptr, middle:Float Ptr, ring:Float Ptr, pinky:Float ptr)
Function P5_GetButtons(P5Id:Long, A:Float ptr, B:Float Ptr, C:Float Ptr, D:Float Ptr)
Function P5_GetThreadStatus:Byte(P5Id:Long)
EndExtern


I save this in my mod directory as:

C:\BlitzMaxBeta101\mod\bot.mod\p5.mod\p5.bmx

And then compile, which works.

Upon attempting to compile a program, however, I get:

Linking:Test.exe
C:\BlitzMaxBeta101\bin\ld: cannot find C:/BlitzMaxBeta101/mod/bot.mod/p5.mod/p5.a
Build Error: Failed to link C:/BlitzMaxBeta101/Projects/P5/Test.exe


This is no bigie, I copy the .a file, and retry:

Linking:Test.exe
C:/BlitzMaxBeta101/Projects/P5/.bmx/Test.bmx.o(code+0x23): undefined reference to `__bb_p5_p5'
Build Error: Failed to link C:/BlitzMaxBeta101/Projects/P5/Test.exe

And this is where I'm stuck now


[edit]Oh, and I have the dll in the directory of the program.

Riot - yeah, err, i do too. That doesnt mean you dont have to set your mingw enviornment paths.

Oh, and the dll comes with a .def file thats alot different from the one produced by pexports:

.def file that comes with it:
LIBRARY   P5DLL
DESCRIPTION "P5 Absolute Mode Driver"
EXPORTS
	??0CP5DLL@@QAE@XZ @1
	P5_Close @22
	P5_Init @23
	P5_SetClickSensitivity @24
	P5_GetClickSensitivity @25
	P5_SaveBendSensors @26
	P5_CalibrateBendSensors @27
	P5_CalibratePositionData @28
	P5_GetMouseState @29
	P5_SetMouseState @30
	P5_SetMouseStickTime @31
	P5_GetMouseStickTime @32
	P5_GetMouseButtonAllocation @33
	P5_SetMouseButtonAllocation @34
	P5_GetLastError @35
    P5_GetCount @36
    P5_GetDataPointer @37
    P5_GetStatePointer @38
    P5_GetInfoPointer @39
    P5_GetCP5DLL @40
    P5_GetCP5 @41
    P5_GetPrivatePointer @42
	Java_com_essentialreality_CP5DLL_00024P5State_update @43
	Java_com_essentialreality_CP5DLL_P5_1Close @44
	Java_com_essentialreality_CP5DLL_P5_1Doit @45
	Java_com_essentialreality_CP5DLL_P5_1SetClickSensitivity @46
	Java_com_essentialreality_CP5DLL_P5_1GetClickSensitivity @47
	Java_com_essentialreality_CP5DLL_P5_1SaveBendSensors @48
	Java_com_essentialreality_CP5DLL_P5_1CalibrateBendSensors @49
	Java_com_essentialreality_CP5DLL_P5_1CalibratePositionData @50
	Java_com_essentialreality_CP5DLL_P5_1GetMouseState @51
	Java_com_essentialreality_CP5DLL_P5_1SetMouseState @52
	Java_com_essentialreality_CP5DLL_P5_1SetMouseStickTime @53
	Java_com_essentialreality_CP5DLL_P5_1GetMouseStickTime @54
	Java_com_essentialreality_CP5DLL_P5_1GetMouseButtonAllocation @55
	Java_com_essentialreality_CP5DLL_P5_1SetMouseButtonAllocation @56
	Java_com_essentialreality_CP5DLL_P5_1GetLastError @57

    Java_com_essentialreality_CP5DLL_00024P5Data_update @58
    Java_com_essentialreality_CP5DLL_00024P5Data_updateFull @59
	Java_com_essentialreality_CP5DLL_00024P5Info_update @60

	P5_GetACAdaptorStatus @61

	P5_GetBendCalibration @62
	P5_GetRawFingerBends @63

	P5_GetCalibrationData @64

	P5_SetUnits @65
	P5_SetForwardZ @66

	P5_SetTowerPos @67
	P5_SetTowerRotMat @68
	P5_TiltTowerForward @69
	P5_SpinTowerRight @70
	P5_TiltTowerRight @71
	P5_SetSensitivity @72

	P5_SetLedPos @73
	P5_SetGlovePos @74
	P5_SetGloveRotMat @75
	P5_PitchGlove @76
	P5_YawGlove @77
	P5_RollGlove @78


	P5_SetInterfaceMode @79
	P5_SetFilterMode @80
	P5_SetFilterAmount @81
	P5_ClearArchive @82
	P5_SetRequiredAccuracy @83
	P5_SetPrediction @84

	P5_RestoreMouse @85
	P5_UnRestoreMouse @86


	P5_SetFeature @87
	P5_SetFeatureReport @88
	P5_GetFeature @89
	P5_GetFeatureReport @90

	P5_GetData @91
	P5_GetState @92
	P5_GetInfo @93

	P5_GetAbsolutePos @94
	P5_GetRelativePos @95
	P5_GetRelativeAvgPos @96
	P5_GetRotation @97
	P5_GetFingerBends @98
	P5_GetButtons @99
	P5_GetThreadStatus @100

	Java_com_essentialreality_CP5DLL_P5_1GetACAdaptorStatus @101
	Java_com_essentialreality_CP5DLL_P5_1SetUnits @102
	Java_com_essentialreality_CP5DLL_P5_1SetForwardZ @103
	Java_com_essentialreality_CP5DLL_P5_1SetTowerPos @104
	Java_com_essentialreality_CP5DLL_P5_1TiltTowerForward @105
	Java_com_essentialreality_CP5DLL_P5_1SpinTowerRight @106
	Java_com_essentialreality_CP5DLL_P5_1TiltTowerRight @107
	Java_com_essentialreality_CP5DLL_P5_1SetSensitivity @108
	Java_com_essentialreality_CP5DLL_P5_1SetLedPos @109
	Java_com_essentialreality_CP5DLL_P5_1SetGlovePos @110
	Java_com_essentialreality_CP5DLL_P5_1PitchGlove @111
	Java_com_essentialreality_CP5DLL_P5_1YawGlove @112
	Java_com_essentialreality_CP5DLL_P5_1RollGlove @113
	Java_com_essentialreality_CP5DLL_P5_1SetInterfaceMode @114
	Java_com_essentialreality_CP5DLL_P5_1SetFilterMode @115
	Java_com_essentialreality_CP5DLL_P5_1SetFilterAmount @116
	Java_com_essentialreality_CP5DLL_P5_1ClearArchive @117
	Java_com_essentialreality_CP5DLL_P5_1SetRequiredAccuracy @118
	Java_com_essentialreality_CP5DLL_P5_1SetPrediction @119
	Java_com_essentialreality_CP5DLL_P5_1RestoreMouse @120
	Java_com_essentialreality_CP5DLL_P5_1UnRestoreMouse @121

    P5_SetTrackerUnwarp @122
	P5_GetTrackerUnwarp @123


Def file produced:
LIBRARY P5DLL.dll
EXPORTS
??0CP5DLL@@QAE@XZ
??1CP5DLL@@QAE@XZ
??4CEnumerator@@QAEAAV0@ABV0@@Z
??4CP5DLL@@QAEAAV0@ABV0@@Z
?CloseHidDevice@CEnumerator@@QAEXPAU_HID_DEVICE@@@Z
?FindHidDevice@CEnumerator@@QAE_NPAPAU_HID_DEVICE@@PAK@Z
?OpenHidDevice@CEnumerator@@AAEEPAXPAU_SP_DEVICE_INTERFACE_DATA@@PAU_HID_DEVICE@@@Z
?P5_CalibrateBendSensors@CP5DLL@@QAEXH@Z
?P5_CalibratePositionData@CP5DLL@@QAEXH@Z
?P5_Close@CP5DLL@@QAEXXZ
?P5_GetClickSensitivity@CP5DLL@@QAEXHPAH00@Z
?P5_GetLastError@CP5DLL@@QAEIPAH0@Z
?P5_GetMouseButtonAllocation@CP5DLL@@QAEXHPAH00@Z
?P5_GetMouseState@CP5DLL@@QAEIH@Z
?P5_GetMouseStickTime@CP5DLL@@QAEHH@Z
?P5_Init@CP5DLL@@QAEIXZ
?P5_SaveBendSensors@CP5DLL@@QAEXH@Z
?P5_SetClickSensitivity@CP5DLL@@QAEXHEEE@Z
?P5_SetMouseButtonAllocation@CP5DLL@@QAEXHHHH@Z
?P5_SetMouseState@CP5DLL@@QAEXHI@Z
?P5_SetMouseStickTime@CP5DLL@@QAEXHE@Z
Java_com_essentialreality_CP5DLL_00024P5Data_update
Java_com_essentialreality_CP5DLL_00024P5Data_updateFull
Java_com_essentialreality_CP5DLL_00024P5Info_update
Java_com_essentialreality_CP5DLL_00024P5State_update
Java_com_essentialreality_CP5DLL_P5_1CalibrateBendSensors
Java_com_essentialreality_CP5DLL_P5_1CalibratePositionData
Java_com_essentialreality_CP5DLL_P5_1ClearArchive
Java_com_essentialreality_CP5DLL_P5_1Close
Java_com_essentialreality_CP5DLL_P5_1Doit
Java_com_essentialreality_CP5DLL_P5_1GetACAdaptorStatus
Java_com_essentialreality_CP5DLL_P5_1GetClickSensitivity
Java_com_essentialreality_CP5DLL_P5_1GetLastError
Java_com_essentialreality_CP5DLL_P5_1GetMouseButtonAllocation
Java_com_essentialreality_CP5DLL_P5_1GetMouseState
Java_com_essentialreality_CP5DLL_P5_1GetMouseStickTime
Java_com_essentialreality_CP5DLL_P5_1PitchGlove
Java_com_essentialreality_CP5DLL_P5_1RestoreMouse
Java_com_essentialreality_CP5DLL_P5_1RollGlove
Java_com_essentialreality_CP5DLL_P5_1SaveBendSensors
Java_com_essentialreality_CP5DLL_P5_1SetClickSensitivity
Java_com_essentialreality_CP5DLL_P5_1SetFilterAmount
Java_com_essentialreality_CP5DLL_P5_1SetFilterMode
Java_com_essentialreality_CP5DLL_P5_1SetForwardZ
Java_com_essentialreality_CP5DLL_P5_1SetGlovePos
Java_com_essentialreality_CP5DLL_P5_1SetInterfaceMode
Java_com_essentialreality_CP5DLL_P5_1SetLedPos
Java_com_essentialreality_CP5DLL_P5_1SetMouseButtonAllocation
Java_com_essentialreality_CP5DLL_P5_1SetMouseState
Java_com_essentialreality_CP5DLL_P5_1SetMouseStickTime
Java_com_essentialreality_CP5DLL_P5_1SetPrediction
Java_com_essentialreality_CP5DLL_P5_1SetRequiredAccuracy
Java_com_essentialreality_CP5DLL_P5_1SetSensitivity
Java_com_essentialreality_CP5DLL_P5_1SetTowerPos
Java_com_essentialreality_CP5DLL_P5_1SetUnits
Java_com_essentialreality_CP5DLL_P5_1SpinTowerRight
Java_com_essentialreality_CP5DLL_P5_1TiltTowerForward
Java_com_essentialreality_CP5DLL_P5_1TiltTowerRight
Java_com_essentialreality_CP5DLL_P5_1UnRestoreMouse
Java_com_essentialreality_CP5DLL_P5_1YawGlove
P5_CalibrateBendSensors
P5_CalibratePositionData
P5_ClearArchive
P5_Close
P5_GetACAdaptorStatus
P5_GetAbsolutePos
P5_GetBendCalibration
P5_GetButtons
P5_GetCP5
P5_GetCP5DLL
P5_GetCalibrationData
P5_GetClickSensitivity
P5_GetCount
P5_GetData
P5_GetDataPointer
P5_GetFeature
P5_GetFeatureReport
P5_GetFingerBends
P5_GetInfo
P5_GetInfoPointer
P5_GetLastError
P5_GetMouseButtonAllocation
P5_GetMouseState
P5_GetMouseStickTime
P5_GetPrivatePointer
P5_GetRawFingerBends
P5_GetRelativeAvgPos
P5_GetRelativePos
P5_GetRotation
P5_GetState
P5_GetStatePointer
P5_GetThreadStatus
P5_GetTrackerUnwarp
P5_Init
P5_PitchGlove
P5_RestoreMouse
P5_RollGlove
P5_SaveBendSensors
P5_SetClickSensitivity
P5_SetFeature
P5_SetFeatureReport
P5_SetFilterAmount
P5_SetFilterMode
P5_SetForwardZ
P5_SetGlovePos
P5_SetGloveRotMat
P5_SetInterfaceMode
P5_SetLedPos
P5_SetMouseButtonAllocation
P5_SetMouseState
P5_SetMouseStickTime
P5_SetPrediction
P5_SetRequiredAccuracy
P5_SetSensitivity
P5_SetTowerPos
P5_SetTowerRotMat
P5_SetTrackerUnwarp
P5_SetUnits
P5_SpinTowerRight
P5_TiltTowerForward
P5_TiltTowerRight
P5_UnRestoreMouse
P5_YawGlove


Not sure which ones right.

Oh, and for reference,

p5.d.i produced by blitzmax
import brl.blitz
P5HEAD_SEPARATION#=51.2#
P5_THUMB=0
P5_INDEX=1
P5_MIDDLE=2
P5_RING=3
P5_PINKY=4
P5_FILTER_NONE=0
P5_FILTER_DEADBAND=1
P5_FILTER_AVERAGE=2
P5_FILTER_DEADBEND=1
P5ERROR_NONE=0
P5ERROR_NOP5DETECTED=1
P5ERROR_P5DISCONNECTED=2
P5ERROR_P5CONNECTED=3
P5ERROR_INVALID_P5ID=4
P5ERROR_INVALID_P5GLOVETYPE=5
P5ERROR_WRONGFIRMWAREVER=6
P5ERROR_EXCEPTION=7
P5ERROR_GETTIME=8
P5ERROR_PARSEBEND=9
P5ERROR_PARSEBUTTONS=10
P5ERROR_PARSELEDNUM=11
P5ERROR_PARSELED=12
P5ERROR_UNWARP=13
P5ERROR_PROCESS=14
P5ERROR_PROCESSROTATION=15
P5ERROR_PROCESSRELATIVEPOSITION=16
P5ERROR_PROCESSRELATIVEAVGPOSITION=17
P5ERROR_PROCESSROTATIONREAL=18
P5ERROR_PROCESSABSOLUTEPOSITION=19
P5ERROR_PROCESSLEDPOSITIONS=20
P5ERROR_INTERNAL=21
P5GLOVETYPE_RIGHTHAND=0
P5GLOVETYPE_LEFTHAND=1
P5GLOVEBACKWARDS_NOT=0
P5GLOVEBACKWARDS_THUMBLITTLE=1
P5GLOVEBACKWARDS_NOTHUMB=2
P5GLOVEBACKWARDS_UPSIDEDOWN=3
P5GLOVEBACKWARDS_DONTWORRY=4
P5_UNITS=1
P5_CM#=0.0496094#
P5_MM#=0.496094#
P5_INCHES#=0.0195313#
P5_FEET#=0.0016276#
P5_M#=0.000496094#
P5_KM#=4.96094e-007#
P5_SECONDS#=1#
P5_MINUTES#=0.0166667#
P5_HOURS#=0.000277778#
P5_FRAME#=0.0239808#
P5_KPH#=0.00178594#
P5_MPS#=0.000496094#
P5_MPSPS#=0.000496094#
P5_DEGREES#=1#
P5_RADIANS#=0.0174533#
P5_REVOLUTIONS#=0.00277778#
P5MODE_RELATIVE=0
P5MODE_ABSOLUTE=1
P5MODE_RELATIVEAVG=2
P5MODE_FILTERED=3
P5MODE_LED0=4
P5MODE_LED1=5
P5MODE_LED2=6
P5MODE_LED3=7
P5MODE_LED4=8
P5MODE_LED5=9
P5MODE_LED6=10
P5MODE_LED7=11
P5MODE_LED8=12
P5MODE_LED9=13
P5MODE_LEDBRIGHT=14
P5MODE_LEDBEST=15
P5MODE_ORIGINAL_PYR=0
P5MODE_BETTER_PYR=2560
P5MODE_BETTER_YPR=2816
P5MODE_BETTER_RYP=3072
P5MODE_BETTER_RPY=3328
P5MODE_BETTER_YRP=3584
P5MODE_BETTER_PRY=3840
P5MODE_BETTER_MIX=4096
P5MODE_FILTERED_PYR=5120
P5MODE_FILTERED_YPR=5376
P5MODE_FILTERED_RYP=5632
P5MODE_FILTERED_RPY=5888
P5MODE_FILTERED_YRP=3584
P5MODE_FILTERED_PRY=3840
P5MODE_FILTERED_MIX=6144
P5_Close()S="P5_Close@0"
P5_Init@()S="P5_Init@0"
P5_SetClickSensitivity(P5Id%%,leftvalue@,rightvalue@,middlevalue@)S="P5_SetClickSensitivity@20"
P5_GetClickSensitivity(P5Id%%,leftclick%%*,rightclick%%*,middleclick%%*)S="P5_GetClickSensitivity@20"
P5_SaveBendSensors(P5Id%%=-1)S="P5_SaveBendSensors@8"
P5_CalibrateBendSensors(P5Id%%=-1)S="P5_CalibrateBendSensors@8"
P5_CalibratePositionData(P5Id%%=-1)S="P5_CalibratePositionData@8"
P5_GetMouseState@(P5Id%%=0)S="P5_GetMouseState@8"
P5_SetMouseState(P5Id%%,state%%)S="P5_SetMouseState@16"
P5_SetMouseStickTime(P5Id%%,time@)S="P5_SetMouseStickTime@12"
P5_GetMouseStickTime%%(P5Id%%=0)S="P5_GetMouseStickTime@8"
P5_GetMouseButtonAllocation(P5Id%%,leftclick%%*,rightclick%%*,middleclick%%*)S="P5_GetMouseButtonAllocation@20"
P5_SetMouseButtonAllocation(P5Id%%,leftclickfinger%%,rightclickfinger%%,middleclickfinger%%)S="P5_SetMouseButtonAllocation@32"
P5_GetLastError@(P5Id%%*,ErrorCode%%*)S="P5_GetLastError@8"
P5_GetCount%%()S="P5_GetCount@0"
P5_GetACAdaptorStatus%%(P5Id%%=0)S="P5_GetACAdaptorStatus@8"
P5_GetBendCalibration(P5Id%%,ThumbStraight%%*,ThumbBent%%*,IndexStraight%%*,IndexBent%%*,MiddleStraight%%*,MiddleBent%%*,RingStraight%%*,RingBent%%*,PinkyStraight%%*,PinkyBent%%*)S="P5_GetBendCalibration@48"
P5_GetRawFingerBends(P5Id%%,thumb%%*,index%%*,middle%%*,ring%%*,pinky%%*)S="P5_GetRawFingerBends@28"
P5_SetUnits(units#=1#)S="P5_SetUnits@4"
P5_SetForwardZ(z%%=1)S="P5_SetForwardZ@8"
P5_SetTowerPos(P5Id%%,x#,y#,z#)S="P5_SetTowerPos@20"
P5_TiltTowerForward(P5Id%%,degrees#)S="P5_TiltTowerForward@12"
P5_SplongowerRight(P5Id%%,degrees#)S="P5_SplongowerRight@12"
P5_TiltTowerRight(P5Id%%,degrees#)S="P5_TiltTowerRight@12"
P5_SetSensitivity(P5Id%%,multiplier#)S="P5_SetSensitivity@12"
P5_SetLedPos(P5Id%%,led%%,x#,y#,z#)S="P5_SetLedPos@28"
P5_SetGlovePos(P5Id%%,x#,y#,z#)S="P5_SetGlovePos@20"
P5_PitchGlove(P5Id%%,theta#)S="P5_PitchGlove@12"
P5_YawGlove(P5Id%%,theta#)S="P5_YawGlove@12"
P5_RollGlove(P5Id%%,theta#)S="P5_RollGlove@12"
P5_SetInterfaceMode(mode%%)S="P5_SetInterfaceMode@8"
P5_SetFilterMode(filters%%)S="P5_SetFilterMode@8"
P5_SetFilterAmount(ExtraFrames%%,DeadDistance#)S="P5_SetFilterAmount@12"
P5_ClearArchive(P5Id%%=-1)S="P5_ClearArchive@8"
P5_SetRequiredAccuracy(accuracy#=10#)S="P5_SetRequiredAccuracy@4"
P5_SetPrediction(prediction%%=1)S="P5_SetPrediction@8"
P5_RestoreMouse(P5Id%%=-1)S="P5_RestoreMouse@8"
P5_UnRestoreMouse(P5Id%%=-1)S="P5_UnRestoreMouse@8"
P5_GetAbsolutePos(P5Id%%,x#*,y#*,z#*)S="P5_GetAbsolutePos@20"
P5_GetRelativePos(P5Id%%,x#*,y#*,z#*)S="P5_GetRelativePos@20"
P5_GetRelativeAvgPos(P5Id%%,x#*,y#*,z#*)S="P5_GetRelativeAvgPos@20"
P5_GetRotation(P5Id%%,yaw#*,pitch#*,roll#*)S="P5_GetRotation@20"
P5_GetFingerBends(P5Id%%,thumb#*,index#*,middle#*,ring#*,pinky#*)S="P5_GetFingerBends@28"
P5_GetButtons(P5Id%%,A#*,B#*,C#*,D#*)S="P5_GetButtons@24"
P5_GetThreadStatus@(P5Id%%)S="P5_GetThreadStatus@8"


The p5.d.a file has a few references to __bb_p5_p5.

You need an import blah.a in your bmx file.

lol. Well, I've added that. Still doesnt work

Here's a zip of my bot.mod directory:

http://blitzstuff.250free.com/zips/botmod.zip

I took out the compiled files so you'll have to bmk makemods bot or a windows comp.

take out the "win32" and you're away!

I also suggest renaming your p5.a file p5lib.a to avoid any unnecesary confusion, although it seems to be working as is.

Well, don't I look like a silly sausage.

Ok, well, that didnt work. did you get it working over there?

I noticed I had quotes aroung my inclusion of p5lib.a, I took those out but now i'm getting this from the module compilation:

C:\BLITZM~1\bin>bmk makemods bot
Compiling:p5.bmx
Compile Error:Can't find interface for module 'p5lib.a'
[C:\BLITZM~1\mod\bot.mod\p5.mod/p5.bmx;1;1]
Build Error: failed to compile C:/BLITZM~1/mod/bot.mod/p5.mod/p5.bmx


Maybe I can make a tutorial about my "experience" when I'm done.

[edit] Oh, also, you may notice I'm attempting to do ByRef values with Ptr appended to the ByRef parameters of Extern functions. I just noticed that this is Var in max2d module for internal byref. Which do I use?

you want to name it
libp5.a
and in the p5.bmx file to include it just have import "-lp5"
which should fix your problem.

Off topicish,
but drago/SKID(Fix it fix it fix it), tt's a bug in the compiler.

Currently, I have trinity set up as a series of modules within a dsi.mod folder, all compiled automatically using Bmk MakeMods -v DSI - Does so OK.


Now, actually compiling an example app using it,

WITH Debug on : Compiles fine.
With debug off : Linker can not find texture.a or etc.
So bot, try putting the debugger on please and let me know if does the same. Well let mark know, not like I can do anything about it :)


And bmk has a few annoying bugs as well, relating to compiling.(reporting missing references once, then mysteriously compiling ok simply by recompiling.)

(fix it)

Antony, have you done "makemods" plus "makemods -r" (for release)?

Tried it and it works fine after building releases modules. Thanks.

:O Holy crap. That's what was wrong. I put it in release mode and it worked fine. This is very, very odd BRL.... Ohwell. Least I can compile stuff now. ;)

Now to see if the module actually does what it says on the box...

Well it sorta works... I can init it and get the number of gloves I have but I'm having problems with Ptr.

Line of the C Header for DLL:
P5DLL_API void __stdcall P5_GetAbsolutePos(int P5Id, float *x, float *y, float *z);

My version in .bmx:
Function P5_GetAbsolutePos(P5Id:Int, x:Float Ptr, y:Float Ptr, z:Float Ptr)


ExampleCode:
If P5_Init()=0 Then RuntimeError("Could not init P5")
Print "You have "+P5_GetCount()+" gloves."

While Not KeyHit(KEY_ESCAPE)
	Local x:Float, y:Float,z:Float
	P5_GetAbsolutePos(0,Varptr x,Varptr y,Varptr z)
	Print x+", "+y+", "+z
Wend


This will print the number of gloves, and then prints out one x,y,z like:

6.86116086e-039, 3.21402937e-039, 0.000000000

One prob with this is that it might not even be my fault, as all the examples use the new way of getting data, which is to recieve a pointer to a structure and then read in data from the structure whenever you want it. I'll try reading raw stuff from the memory of the struct next.

you can make a type that is a clone of the structure, and pass it. and it should be filled with the info :)

Ugg. dunno. I think I'm gonna write a wrapper file and see if I can include that, and get bmax to autocompile it for me.

I've blitzified the types, the problem is converting a pointer to a blitz type:

If P5_Init()=0 Then RuntimeError("Could not init P5")

Local State:P5State Ptr
State=P5_GetStatePointer(0)

Print "You have "+P5_GetCount()+" gloves."

While Not KeyHit(KEY_ESCAPE)
	Print State[0].x#+", "+State[0].y#+", "+State[0].z#
	FlushMem
Wend


:( MEES (Memory Exception Error)

I'm gonna try writing some C code to convert all these structs ByRefs, etc into straight function returns.

Ok, I've figured out I can get a pointer to the structure containing the data, and read raw stuff from it :) It works!

How did you manage to pass the structure?

Is there an "Official" linking to dll guide one year later??

Maybe now? I seriously need help!