Connecting Tech Pros Worldwide Help | Site Map

MarshalDirectiveException - Method's type signature is not PInvoke compatible

  #1  
Old July 2nd, 2009, 01:44 PM
Newbie
 
Join Date: Jul 2009
Location: Italy
Posts: 1
Hello,
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
  1. struct MESSAGEE 
  2. {
  3.       int               MsgNo;          
  4.       int               MsgType;       
  5.       char        MsgTypeText[64];
  6.       char        MsgNoText[64];  
  7.       char        MsgText[256];    
  8. };
--
the function to be connected to (C coded)
--
Expand|Select|Wrap|Line Numbers
  1. MESSAGEE*  Msg_Listing(
  2.             int         &nMsg,    
  3.             int         Type        
  4. )
--
My code in C# for the structure:
--
Expand|Select|Wrap|Line Numbers
  1.  [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
  2.         public struct MESSAGEE 
  3.         {
  4.             Int32 MsgNo;
  5.             Int32 MsgType;
  6.             [MarshalAs(UnmanagedType.LPStr, SizeConst = 64)]
  7.             string MsgTypeText;
  8.             [MarshalAs(UnmanagedType.LPStr, SizeConst = 64)]
  9.             string MsgNoText;
  10.             [MarshalAs(UnmanagedType.LPStr, SizeConst = 256)]
  11.             string MsgText;
  12.         }
--
And a DLL function calling :
--
Expand|Select|Wrap|Line Numbers
  1.         [DllImport("messagees.dll")] // Connection string
  2.         [return: MarshalAs(UnmanagedType.LPStruct)]
  3.         public static unsafe extern MESSAGEE Msg_Listing([Out]
  4.             Int32 nRules,    // # of defined rules
  5.             Int32 Type    // type of rule checking
  6.             );
--

Thanks a lot in advance!!
Reply

Tags
marshaldirectiveexception, method's, pinvoke, signature, type