CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: marshal char[]

  1. #1
    Join Date
    Oct 2002
    Posts
    5

    marshal char[]

    I am trying to interface with a dll that uses this typedef.

    typedef struct{
    char szGroupKey[64]; // grouping key
    char szCoordSysKey[64]; // system key
    char szDatumKey[64]; // datum key
    char szUnitKey[64]; // unit key
    } COORDSYSTEM;


    I've tried
    [ MarshalAs( UnmanagedType.ByValTStr, SizeConst=64 )]
    [ MarshalAs( UnmanagedType.ByValArray, SizeConst=64 )]

    and god knows what else.

    I am going slighty insane;
    Any help would be GREATLY appreciated;

    Thanks

  2. #2
    Join Date
    Jul 2002
    Posts
    2,543
    Try CharSet = CharSet.Ansi in DllImport directive.
    Read also this article:
    http://msdn.microsoft.com/library/de...rp09192002.asp

  3. #3
    Join Date
    Oct 2002
    Posts
    5
    CharSet.Ansi gives me errors

    This isn't throwing errors, but it still isn't working right:

    [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto )]
    public struct COORDSYSTEM
    {
    [ MarshalAs( UnmanagedType.ByValTStr, SizeConst=64 )]
    public string szGroupKey; // grouping key
    [ MarshalAs( UnmanagedType.ByValTStr, SizeConst=64 )]
    public string szCoordSysKey; // system key
    [ MarshalAs( UnmanagedType.ByValTStr, SizeConst=64 )]
    public string szDatumKey; // datum key
    [ MarshalAs( UnmanagedType.ByValTStr, SizeConst=64 )]
    public string szUnitKey; // unit key
    }


    I've gotten it to work great in VB with this:

    Type COORDSYSTEM
    szGroupKey As String * 64
    szCoordSysKey As String * 64
    szDatumKey As String * 64
    szUnitKey As String * 64
    End Type

  4. #4
    Join Date
    Feb 2007
    Posts
    1

    Re: marshal char[]


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured