OSVERSIONINFOEX Struct in VB.NET Urgent Help needed 
Author Message
 OSVERSIONINFOEX Struct in VB.NET Urgent Help needed

How is the struct I have to use in VB.NET that is sumilar to this one?

typedef struct _OSVERSIONINFOEX {
  DWORD dwOSVersionInfoSize;
  DWORD dwMajorVersion;
  DWORD dwMinorVersion;
  DWORD dwBuildNumber;
  DWORD dwPlatformId;
  TCHAR szCSDVersion[ 128 ];
  WORD wServicePackMajor;
  WORD wServicePackMinor;
  WORD wSuiteMask;
  BYTE wProductType;
  BYTE wReserved;

Quote:
} OSVERSIONINFOEX, *POSVERSIONINFOEX, *LPOSVERSIONINFOEX;

The problem is that I can't get a fixed size of 156 and I get a size of 32.
I'm using Integers as Dword, Short as word, byte as byte and String as tchar
(where the problem is as far as I can see)

Thanks.

~~~~~~~~~~~~~~~~~~~~~
Ing. Ariel Erlijman

www.espaciointeractivo.com
~~~~~~~~~~~~~~~~~~~~~



Sun, 25 Jul 2004 23:00:40 GMT  
 OSVERSIONINFOEX Struct in VB.NET Urgent Help needed
Hi Ariel,

it is not possible to declare a fix-length string (like szCSDVersion[128])
in .NET.

Andy



Quote:
> How is the struct I have to use in VB.NET that is sumilar to this one?

> typedef struct _OSVERSIONINFOEX {
>   DWORD dwOSVersionInfoSize;
>   DWORD dwMajorVersion;
>   DWORD dwMinorVersion;
>   DWORD dwBuildNumber;
>   DWORD dwPlatformId;
>   TCHAR szCSDVersion[ 128 ];
>   WORD wServicePackMajor;
>   WORD wServicePackMinor;
>   WORD wSuiteMask;
>   BYTE wProductType;
>   BYTE wReserved;
> } OSVERSIONINFOEX, *POSVERSIONINFOEX, *LPOSVERSIONINFOEX;

> The problem is that I can't get a fixed size of 156 and I get a size of
32.
> I'm using Integers as Dword, Short as word, byte as byte and String as
tchar
> (where the problem is as far as I can see)

> Thanks.

> ~~~~~~~~~~~~~~~~~~~~~
> Ing. Ariel Erlijman

> www.espaciointeractivo.com
> ~~~~~~~~~~~~~~~~~~~~~



Sun, 25 Jul 2004 23:44:16 GMT  
 OSVERSIONINFOEX Struct in VB.NET Urgent Help needed
But in C# it is possible with something like this:

  [StructLayout(LayoutKind.Sequential)]
   public struct OSVERSIONINFOEX
  {
   [MarshalAs(UnmanagedType.U4)]
   public int dwOSVersionInfoSize;
   [MarshalAs(UnmanagedType.U4)]
   public int dwMajorVersion;
   [MarshalAs(UnmanagedType.U4)]
   public int dwMinorVersion;
   [MarshalAs(UnmanagedType.U4)]
   public int dwBuildNumber;
   [MarshalAs(UnmanagedType.U4)]
   public int dwPlatformId;
   [MarshalAs(UnmanagedType.LPTStr, SizeConst=128)]
   public string szCSDVersion;
   [MarshalAs(UnmanagedType.U2)]
   public short wServicePackMajor;
   [MarshalAs(UnmanagedType.U2)]
   public short wServicePackMinor;
   [MarshalAs(UnmanagedType.U2)]
   public short wSuiteMask;
   public byte wProductType;
   public byte wReserved;
  }

  // Declaration for GetVersionEx.
  [DllImport("kernel32.dll")]
  public static extern bool GetVersionEx(
   [In, Out, MarshalAs(UnmanagedType.Struct)] ref OSVERSIONINFOEX
   lpVersionInfo);

Can I do this in VB.NET??
Thanks

Quote:
> Hi Ariel,

> it is not possible to declare a fix-length string (like szCSDVersion[128])
> in .NET.

> Andy



> > How is the struct I have to use in VB.NET that is sumilar to this one?

> > typedef struct _OSVERSIONINFOEX {
> >   DWORD dwOSVersionInfoSize;
> >   DWORD dwMajorVersion;
> >   DWORD dwMinorVersion;
> >   DWORD dwBuildNumber;
> >   DWORD dwPlatformId;
> >   TCHAR szCSDVersion[ 128 ];
> >   WORD wServicePackMajor;
> >   WORD wServicePackMinor;
> >   WORD wSuiteMask;
> >   BYTE wProductType;
> >   BYTE wReserved;
> > } OSVERSIONINFOEX, *POSVERSIONINFOEX, *LPOSVERSIONINFOEX;

> > The problem is that I can't get a fixed size of 156 and I get a size of
> 32.
> > I'm using Integers as Dword, Short as word, byte as byte and String as
> tchar
> > (where the problem is as far as I can see)

> > Thanks.

> > ~~~~~~~~~~~~~~~~~~~~~
> > Ing. Ariel Erlijman

> > www.espaciointeractivo.com
> > ~~~~~~~~~~~~~~~~~~~~~



Mon, 26 Jul 2004 00:04:23 GMT  
 OSVERSIONINFOEX Struct in VB.NET Urgent Help needed


Quote:
> But in C# it is possible with something like this:

>   [StructLayout(LayoutKind.Sequential)]
>    public struct OSVERSIONINFOEX
>   {
>    [MarshalAs(UnmanagedType.U4)]
>    public int dwOSVersionInfoSize;
>    [MarshalAs(UnmanagedType.U4)]
>    public int dwMajorVersion;
>    [MarshalAs(UnmanagedType.U4)]
>    public int dwMinorVersion;
>    [MarshalAs(UnmanagedType.U4)]
>    public int dwBuildNumber;
>    [MarshalAs(UnmanagedType.U4)]
>    public int dwPlatformId;
>    [MarshalAs(UnmanagedType.LPTStr, SizeConst=128)]
>    public string szCSDVersion;
>    [MarshalAs(UnmanagedType.U2)]
>    public short wServicePackMajor;
>    [MarshalAs(UnmanagedType.U2)]
>    public short wServicePackMinor;
>    [MarshalAs(UnmanagedType.U2)]
>    public short wSuiteMask;
>    public byte wProductType;
>    public byte wReserved;
>   }

>   // Declaration for GetVersionEx.
>   [DllImport("kernel32.dll")]
>   public static extern bool GetVersionEx(
>    [In, Out, MarshalAs(UnmanagedType.Struct)] ref OSVERSIONINFOEX
>    lpVersionInfo);

> Can I do this in VB.NET??

Yeah. Just use <> for attributes instead of [].

--
Dave Rothgery



Mon, 26 Jul 2004 00:12:40 GMT  
 OSVERSIONINFOEX Struct in VB.NET Urgent Help needed
I replaced the [] with <> but I can't get it compile. Are you sure that you
can make an equivalent structure, with the SizeConst=128 included??

Thanks
Ariel


Quote:



> > But in C# it is possible with something like this:

> >   [StructLayout(LayoutKind.Sequential)]
> >    public struct OSVERSIONINFOEX
> >   {
> >    [MarshalAs(UnmanagedType.U4)]
> >    public int dwOSVersionInfoSize;
> >    [MarshalAs(UnmanagedType.U4)]
> >    public int dwMajorVersion;
> >    [MarshalAs(UnmanagedType.U4)]
> >    public int dwMinorVersion;
> >    [MarshalAs(UnmanagedType.U4)]
> >    public int dwBuildNumber;
> >    [MarshalAs(UnmanagedType.U4)]
> >    public int dwPlatformId;
> >    [MarshalAs(UnmanagedType.LPTStr, SizeConst=128)]
> >    public string szCSDVersion;
> >    [MarshalAs(UnmanagedType.U2)]
> >    public short wServicePackMajor;
> >    [MarshalAs(UnmanagedType.U2)]
> >    public short wServicePackMinor;
> >    [MarshalAs(UnmanagedType.U2)]
> >    public short wSuiteMask;
> >    public byte wProductType;
> >    public byte wReserved;
> >   }

> >   // Declaration for GetVersionEx.
> >   [DllImport("kernel32.dll")]
> >   public static extern bool GetVersionEx(
> >    [In, Out, MarshalAs(UnmanagedType.Struct)] ref OSVERSIONINFOEX
> >    lpVersionInfo);

> > Can I do this in VB.NET??

> Yeah. Just use <> for attributes instead of [].

> --
> Dave Rothgery




Mon, 26 Jul 2004 00:31:45 GMT  
 OSVERSIONINFOEX Struct in VB.NET Urgent Help needed
The attributes might be slightly different (I really haven't done much with
this), but I'm fairly sure you can build an equivalent structure. Sorry I
can't help more.

--
Dave Rothgery


Quote:
> I replaced the [] with <> but I can't get it compile. Are you sure that
you
> can make an equivalent structure, with the SizeConst=128 included??

> Thanks
> Ariel





> > > But in C# it is possible with something like this:

> > >   [StructLayout(LayoutKind.Sequential)]
> > >    public struct OSVERSIONINFOEX
> > >   {
> > >    [MarshalAs(UnmanagedType.U4)]
> > >    public int dwOSVersionInfoSize;
> > >    [MarshalAs(UnmanagedType.U4)]
> > >    public int dwMajorVersion;
> > >    [MarshalAs(UnmanagedType.U4)]
> > >    public int dwMinorVersion;
> > >    [MarshalAs(UnmanagedType.U4)]
> > >    public int dwBuildNumber;
> > >    [MarshalAs(UnmanagedType.U4)]
> > >    public int dwPlatformId;
> > >    [MarshalAs(UnmanagedType.LPTStr, SizeConst=128)]
> > >    public string szCSDVersion;
> > >    [MarshalAs(UnmanagedType.U2)]
> > >    public short wServicePackMajor;
> > >    [MarshalAs(UnmanagedType.U2)]
> > >    public short wServicePackMinor;
> > >    [MarshalAs(UnmanagedType.U2)]
> > >    public short wSuiteMask;
> > >    public byte wProductType;
> > >    public byte wReserved;
> > >   }

> > >   // Declaration for GetVersionEx.
> > >   [DllImport("kernel32.dll")]
> > >   public static extern bool GetVersionEx(
> > >    [In, Out, MarshalAs(UnmanagedType.Struct)] ref OSVERSIONINFOEX
> > >    lpVersionInfo);

> > > Can I do this in VB.NET??

> > Yeah. Just use <> for attributes instead of [].

> > --
> > Dave Rothgery




Mon, 26 Jul 2004 01:14:35 GMT  
 OSVERSIONINFOEX Struct in VB.NET Urgent Help needed
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=128)> Public szCSDVersion as
string

HTH
Corrado



Mon, 26 Jul 2004 01:48:36 GMT  
 OSVERSIONINFOEX Struct in VB.NET Urgent Help needed
This finally worked great for me:

    <StructLayout(LayoutKind.Sequential)> _
     Public Structure OSVERSIONINFOEX1
        <MarshalAs(UnmanagedType.U4)> _
            Public dwOSVersionInfoSize As Integer
        <MarshalAs(UnmanagedType.U4)> _
        Public dwMajorVersion As Integer
        <MarshalAs(UnmanagedType.U4)> _
        Public dwMinorVersion As Integer
        <MarshalAs(UnmanagedType.U4)> _
        Public dwBuildNumber As Integer
        <MarshalAs(UnmanagedType.U4)> _
        Public dwPlatformId As Integer
        <MarshalAs(UnmanagedType.ByValArray, SizeConst : =128)> _
        Public szCSDVersion() As Char
        <MarshalAs(UnmanagedType.U2)> _
        Public wServicePackMajor As Short
        <MarshalAs(UnmanagedType.U2)> _
        Public wServicePackMinor As Short
        <MarshalAs(UnmanagedType.U2)> _
        Public wSuiteMask As Short
        Public wProductType As Byte
        Public wReserved As Byte
    End Structure

    <DllImport("kernel32.dll")> _
    Public Function GetVersionEx(<MarshalAs(UnmanagedType.Struct)> ByRef
lpVersionInfo As OSVERSIONINFOEX1) As Boolean '

    End Function

Thanks everybody.


Quote:
> <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=128)> Public szCSDVersion
as
> string

> HTH
> Corrado



Mon, 26 Jul 2004 01:58:47 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Need urgent help with browser control under VB.NET

2. Need urgent help with browser control under VB.NET

3. Installation vb.net failed - Urgent Help needed

4. Help with structs in .NET

5. Array of structs in VB.NET?

6. Need Struct help????

7. Help needed to read a Fortran binary file in VB or VB.NET

8. Howto use a Struct in drag and drop (struct to array-function)

9. Student new to vb needs urgent help!

10. Urgent! Need Help in Vb animation

11. urgent help needed: developing a drawing application in VB

12. URGENT HELP NEEDED: Flushing the WINI.INI Cache in VB 4.0 16 bit

 

 
Powered by phpBB® Forum Software