Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > API > Interfacing sensor.dll into VB


Reply
 
Thread Tools Display Modes
  #1  
Old 06-03-2007, 03:01 PM
izzy4505 izzy4505 is offline
Regular
 
Join Date: Dec 2004
Location: IL, USA
Posts: 84
Post Interfacing sensor.dll into VB (Bad DLL Calling Convention?)

I'm trying to interface the IBM ThinkPad's accelerometer chip into a VB app. After much googling, it seems that there is this sensor.dll that handles everything. I've been marginally successful at using it so far, and I was wondering if I could get some help. I've used DLLs in apps before, but with documentation, and since there is none on this one, it's been a challenge for me. Here's the details.....

I came across this page: http://www.stanford.edu/~bsuter/thinkpad-accelerometer/

This guy has some code up (http://www.stanford.edu/~bsuter/thin...ter/ApsDemo.cs) written for .NET that calls ShockproofGetAccelerometerData() in the DLL. I'd like to use that function in my app. So I have the following code in a module:

Code:
Private Declare Function ShockproofGetAccelerometerData Lib "sensor.dll" (ByRef AccelData As Long) As Long

Public Function GetAccelData(ByRef x As Long, ByRef y As Long) As Long
Dim data As Long

''''Debug.Print "spgad: " & ShockproofGetAccelerometerData(data)
ShockproofGetAccelerometerData data
Debug.Print "data: " & data

End Function
When this runs, VB keeps saying "Bad DLL calling convention." A minute ago, I was able to get it to put some values in data which I'm assuming were pointers to a structure.

Any ideas on how I should get started with this? Thanks.

Last edited by izzy4505; 06-03-2007 at 04:18 PM.
Reply With Quote
  #2  
Old 06-03-2007, 05:02 PM
izzy4505 izzy4505 is offline
Regular
 
Join Date: Dec 2004
Location: IL, USA
Posts: 84
Default Partially works...

I am able to call another method in this DLL like this....

Code:
Private Declare Sub ShockproofGetShockStatus Lib "sensor.dll" (ByRef lStatus As Long)


Dim Status As Long
ShockproofGetShockStatus Status
Debug.Print Status
Not sure if that sheds any light on the problem or not, but this function works fine.
Reply With Quote
  #3  
Old 06-05-2007, 10:39 AM
cenit33 cenit33 is offline
Regular
 
Join Date: Jan 2006
Posts: 91
Default

Try this:

You are missing AccelData structure.
Code:
Private Type AccelData
    status As Long
    x As Integer
    y As Integer
End Type
You should declare the process like this
Code:
Private Declare Sub ShockproofGetAccelerometerData Lib "sensor.dll" (ByRef data As AccelData)
You must reserv memory for the structure and put values to it
Code:
Public Function GetAccelData(ByVal x As Integer, ByVal y As Integer) As Long
	Dim data As AccelData
	
	data.x = x
	data.y = y
	''''Debug.Print "spgad: " & ShockproofGetAccelerometerData(data)
	ShockproofGetAccelerometerData data
	Debug.Print "data: " & data.status

End Function
Reply With Quote
  #4  
Old 06-06-2007, 07:26 PM
izzy4505 izzy4505 is offline
Regular
 
Join Date: Dec 2004
Location: IL, USA
Posts: 84
Question Error still exists, but I did get values!

Woot, I was able to get the x, y, and status values. However it still pops up and says "Bad DLL calling convention...". It's weird, because the first time I run the code (being called from a form... code is in a module), it prints values and then pops the error. All later attempts (even upon running again!) it pops the error first and shows no values. Code I'm testing with:

Code:
Public Function GetAccelData() As Long
Dim data As AccelData

ShockproofGetAccelerometerData data

Debug.Print data.status
Debug.Print data.x
Debug.Print data.y

End Function
I am using your function declaration and user type.
Reply With Quote
  #5  
Old 06-16-2007, 09:40 AM
izzy4505 izzy4505 is offline
Regular
 
Join Date: Dec 2004
Location: IL, USA
Posts: 84
Default

Still stumped on this one.... I can't seem to get rid of the Bad DLL calling convention. A friend of mine suggested that maybe I couldn't use the DLL because of a way it was compiled?
Reply With Quote
  #6  
Old 06-18-2007, 12:41 PM
cenit33 cenit33 is offline
Regular
 
Join Date: Jan 2006
Posts: 91
Default

Try this
Code:
Private Declare Sub ShockproofGetAccelerometerData Lib "sensor.dll" _
    (ByRef data As Any)

ShockproofGetAccelerometerData ByVal data
or this
Code:
Private Declare Sub ShockproofGetAccelerometerData Lib "sensor.dll" _
    (ByVal data As Long)

ShockproofGetAccelerometerData VarPtr(data)
or this
Code:
Private Declare Sub ShockproofGetAccelerometerData Lib "sensor.dll" _
    (ByVal data As Long)

ShockproofGetAccelerometerData ByVal VarPtr(data)
Reply With Quote
  #7  
Old 06-23-2007, 04:39 PM
izzy4505 izzy4505 is offline
Regular
 
Join Date: Dec 2004
Location: IL, USA
Posts: 84
Default VB Crashed

No luck. The first code example you gave just crashes VB. The last two left data equal to empty.
Reply With Quote
  #8  
Old 06-25-2007, 12:53 PM
Cerian Knight's Avatar
Cerian Knight Cerian Knight is offline
Multi-Technologist

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 3,040
Default

Perhaps this will explain the problem (and provide a solution if you have the required resources): http://support.microsoft.com/kb/153586
Reply With Quote
  #9  
Old 06-25-2007, 07:23 PM
izzy4505 izzy4505 is offline
Regular
 
Join Date: Dec 2004
Location: IL, USA
Posts: 84
Default

I don't have the src to the DLL, so I am unable to change the calling method. However, I stumbled across some code which may solve this problem:
http://www.pscode.com/vb/scripts/Sho...xtCodeId=49776

So far, VB has been crashing when I've tried applying the method to sensor.dll, but I'm going to keep trying.
Reply With Quote
  #10  
Old 06-25-2007, 08:31 PM
Cerian Knight's Avatar
Cerian Knight Cerian Knight is offline
Multi-Technologist

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 3,040
Default

That might be made to work. You don't need the dll source code to implement Microsoft's solution...just the ability to write and compile something similar to their 'wrapper' example.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:

Powered by liquidweb