DLL Trouble

Hi guys,
Having some trouble with a DLL, it is supposed to gather information from an external device, by passing a pointer to an array of double.
What I am getting back though is garbage

Here is the code I have in VB:
Dim ptr3 As Long
Dim ptr4 As Long
Dim data0(0 To 100) As Double
Dim data1(0 To 100) As Double

ptr3 = VarPtr(data0(0))
ptr4 = VarPtr(data1(0))

Call PX_GetTimeBins(0, channel0, 1, ptr3, 9, False)
Call PX_GetTimeBins(0, channel1, 1, ptr4, 9, False)

Text5.text = data0(0)
Text6.text = data1(0)

This is what I have in the reference module:

Declare Function PX_GetTimeBins Lib "C:Documents and SettingsAndrew MeaneyDesktopProjectDriversSNSL_API.dll" (ByVal uiDeviceNo As Integer, ByVal channelmask As String, ByVal channelNo As Integer, ByVal bins As Long, ByVal binCount As Long, ByVal adoptBuffer As Boolean) As Integer

And this is the prototype given to me:

SNSL_STATUS PX_GetTimeBins(UINT devNo, UCHAR channelMask, UINT channelNo, ULONG **bins, ULONG binCount , bool adoptBuffer)

Any help would be greatly appreciated, thanks.

Comments

  • One thing: you sure it's double? It's defined as ULONG**.

    What happens if you try:

    [code]
    Declare Function PX_GetTimeBins Lib "..." (ByVal uiDeviceNo As Integer, _
    ByVal channelmask As String, ByVal channelNo As Integer, _
    [color=Blue]ByRef[/color] bins As [color=Blue]Double[/color], ByVal binCount As Long, _
    ByVal adoptBuffer As Boolean) As Integer

    ...

    Call PX_GetTimeBins(0, channel0, 1, [color=Blue]data0[/color], 9, False)
    [/code]

    I must say this is quite dangerous code. As I see, it takes a ULONG**, which basically means the adress of the array pointer. Which means it could set your Double array variable to another location. Meaning you could get a memory leak...

    What's the description you get with the function? (like explanation of what it does, and what it expects to get as parameters).

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion