api结构如下:
pDeliverResp是保存短消息的DeliverResp结构指针,DeliverResp定义如下:#pragma pack(push,_CTRL_BLOCK)
#pragma pack(1)
typedef struct
{
char SmsgID[11];
int NmsgFormat;
}DeliverResp;
#pragma pack(pop,_CTRL_BLOCK)
函数原型:DWORD SMGPDeliver(int nTimeout, DeliverResp * pDeliverResp)C#中我声明了第二个参数为ref,结构
struct strucDeliver
{
string SmsgID;int NmsgFormat;
}调用时返回:
struDeliver_resp deliver_resp=new struDeliver_resp();
i= SMGPDeliver( 5000,ref deliver_resp );
错误 :未能对象引用返回到对象实例。
麻烦帮解答,。
pDeliverResp是保存短消息的DeliverResp结构指针,DeliverResp定义如下:#pragma pack(push,_CTRL_BLOCK)
#pragma pack(1)
typedef struct
{
char SmsgID[11];
int NmsgFormat;
}DeliverResp;
#pragma pack(pop,_CTRL_BLOCK)
函数原型:DWORD SMGPDeliver(int nTimeout, DeliverResp * pDeliverResp)C#中我声明了第二个参数为ref,结构
struct strucDeliver
{
string SmsgID;int NmsgFormat;
}调用时返回:
struDeliver_resp deliver_resp=new struDeliver_resp();
i= SMGPDeliver( 5000,ref deliver_resp );
错误 :未能对象引用返回到对象实例。
麻烦帮解答,。
[DllImport("smgp.dll",CharSet=CharSet.Auto)]
static extern unsigned long SMGPDeliver(int nTimeout,ref DeliverResp delresp);
对于API中的struct中的数组,你需要指定其长度,在C#里可以这样指定
[ StructLayout( LayoutKind.Sequential )]
public struct DeliverResp
{
[ MarshalAs( UnmanagedType.ByValTStr, SizeConst=11)]
public string SmsgID;
public int NmsgFormat;
}