473,408 Members | 2,009 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Translate Visual C++ to VB.NET

I tried to do some 'DLLImport' on a DLL. The actual source code was written
in 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
May 12 '06 #1
1 1815
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
May 12 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: inquirydog | last post by:
Hello- I, the inquirydog, would like to solicit suggestions for a new web page I am making: I am creating a simple website that will translate concepts between windows os's, Linux, and the...
7
by: Bengt Richter | last post by:
Just thought None as the first argument would be both handy and mnemonic, signifying no translation, but allowing easy expression of deleting characters, e.g., s = s.translate(None,...
7
by: thwei | last post by:
How to translate this to c++ public new Bar this { get{ return (Bar)base; } }
12
by: Eirik Eldorsen | last post by:
Could someone please help me translate this into C#? Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender Eirik Eldorsen
6
by: VBTricks.de.vu Webmaster | last post by:
Hello, in VB6 I used to translate my application by setting the tag-property of all controls, menu-entries... to a number which has been linked to a string (array). Then I went through all...
6
by: bobueland | last post by:
The module string has a function called translate. I tried to find the source code for that function. In: C:\Python24\Lib there is one file called string.py I open it and it says
1
by: jongjong | last post by:
elow...i am a new in visual basic programming can you help me in opening a text files that contain a certain langauage and translate it to another langauge when it is open in visual basic in the...
9
bvdet
by: bvdet | last post by:
I have done some more work on a simple class I wrote to calculate a global coordinate in 3D given a local coordinate: ## Basis3D.py Version 1.02 (module macrolib.Basis3D) ## Copyright (c) 2006...
3
by: Daniel =?iso-8859-1?Q?Lidstr=F6m?= | last post by:
Hello! I'd like to know if there are good ways to let someone translate windows forms. We're using Visual Studio 7.1 and I've seen the GUI designer lets you change language very easily. However,...
3
by: Kenneth McDonald | last post by:
I have the need to occasionally translate a single word programatically. Would anyone have a Python script that would let me do this using Google (or another) translation service? Thanks, Ken
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.