This declare is driving me crazy

I’ve changed the names a bit because they are under and NDA, but basically here is how the function is described in the documents:

long Initialize(DWORD DevID, void *Id, void *HDev)

Here is how I am trying to declare it:

Soft Declare Function Initialize Lib CONST_FRAMEWORK (DevID As Integer, Id as Ptr, HDev As Ptr) As Integer

Here is how I am trying to call it (although I have also tried using memory blocks instead of pointers):

[code]dim DevID as integer = 0
Dim ID as ptr
Dim HDev As ptr

dim result as integer = Initialize(DevID, ID, HDev)[/code]

No matter what I do the debug app just crashes with EXC_BAD_ACCESS.

I would really appreciate some help if anyone has a moment.

Are you sure *Foo is a Ptr not a Handle ?

What is C function header?

those void* may be ptr to output, so you may need to pass something byref there.

Thanks both of you for responding.

It looks like the way I was declaring the function was correct, because I can get it to work when I use memoryblocks like this:

[code]Dim DevID as integer = 0

//DeviceListPointer is pointing to an array of devices returned from another declare
Dim deviceList As memoryblock = deviceListPointer.ptr(0)

//device pointing to an individual device in the device list
Dim device As memoryblock = deviceList.ptr(2)

Dim deviceName As memoryblock = device.ptr(0)
Dim HDevice As New MemoryBlock(8)

//This Works
result = Initialize(DevID, deviceName, HDevice)[/code]

DeviceName here is derived from the result of another declare. When I examine it in the debugger it is clearly pointing to a string representation of the device name.

The problem seems to come when I want to assign the device name explicitly. I thought I could just do something like:

dim mbDeviceName as MemoryBlock mbDeviceName = "MyDevice" dim deviceName as MemoryBlock = mbDeviceName.ptr(0)

But that fails. When I examine deviceName in the debugger in this case, it is empty, not clearly pointing to a location with a value of “MyDevice”.

I think I have determined that this was not actually a problem with the declare, but a problem with when I was calling it and how it was expecting memory to be allocated. Thanks again for the help, I’m pretty sure I was barking up the wrong tree.