Help converting unmanaged C struct

Last post 07-02-2009 3:27 PM by ToddWolff. 0 replies.

Sort Posts:

  • Help converting unmanaged C struct

    07-02-2009, 3:27 PM
    • Member
      53 point Member
    • ToddWolff
    • Member since 10-24-2006, 1:41 PM
    • Posts 14

    I'm trying to convert an unmanaged C struct into VB.NET structure. No matter what I try I am getting the error...

    Cannot marshal 'parameter #1': Invalid managed/unmanaged type combination (this value type must be paired with Struct).

    Any help that you can provide is greatly appreciated.


    Here is the C struct...

    '/*****************************************************************************/
    '/* Parameter list for z4geterror() */
    '/* NOTE: Only fields containing +1 in the length are null terminated. */
    '/*****************************************************************************/
    'typedef struct tagError
    '{
    ' int iErrorCode; /* Error Code */
    ' char strErrorMessage[100+1]; /* Error Message */
    ' int iFileCode; /* File Code */
    ' char strFileName[26+1]; /* File Name */
    ' char strDiagnostics[300+1]; /* Diagnostic Message */
    '} Z4_ERROR;


    I have tried this but it doesn't work...

    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
    Public Structure Z4_ERROR
    Public iErrorCode As Int32
    <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=101)> Public strErrorMessage As String
    Public iFileCode As Int32
    <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=27)> Public strFileName As String
    <MarshalAs(UnmanagedType.ByValTStr, sizeconst:=301)> Public strDiagnostics As String
    End Structure


    I have also tried this...

    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
    Public Structure Z4_ERROR
    <MarshalAs(UnmanagedType.I4)> Public iErrorCode As Int32
    <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=101)> Public strErrorMessage As String
    <MarshalAs(UnmanagedType.I4)> Public iFileCode As Int32
    <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=27)> Public strFileName As String
    <MarshalAs(UnmanagedType.ByValTStr, sizeconst:=301)> Public strDiagnostics As String
    End Structure


Page 1 of 1 (1 items)