Translate from C/C++ to VB.net

  • Thread starter Thread starter Petar Popara
  • Start date Start date
P

Petar Popara

Please could someone translate this for me from C/C++ to VB.net?

#define MY_CONST 1

typedef struct _MYSTRUCT {
const char* p1;
int p2;
char p3[20];
short p4;
unsigned long p5;
} MYSTRUCT;

void main()
{
HINSTANCE someDLL = LoadLibrary("some.dll");

MYSTRUCT prop;
prop.p1 = "some text";
prop.p2 = 2;
prop.p4 = 8;
prop.p5 = 10;

MYSTRUCT (*fnMyFunc)(MYSTRUCT);
fnMyFunc=(MYSTRUCT (*)(MYSTRUCT)) GetProcAddress(someDLL,"myFunc");
MYSTRUCT result = fnMyFunc(prop);
}

Thank you in advance.
 
At least, could you please tell me how can I translate:

char a[20]

and

unsigned int i?
 
Is this a proper translation?

Private Const MY_CONST = 1

<StructLayout(LayoutKind.Sequential)> Public Structure MYSTRUCT
Public p1 As String
Public p2 As Integer
<MarshalAs(UnmanagedType.ByValTStr, sizeconst:=20)> Public p3 As String
Public p4 As Short
Public p5 As Integer
End Structure

Private Declare Function myFunc Lib "some" (ByVal prop As MY_STRUCT) As
MY_STRUCT

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim prop As MY_STRUCT
Dim res As MY_STRUCT

prop.p1 = "some text..."

res = myFunc(prop)
End Sub
 
This is outside my area of expertise, so I'm asking, not declaring.
However, wouldn't 'Private Const MY_CONST = 1' be better written as
'#Const MY_CONST = 1' instead? Also, wouldn't P5 be better declared as
UInt64 rather than Integer?


Thanx,


Ralf


:
: Is this a proper translation?
:
: Private Const MY_CONST = 1
:
: <StructLayout(LayoutKind.Sequential)> Public Structure MYSTRUCT
: Public p1 As String
: Public p2 As Integer
: <MarshalAs(UnmanagedType.ByValTStr, sizeconst:=20)> Public p3 As
: String
: Public p4 As Short
: Public p5 As Integer
: End Structure
:
: Private Declare Function myFunc Lib "some" (ByVal prop As MY_STRUCT)
: As MY_STRUCT
:
: Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
: System.EventArgs) Handles MyBase.Load
: Dim prop As MY_STRUCT
: Dim res As MY_STRUCT
:
: prop.p1 = "some text..."
:
: res = myFunc(prop)
: End Sub
:
:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top