DLLImport

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a WAPI in C++, which pass an array as parameter to a function

DWORD WINAPI Function1 (DWORD *IN_TBL)

DWORD Var1[32]
Var1[1]=1
..
DWORD dwRv = Function1 (Var1)

This is what I did in vb.net, It doesn't work

<DllImport("example.dll", EntryPoint:="_Function1@16")>
Private Shared Function Function1(ByVal Function1 As Integerr) As Intege
End Functio

Dim ptr1 as intPt
Private Var1() As Intege
Redim Var1(31
..
intPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(Var1)
Dim iResult as integer = Function1 (intPtr.ToInt32

1. How could I declare integer array and this funciton with DLLIMPORT in vb.net?
2. How could pass integer array to the function

Thanks
 
Qindong Z. said:
I have a WAPI in C++, which pass an array as parameter to a function.


DWORD WINAPI Function1 (DWORD *IN_TBL);

DWORD Var1[32];
Var1[1]=1;
...
DWORD dwRv = Function1 (Var1);


This is what I did in vb.net, It doesn't work.

<DllImport("example.dll", EntryPoint:="_Function1@16")> _
Private Shared Function Function1(ByVal Function1 As Integerr) As Integer
End Function

I've found using the EntryPoint declaritive can cause problems, and you
don't need it anyway.
You should also be getting an error because from my experiance, PInvoke must
be static and public, but using just the Public keyword suffices fine...
Dim ptr1 as intPtr
Private Var1() As Integer
Redim Var1(31)
...
intPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(Var1))
Dim iResult as integer = Function1 (intPtr.ToInt32)

1. How could I declare integer array and this funciton with DLLIMPORT in vb.net?
2. How could pass integer array to the function?

Thanks.

If I'm understanding you right, This should be what it looks like....
<DllImport("example.dll"> _
Public Function Function1(ByVal Input() As Integer) As Integer()
End Function

Now for th rest of it, this is kind of confusing to me.... The API function
accepts a Integer array and returns one? Could you post the prototype of
the function, that may help...

HTH,
Sueffel
 
I have a WAPI in C++, which pass an array as parameter to a function.


DWORD WINAPI Function1 (DWORD *IN_TBL);

DWORD Var1[32];
Var1[1]=1;
...
DWORD dwRv = Function1 (Var1);


This is what I did in vb.net, It doesn't work.

<DllImport("example.dll", EntryPoint:="_Function1@16")> _
Private Shared Function Function1(ByVal Function1 As Integerr) As Integer
End Function

Dim ptr1 as intPtr
Private Var1() As Integer
Redim Var1(31)
...
intPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(Var1))
Dim iResult as integer = Function1 (intPtr.ToInt32)

1. How could I declare integer array and this funciton with DLLIMPORT in vb.net?

<DllImport("example.dll", EntryPoint:="_Function1@16")> _
Private Shared Function Function1 (ByVal IN_TBL() As Integer) As Integer
End Function
2. How could pass integer array to the function?

Dim intArray(31) As Integer
Dim retVal As Integer = Function1(intArray)
 
Back
Top