struct UIM_BOOK_STRUCT
{
int UimIndex;
char szName[15];
char szPhone[21];
};
int ReadUimAllBook(UIM_BOOK_STRUCT lpUimBookItem[],int nMaxArraySize);

 

   C#引用

 

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]//可以指定编码类型
public struct UIM_BOOK_STRUCT
{
public int UimIndex;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst= 15)]
public string szName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst= 21)]
public string szPhone;
};
[DllImport( "CdmaCard.dll",EntryPoint="ReadUimAllBook")]
public    static    extern   int ReadUimAllBook([Out] UIM_BOOK_STRUCT [] lpUimBookItem,int nMaxArraySize);
UIM_BOOK_STRUCT[] p = new UIM_BOOK_STRUCT[20];
int ret = ReadUimAllBook(p,p.Length);

  6. 注意问题
  类型不一致,会导致调用失败,
  (1) long 类型,在C++中是4字节的整数,在C#中是8字节的整数;
  (2) 字符串类型的设置不正确;
  以下是几个简单的window调用

 

[System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously
[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern bool ScreenToClient(IntPtr hWnd, ref System.Drawing.Point rect);
[System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously
[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern bool GetWindowRect(IntPtr hWnd, out System.Drawing.Rectangle rect);
[System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously
[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern bool UnregisterClass([MarshalAs(UnmanagedType.LPTStr)] string className, IntPtr instanceHandle);