我遇到一个十分讨厌的DISP_FUNCTION_ID参数映射问题,希望高手能够指点迷津。
我在MFC的ActiveX工程中定义了一个结构体,并希望把这个结构体作为一个方法的参数暴露出去。
在MyInt.idl文件中这样定义:
[uuid(...), version(1.0), helpfile("MyInt.hlp"), control]
library MyIntLib
{
importlib(STDOLE_TLB);typedef [uuid(...)]
struct tagPerson{
int age;
}Person;
[uuid(...)]
dispinterface _DMyInt{
properties:
methods:
[id(1)] void Grows([in]Person* p);
};
[uuid(...)]
dispinterface _DMyIntEvents
{
properties:
methods:
};
[uuid(...), control]
coclass MyInt
{
[default] dispinterface _DMyIM;
[default, source] dispinterface _DMyIMEvents;
};
};编译idl文件后,好象得到了一个MyIntidl.h文件,在MyIntCtrl.h中定义了一个方法:
#include "MyIntidl.h"
class CMyIntCtrl : public COleControl
{
......
public:
enum {
dispidGrows = 1L,
};
protected:
void Grows(Person* p);
};在MyIntCtrl.cpp中定义为:...BEGIN_DISPATCH_MAP(CMyIMCtrl, COleControl)
DISP_FUNCTION_ID(CMyIMCtrl, "Grows", dispidGrows, Grows, VT_EMPTY, VTS_PVARIANT)
END_DISPATCH_MAP()...void CMyIntCtrl::Grows(Person *p)
{
if(p != NULL) p->age ++;
}这样可以成功编译出一个OCX,但是,当在VB中使用这个OCX时,会出数据类型错误:
VB中:
Dim p As Person
p.age = 10
MyInt1.Grows p ' <== 就在这里出了数据类型错误。我想应该是DISP_FUNCTION_ID中参数映射出了错误,可是我几乎尝试了各种参数映射,都是一样的错误。当然,我可以不需要这样暴露参数,但我面临的工程十分庞大,不这样暴露参数会使得接口难以维护。我当然相信使用COM技术能够以这种方式暴露参数。所以,在这里我需要你的帮助。
我在MFC的ActiveX工程中定义了一个结构体,并希望把这个结构体作为一个方法的参数暴露出去。
在MyInt.idl文件中这样定义:
[uuid(...), version(1.0), helpfile("MyInt.hlp"), control]
library MyIntLib
{
importlib(STDOLE_TLB);typedef [uuid(...)]
struct tagPerson{
int age;
}Person;
[uuid(...)]
dispinterface _DMyInt{
properties:
methods:
[id(1)] void Grows([in]Person* p);
};
[uuid(...)]
dispinterface _DMyIntEvents
{
properties:
methods:
};
[uuid(...), control]
coclass MyInt
{
[default] dispinterface _DMyIM;
[default, source] dispinterface _DMyIMEvents;
};
};编译idl文件后,好象得到了一个MyIntidl.h文件,在MyIntCtrl.h中定义了一个方法:
#include "MyIntidl.h"
class CMyIntCtrl : public COleControl
{
......
public:
enum {
dispidGrows = 1L,
};
protected:
void Grows(Person* p);
};在MyIntCtrl.cpp中定义为:...BEGIN_DISPATCH_MAP(CMyIMCtrl, COleControl)
DISP_FUNCTION_ID(CMyIMCtrl, "Grows", dispidGrows, Grows, VT_EMPTY, VTS_PVARIANT)
END_DISPATCH_MAP()...void CMyIntCtrl::Grows(Person *p)
{
if(p != NULL) p->age ++;
}这样可以成功编译出一个OCX,但是,当在VB中使用这个OCX时,会出数据类型错误:
VB中:
Dim p As Person
p.age = 10
MyInt1.Grows p ' <== 就在这里出了数据类型错误。我想应该是DISP_FUNCTION_ID中参数映射出了错误,可是我几乎尝试了各种参数映射,都是一样的错误。当然,我可以不需要这样暴露参数,但我面临的工程十分庞大,不这样暴露参数会使得接口难以维护。我当然相信使用COM技术能够以这种方式暴露参数。所以,在这里我需要你的帮助。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货