Real Software Forums

External method in Windows DLL
Page 1 of 1

Author:  ruyterb [ Sun Oct 09, 2011 10:29 am ]
Post subject:  External method in Windows DLL

Although I would assume that my question is standard, I could not find an answer via Google or through the examples included with RealStudio.
So here we go...

I am trying to use a function implemented in a Windows DLL.
For this I declare an external method. In general this works (other functions work ok) but there is one external function that I cannot get to work. This function "returns" a value not only as a standard return value but also modifies a variable in the function call.

This is the function as defined for Visual Basic:
Function USB_Read Lib "USB.dll" (ByVal handle As Long, ByVal block_index As Long, ByVal buffer512 As Any) As Long

So besides a return value (error code) from the function, the actual content is returned in bufer512

In RealStudio I have implemented this as:
Declare Function USB_Read Lib "USB.dll" Alias "USB_Read" (ByVal handle As int32, ByVal block_index As int32, ByVal buffer512 As Ptr) as int32

In the application I call the function as follows:

dim usbString as MemoryBlock
dim n as int32

usbString = new MemoryBlock(512)

n = USB_Read(handleUSB, 0, usbString.Ptr(0) )

note: the handleUSB is an int32 that was obtained by another external function that returns the handle (this works correct).

I then try to get the value that was returned by:
TextField1.Text = dongleString.StringValue(1,20)

but it remains empty...
I assume I am not doing this correctly?

Any help would be great.

Author:  pawn [ Sun Oct 09, 2011 4:39 pm ]
Post subject:  Re: External method in Windows DLL

dim usbString as new MemoryBlock(512)
dim n as int32

n = USB_Read(handleUSB, 0, usbString )

Author:  pawn [ Sun Oct 09, 2011 4:39 pm ]
Post subject:  Re: External method in Windows DLL

err, try that instead

Author:  ruyterb [ Thu Oct 13, 2011 11:23 am ]
Post subject:  Re: External method in Windows DLL

Yes: that did it!

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group