|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Translate Visual C++ to VB.NETin Visual C++. Unfortunately I can't get the VB.NET syntax right for this function call. Can someone provide me with the correct VB.NET syntax? ---------------------------------------- #define S00X_ANTICOLL_ARRAY 64 int MSTX_EXPORT S00X_ReadC220(BOOL useconfig, BOOL changeconfig, BOOL anticollision, double listeningtime, unsigned char *nbchips, unsigned char chips[][S00X_ANTICOLL_ARRAY], unsigned char *cmdstatus); <DllImport("MedioSTX.dll")> _ Private Function S00X_ReadC220(ByVal useconfig As Boolean, ByVal changeconfig As Boolean, ByVal anticollision As Boolean, ByVal listeningtime As Double, ByRef nbchips As Char, ByRef chips()() As Char, ByRef cmdStatus As Char) As Integer End Function Hi,
First of all, char * is a String (LPStr actually). But the chips parameter poses a difficulty indeed, since AFAIK [][] means an continuous sequence of strings, not even an array of LPStr's 8=[. And I don't see a way to pass this except allocating the memory and positioning strings manually. So that's the declarations: ~ Const S00X_ANTICOLL_ARRAY As Integer = 64 Declare Ansi Function S00X_ReadC220 Lib "MedioSTX.dll" ( _ ByVal useconfig As Boolean, _ ByVal changeconfig As Boolean, _ ByVal anticollision As Boolean, _ ByVal listeningtime As Double, _ <MarshalAs(UnmanagedType.LPStr)> ByVal nbchips As String, _ ByVal chips As IntPtr, _ <MarshalAs(UnmanagedType.LPStr)> ByVal cmdstatus As String _ ) As Integer ~ And the usage: ~ Protected Overrides Sub OnClick(ByVal e As System.EventArgs) MyBase.OnClick(e) Dim ChipsA() As String = {"JC Denton", "Alex Jacobson", "Jaime Reyes", "Joseph Manderley"} ' I presume you have a string array called ChipsA ' strings' length must not exceed S00X_ANTICOLL_ARRAY, ' or you'll get garbage! Dim base As IntPtr, cur As Integer base = Marshal.AllocHGlobal(S00X_ANTICOLL_ARRAY * ChipsA.Length) cur = base.ToInt32 For Each str As String In ChipsA 'Copy the string... Marshal.Copy(System.Text.Encoding.Default.GetBytes(str), 0, New IntPtr(cur), str.Length) '... and append the terminating NULL. Marshal.WriteByte(New IntPtr(cur), str.Length, CByte(0)) cur += S00X_ANTICOLL_ARRAY Next 'Use function with base as chips: 'S00X_ReadC220(blah blah blah...) Marshal.FreeHGlobal(base) End Sub ~ Whew... This was a bit harder that I initially expected.. 8=] Unfortunately, I don't have a library to test this on, but it should work. Hope this helps, Roman
Multiple fields in a single textbox
Image Resource - not released Reading and Writing Text Files Sending an Email from .net? How to import always the FIRST available sheet from EXCEL-File Closing all forms at once How to create a new sheet in EXCEL-File via OLEDBProvider Inherent encryption in .NET 2.0? dot.net com class function Copy HTML Table To CSV |
|||||||||||||||||||||||