I'm trying to call an function in an unmanaged c++ dll in .net cf 3.5 in a windows ce 6.0 environment.
The struct is defined as:
typedef struct TagOperatorInfo
{
DWORD dwMode;
DWORD dwFormat; //Operator name format
DWORD dwAct; //Network type(Available in 3G module£oGSM or 3G),
TCHAR szOper[32];
}OperatorInfo,*LPOperatorInfo;
and the function call is:
BOOL GetCurOperatorInfo(LPOperatorInfo pinfo);
I defined in .net the TagOperatorInfo as follows:
[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;
}
and after seeing some articles and msdn documentation i call the native function as:
[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);
Note: I call the function with an entry point defined with the ordinal because the c++ mangled names.
The problem that i have is that i always get the notSupportedException throw. I don't understand because the ref parameter should give it the Pointer to the struct.
My .net function that calls it is:
/// <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;
}
}
What i'm missing for this to work.
UPDATE
New .Net Compact Framework method call
[System.Runtime.InteropServices.DllImportAttribute(gsmaAdapterDLLName, EntryPoint = "?GetCurOperatorInfo@CGSMAdapter@@YAHPAUTagOperatorInfo@@@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);
See Question&Answers more detail:
os