ATL创建的Activex的接口 自定义类型该怎么传入和传出

ATL创建的Activex的接口 自定义类型该如何传入和传出
本帖最后由 zcdabing 于 2014-05-14 15:29:12 编辑
在IDL文件中中加入自定义类型的定义,在接口中使用这种类型,然后编译连接没问题,可是将这些自定义的类型传出,接口的另一端该接受?要在接口的另一端也定义这种类型嘛?或者传出个指针(char*),强制转换两次?



// ActiveXCard.idl : ActiveXCard 的 IDL 源
//
// 此文件将由 MIDL 工具处理以
// 产生类型库(ActiveXCard.tlb)和封送处理代码。

import "oaidl.idl";
import "ocidl.idl";
import "unknwn.idl";


/*帐户信息包*/
typedef struct 
{
char       Name[21]; 
char       SexNo[2]; 
char DeptCode[19];
unsigned int CardNo; 
unsigned int AccountNo; 
char StudentCode[21]; 
char IDCard[21]; 
char PID[3];
char IDNo[13]; 
int Balance; 
char Password[7];
char ExpireDate[7];
unsigned short SubSeq;
} AccountMsg;

interface IOnThird : IDispatch{

[id(5), helpstring("方法OnThirdreadcardsim")] HRESULT OnThirdreadcardsim([out,retval] AccountMsg* am);
}

// OnThird.cpp : COnThird 的实现

#include "stdafx.h"
#include "OnThird.h"

STDMETHODIMP COnThird::OnThirdreadcardsim(AccountMsg* am)
{
// TODO: 在此添加实现代码
P_TA_ReadCardSimple pTARCS = (P_TA_ReadCardSimple)GetProcAddress(hInst,"TA_ReadCardSimple");

AccountMsg amTemp;

memset( &amTemp , 0 , sizeof(amTemp));
nRet = pTARCS( &amTemp);

*am = amTemp;
return S_OK;
}




比如这个
AccountMsg* pAccMsg 该如何通过接口传递
------解决方案--------------------
我更加倾向于使用 IAccountMsg 来传递这个信息。
不要使用 UDT,而是使用接口。
在 IAccountMsg 使用属性,如 get_Name(BSTR *name);
------解决方案--------------------
最好也定义该类型