I'm trying to retrieve a structure in C# from a C dll. Really to say I'm not an expert programmer on both C/C#, and will appreciate any comments and suggestions.
Here's a C dll coded structure, to be retrieved..
--
Expand|Select|Wrap|Line Numbers
- struct MESSAGEE
- {
- int MsgNo;
- int MsgType;
- char MsgTypeText[64];
- char MsgNoText[64];
- char MsgText[256];
- };
the function to be connected to (C coded)
--
Expand|Select|Wrap|Line Numbers
- MESSAGEE* Msg_Listing(
- int &nMsg,
- int Type
- )
My code in C# for the structure:
--
Expand|Select|Wrap|Line Numbers
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
- public struct MESSAGEE
- {
- Int32 MsgNo;
- Int32 MsgType;
- [MarshalAs(UnmanagedType.LPStr, SizeConst = 64)]
- string MsgTypeText;
- [MarshalAs(UnmanagedType.LPStr, SizeConst = 64)]
- string MsgNoText;
- [MarshalAs(UnmanagedType.LPStr, SizeConst = 256)]
- string MsgText;
- }
And a DLL function calling :
--
Expand|Select|Wrap|Line Numbers
- [DllImport("messagees.dll")] // Connection string
- [return: MarshalAs(UnmanagedType.LPStruct)]
- public static unsafe extern MESSAGEE Msg_Listing([Out]
- Int32 nRules, // # of defined rules
- Int32 Type // type of rule checking
- );
Thanks a lot in advance!!