S
Shayne H
How can I create a structure that gets passed to an API call that will
automatically set its size field?
I tried the following:
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
Public Structure OsVersionInfo
Shared Sub New()
Size = Marshal.SizeOf(GetType(OsVersionInfo))
End Sub
Public Shared ReadOnly Size As Integer
Public MajorVersion As Integer
Public MinorVersion As Integer
Public BuildNumber As Integer
Public PlatformId As Integer
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=128)> Public Version As
String
End Structure
However the Size field remains 0 after:
verInfo = New OsVersionInfo()
What is wrong with this technique?
automatically set its size field?
I tried the following:
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
Public Structure OsVersionInfo
Shared Sub New()
Size = Marshal.SizeOf(GetType(OsVersionInfo))
End Sub
Public Shared ReadOnly Size As Integer
Public MajorVersion As Integer
Public MinorVersion As Integer
Public BuildNumber As Integer
Public PlatformId As Integer
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=128)> Public Version As
String
End Structure
However the Size field remains 0 after:
verInfo = New OsVersionInfo()
What is wrong with this technique?