为了在atl(EXE SERVER类型)和客户端之前传递自定义数据
struct node{
BSTR description; /* optional element of type xsd:string */
BSTR id; /* optional element of type xsd:string */
BSTR name; /* optional element of type xsd:string */
struct {BSTR* tags;int numberOfTags;}
}
,我在MDIL中定义了自定义的数据结构.
typedef struct TAGS_DEF {
BSTR* item; //pointer to the memory where tags are stared.
int length; //number of tags
}TAGS;
typedef struct RESNODE {
BSTR description; /* optional element of type xsd:string */
BSTR id; /* optional element of type xsd:string */
BSTR name; /* optional element of type xsd:string */
TAGS tags;
}ResNode;
和响应添加的接口.
[id(6), helpstring("方法AddOrModifyRes")] HRESULT AddOrModifyRes([in] ResNode* res, [in] BSTR operat);
但是在exe server模式的ATL项目中,这个接口不能正确的被执行.就是说如果在客户端执行.
hr = spf.CoCreateInstance( CLSID_DataServer);
if( FAILED( hr )) throw( _T("服务器注删失败!"));
ResNode rn;
BSTR* tmpStr=NULL;
rn.tags.item=tmpStr;
rn.tags.length=0;
BSTR tmp=L"add";
spf->AddOrModifyRes(rn,tmp);
这样的语句的时候,AddOrModifyRes这个函数并未被正确的执行.很奇怪的是在ATL项目被定制成DLL的类型的时候,就不存在上述问题.我的MIDL的定义是
// monwebDataService.idl : monwebDataService 的 IDL 源
//// 此文件将由 MIDL 工具处理以
// 产生类型库(monwebDataService.tlb)和封送处理代码。import "oaidl.idl";
import "ocidl.idl";
typedef struct TAGS_DEF {
BSTR* item; //pointer to the memory where tags are stared.
int length; //number of tags
}TAGS;
typedef struct RESNODE {
BSTR description; /* optional element of type xsd:string */
BSTR id; /* optional element of type xsd:string */
BSTR name; /* optional element of type xsd:string */
TAGS tags;
}ResNode;
[
object,
uuid(EEC2233E-D1A7-435A-9CBD-48901778AEB7),
dual,
nonextensible,
helpstring("IDataServer 接口"),
pointer_default(unique)
]
interface IDataServer : IDispatch{
[id(1), helpstring("方法IsDataOK")] HRESULT IsDataOK([in,out] BYTE* sucFlag);
[id(2), helpstring("方法AddOrModifyRes")] HRESULT AddOrModifyRes([in] ResNode* res, [in] BSTR operat);
};
[
uuid(B79310B8-7A31-4598-897B-A9DD16EA3C33),
version(1.0),
helpstring("monwebDataService 1.0 类型库")
]
library monwebDataServiceLib
{
importlib("stdole2.tlb");
[
uuid(8256EA22-CA60-4914-B8EB-F215E01C91A7),
helpstring("DataServer Class")
]
coclass DataServer
{
[default] interface IDataServer;
};
};
struct node{
BSTR description; /* optional element of type xsd:string */
BSTR id; /* optional element of type xsd:string */
BSTR name; /* optional element of type xsd:string */
struct {BSTR* tags;int numberOfTags;}
}
,我在MDIL中定义了自定义的数据结构.
typedef struct TAGS_DEF {
BSTR* item; //pointer to the memory where tags are stared.
int length; //number of tags
}TAGS;
typedef struct RESNODE {
BSTR description; /* optional element of type xsd:string */
BSTR id; /* optional element of type xsd:string */
BSTR name; /* optional element of type xsd:string */
TAGS tags;
}ResNode;
和响应添加的接口.
[id(6), helpstring("方法AddOrModifyRes")] HRESULT AddOrModifyRes([in] ResNode* res, [in] BSTR operat);
但是在exe server模式的ATL项目中,这个接口不能正确的被执行.就是说如果在客户端执行.
hr = spf.CoCreateInstance( CLSID_DataServer);
if( FAILED( hr )) throw( _T("服务器注删失败!"));
ResNode rn;
BSTR* tmpStr=NULL;
rn.tags.item=tmpStr;
rn.tags.length=0;
BSTR tmp=L"add";
spf->AddOrModifyRes(rn,tmp);
这样的语句的时候,AddOrModifyRes这个函数并未被正确的执行.很奇怪的是在ATL项目被定制成DLL的类型的时候,就不存在上述问题.我的MIDL的定义是
// monwebDataService.idl : monwebDataService 的 IDL 源
//// 此文件将由 MIDL 工具处理以
// 产生类型库(monwebDataService.tlb)和封送处理代码。import "oaidl.idl";
import "ocidl.idl";
typedef struct TAGS_DEF {
BSTR* item; //pointer to the memory where tags are stared.
int length; //number of tags
}TAGS;
typedef struct RESNODE {
BSTR description; /* optional element of type xsd:string */
BSTR id; /* optional element of type xsd:string */
BSTR name; /* optional element of type xsd:string */
TAGS tags;
}ResNode;
[
object,
uuid(EEC2233E-D1A7-435A-9CBD-48901778AEB7),
dual,
nonextensible,
helpstring("IDataServer 接口"),
pointer_default(unique)
]
interface IDataServer : IDispatch{
[id(1), helpstring("方法IsDataOK")] HRESULT IsDataOK([in,out] BYTE* sucFlag);
[id(2), helpstring("方法AddOrModifyRes")] HRESULT AddOrModifyRes([in] ResNode* res, [in] BSTR operat);
};
[
uuid(B79310B8-7A31-4598-897B-A9DD16EA3C33),
version(1.0),
helpstring("monwebDataService 1.0 类型库")
]
library monwebDataServiceLib
{
importlib("stdole2.tlb");
[
uuid(8256EA22-CA60-4914-B8EB-F215E01C91A7),
helpstring("DataServer Class")
]
coclass DataServer
{
[default] interface IDataServer;
};
};
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货