הערה
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות להיכנס או לשנות מדריכי כתובות.
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות לשנות מדריכי כתובות.
Question
Wednesday, August 3, 2011 2:40 PM
typedef
struct
{
unsigned
long length;
unsigned
char *data;
// binary data
} ABUFFER;
ABUFFER id;
unsigned
char sID[64];
memset(sID, 0,sizeof (sID));
id.length =sizeof(sID);
id.data = sID;
Need some help to convert above line to VB.net.
Thanks in advance
tan
// length of binary data
All replies (3)
Wednesday, August 3, 2011 6:47 PM ✅Answered | 1 vote
Sometimes translate C/C++ to VB.NET line by line dont seem to work well or not working at all without compiler error unless you understand what the code does. Below is what i came up with
Public Structure ABUFFER
Public length As UInteger
Public data() As Byte
End Structure
Sub setupStruct()
Dim id As New ABUFFER
Dim sID() As Byte = New Byte(63) {}
'memset is not needed in vb.net
id.length = sID.Length
id.data = sID
End Sub
kaymaf
CODE CONVERTER SITE
http://www.carlosag.net/Tools/CodeTranslator/.
http://www.developerfusion.com/tools/convert/csharp-to-vb/.
Thursday, August 4, 2011 2:39 AM
Hmmmm... i'm still getting error--> Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
I'm try call function in C's DLL with PInvoke method which mean
In C Code
int
GetStatus (IN UCHAR *ID,OUT UCHAR *Status,OUT USHORT *Count,OUT ULONG *Minute,OUT ABUFFER *SID);
In VB.Net, i have this line
<DllImport("somespi.dll")> Public Shared Function _
GetStatus(ByVal ID() As Byte,<Out()> ByVal Status As Byte, <Out()> ByVal Count() As UInt16, <Out()> ByVal Minute() AsUInt32, <Out()> ByVal byBuffer As ABUFFER) AsInt32 End Function
Public Structure ABUFFER
Public length As UInteger
Public data() As Byte
End Structure
Sub setupStruct()
Dim id As New ABUFFER, Dim Status As Byte,Dim Count() As UInt16={0}, Dim Minute() As UInt32={0}
Dim sID() As Byte = New Byte(63) {}
'memset is not needed in vb.net
id.length = sID.Length
id.data = sID
GetStatus('test',Status ,Count,Minute)
End Sub
Is that anything wrong with the code?
tan
Thursday, August 4, 2011 4:10 PM
Did you write C/C++ code yourself or is from someone?
As i said in my first post, sometimes is pain in the neck to know exact data type when converting C/C++ to .net. You have to play around with other possibilities such as UChar = string
By the way, if you have access to the C/C++ code, you can post this issue in C++ forum maybe someone can shed light on it for you.
C++ forum : http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/threads
kaymaf
CODE CONVERTER SITE