我試圖在windows ce 6.0環境中.net cf 3.5中的非託管C++ dll中調用一個函數。P /調用函數通過mangled名稱
的結構被定義爲:
typedef struct TagOperatorInfo
{
DWORD dwMode;
DWORD dwFormat; //Operator name format
DWORD dwAct; //Network type(Available in 3G module£ºGSM or 3G),
TCHAR szOper[32];
}OperatorInfo,*LPOperatorInfo;
和函數調用是:
BOOL GetCurOperatorInfo(LPOperatorInfo pinfo);
我在.NET的TagOperatorInfo定義如下:
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
public struct TagOperatorInfo
{
/// DWORD->unsigned int
public uint dwMode;
/// DWORD->unsigned int
public uint dwFormat;
/// DWORD->unsigned int
public uint dwAct;
/// TCHAR[32]
[System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst = 32)]
public string szOper;
}
,看到後一些文章和MSDN文檔我稱爲本地功能爲:
[System.Runtime.InteropServices.DllImportAttribute(gsmaAdapterDLLName, EntryPoint = "#30", CallingConvention = CallingConvention.Winapi)]
[return: System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)]
internal static extern bool GetCurOperatorInfo([MarshalAs(UnmanagedType.LPStruct)] ref NativeHelper.TagOperatorInfo operatorInfo);
注:我調用的函數的入口點使用序號定義,因爲C++的mangled名稱。
我的問題是我總是得到notSupportedException拋出。我不明白,因爲ref參數應該給它指向結構的指針。
調用它是我的.NET功能:
/// <summary>
/// Gets the current operator information.
/// </summary>
/// <param name="operatorInfo">The operator info.</param>
/// <returns></returns>
public static bool GetOperatorInformation(out NativeHelper.TagOperatorInfo operatorInfo)
{
operatorInfo = new NativeHelper.TagOperatorInfo();
if (NativeImports.GetCurOperatorInfo(ref operatorInfo) == true)
{
return true;
}
else
{
return false;
}
}
什麼我缺少這個工作。
UPDATE
新.NET Compact Framework受方法調用
[System.Runtime.InteropServices.DllImportAttribute(gsmaAdapterDLLName, EntryPoint = "[email protected]@@[email protected]@@Z", CallingConvention = CallingConvention.Winapi)]
[return: System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)]
internal static extern bool GetCurOperatorInfo([MarshalAs(UnmanagedType.LPStruct)]ref NativeHelper.TagOperatorInfo operatorInfo);
你確定你需要序號?試試它的名字。幾乎所有的C++ API都將使用`extern「C」`作爲未加密的名稱。 – 2011-01-26 12:35:45
查看評論下載 – Sorcerer86pt 2011-01-26 12:42:13