convert to vb.net

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

Guest

hi i got the following from c, how do i convert into vb.net?

typedef struct _SP_DEVICE_INTERFACE_DETAIL_DATA {
DWORD cbSize;
TCHAR DevicePath[ANYSIZE_ARRAY];
} SP_DEVICE_INTERFACE_DETAIL_DATA, *PSP_DEVICE_INTERFACE_DETAIL_DATA;
 
Try:

Structure _SP_DEVICE_INTERFACE_DETAIL_DATA

Public cbSize As Integer
Public DevicePath(ANYSIZE_ARRAY - 1) As Char

End Structure
 
Staphany,

Stephany Young said:
Structure _SP_DEVICE_INTERFACE_DETAIL_DATA
[...]
Public DevicePath(ANYSIZE_ARRAY - 1) As Char

The line above won't work...
 
In that case try:

Public Class _SP_DEVICE_INTERFACE_DETAIL_DATA

Private Const ANYSIZE_ARRAY As Integer = 1024

Public cbSize As Integer
Public DevicePath(ANYSIZE_ARRAY - 1) As Char

End Class


Herfried K. Wagner said:
Staphany,

Stephany Young said:
Structure _SP_DEVICE_INTERFACE_DETAIL_DATA
[...]
Public DevicePath(ANYSIZE_ARRAY - 1) As Char

The line above won't work...
 
Stephany Young said:
Public Class _SP_DEVICE_INTERFACE_DETAIL_DATA

Private Const ANYSIZE_ARRAY As Integer = 1024

Public cbSize As Integer
Public DevicePath(ANYSIZE_ARRAY - 1) As Char

End Class

This won't work too in a p/invoke scenario because the function is expecting
a value type (structure).
 
Stephany Young said:
I didn't notice the OP asking about a p/invoke scenario.

Oh, I thought that's self-evident :-). Otherwise I don't understand why the
OP is posting the question at all.
 
Several issues exist here:
1) The Layout of the Structure needs to be defined
2) The Windows32 API expects a C-String -- this is what the StringBuilder
class is ideal for
3) The cbSize member needs to pass the size of the structure
4) Int32 should (probably) be used in lieu of Integer (eventhough they
currently mean the same thing -- with the advent of Win64, I expect that the
definition of integer will eventually widen).

<StructLayout(LayoutKind.Explicit)> Structure
SP_DEVICE_INTERFACE_DETAIL_DATA

<FieldOffset(0)> Public cbSize As Int32
<FieldOffset(4)> Public DevicePath As StringBuilder(ANYSIZE_ARRAY - 1)

End Structure
 
stand__sure said:
4) Int32 should (probably) be used in lieu of Integer (eventhough they
currently mean the same thing -- with the advent of Win64, I expect that
the
definition of integer will eventually widen).

I prefer 'Int32' when dealing with unmanaged code too, however, 'Integer'
will remain an alias for 'Int32' in 64-bit versions of .NET.
 
Back
Top