我用atl模板生成一个com组件,然后在里面添加了个接口ICreateInstance,这时候编译没问题,但是在接口中添加虚函数Login(string IpOrHost, long port)时再编译就没的过了。
添加后的.idl文件如下:
import "oaidl.idl";
import "ocidl.idl";
[
object,
uuid(F4B43F43-E4AB-4008-97EB-1ABC2CCB6E25),
dual,
helpstring("ICreateInstance Interface"),
pointer_default(unique)
]
interface ICreateInstance : IDispatch
{
//添加的虚函数在这个地方 [id(1), helpstring("method Login")] HRESULT Login([in] string IpOrHost, [in] long port);
};[
uuid(64C1D8EB-86D3-4870-8364-1C85A9E975D3),
version(1.0),
helpstring("VNCClientATL 1.0 Type Library")
]
library VNCCLIENTATLLib
{
importlib("stdole32.tlb");
importlib("stdole2.tlb"); [
uuid(F44A3DD8-CCEA-47FB-B5A4-BF87843221A3),
helpstring("Client Class")
]
coclass Client
{
[default] interface ICreateInstance;
};
};
在添加之前编译没问题,添加之后就没的过了。编译器的提示如下:
error MIDL2025 : syntax error : expecting a type specification near "string"
在IDL中不是支持string 类型的嘛,怎么会报这个错啊,整个过程添加函数步骤我都时用模板添加的。另外,我还想问一下:本来我想添加函数void Login(string IpOrHost,int port)的,但是IDL中没有int,所以选则4字节的long。但是在com中编译器自动添加的函数也是Loing(string IpOrHost, long port)并不是我想要的int啊,如下:
STDMETHOD(Login)(/*[in]*/ string IpOrHost, /*[in]*/ long port);
这怎么办啊?
添加后的.idl文件如下:
import "oaidl.idl";
import "ocidl.idl";
[
object,
uuid(F4B43F43-E4AB-4008-97EB-1ABC2CCB6E25),
dual,
helpstring("ICreateInstance Interface"),
pointer_default(unique)
]
interface ICreateInstance : IDispatch
{
//添加的虚函数在这个地方 [id(1), helpstring("method Login")] HRESULT Login([in] string IpOrHost, [in] long port);
};[
uuid(64C1D8EB-86D3-4870-8364-1C85A9E975D3),
version(1.0),
helpstring("VNCClientATL 1.0 Type Library")
]
library VNCCLIENTATLLib
{
importlib("stdole32.tlb");
importlib("stdole2.tlb"); [
uuid(F44A3DD8-CCEA-47FB-B5A4-BF87843221A3),
helpstring("Client Class")
]
coclass Client
{
[default] interface ICreateInstance;
};
};
在添加之前编译没问题,添加之后就没的过了。编译器的提示如下:
error MIDL2025 : syntax error : expecting a type specification near "string"
在IDL中不是支持string 类型的嘛,怎么会报这个错啊,整个过程添加函数步骤我都时用模板添加的。另外,我还想问一下:本来我想添加函数void Login(string IpOrHost,int port)的,但是IDL中没有int,所以选则4字节的long。但是在com中编译器自动添加的函数也是Loing(string IpOrHost, long port)并不是我想要的int啊,如下:
STDMETHOD(Login)(/*[in]*/ string IpOrHost, /*[in]*/ long port);
这怎么办啊?
改为
STDMETHOD(Login)(/*[in]*/ BSTR IpOrHost, /*[in]*/ long port);string 是什么东西? IDL9.0还支持STL呢◎..◎
呵呵,IDL9.0还没出来呢
能不能帮看看上面的其它两个问题啊?
就是port你在idl中定义接口时用的long,表示的是四个字节的整型,在后面的组件中,编译器也添加的long,是使用实参时强制转换成int嘛?
还有一个就是上面的Windows下的WPARAM和LPARAM这两个数据类型在idl中用什么数据类型与其匹配啊?