//我写两个组件一个aa.dll,另一个bb.dll,其中aa.dll有一个接口Iaaa, bb.dll有一个接口Ibbb,接口Ibbb的一个方法Hello的一个参数为Iaaa *aaaa, 但是编译总是出错。
//第一个组件aa.dll
import "oaidl.idl";
import "ocidl.idl";
[
object,
uuid(731826A0-58DA-40E3-8B8A-1756D61CDDB5),
dual,
helpstring("Iaaa Interface"),
pointer_default(unique)
]
interface Iaaa : IDispatch
{
[id(1), helpstring("method Hello")] HRESULT Hello([out] BSTR * bstr);
};[
uuid(FC64D9A4-81EA-40B0-84D9-05443812DBA3),
version(1.0),
helpstring("aa 1.0 Type Library")
]
library AALib
{
importlib("stdole32.tlb");
importlib("stdole2.tlb"); [
uuid(93FC08FE-BA1C-44AF-A7C9-7E81CE8D28E2),
helpstring("aaa Class")
]
coclass aaa
{
[default] interface Iaaa;
};
};
//该组件生成aa.dll
//该接口方法返回一个字符串.
STDMETHODIMP Caaa::Hello(BSTR *bstr)
{
// TODO: Add your implementation code here
*bstr = _bstr_t("Hello aaa !");
return S_OK;
}
//第二个组件bb.dll
import "oaidl.idl";
import "ocidl.idl";
[
object,
uuid(16B6337A-501C-4EE4-AAEB-913BC5AB9524),
dual,
helpstring("Ibbb Interface"),
pointer_default(unique)
]
interface Ibbb : IDispatch
{
[id(1), helpstring("method Hello")] HRESULT Hello([in] Iaaa *aaa , [out] BSTR * bstr);//这行的输入参数Iaaa 出错。
};[
uuid(680357C2-1C0D-464D-8B98-CB7EAA6E32E1),
version(1.0),
helpstring("bb 1.0 Type Library")
]
library BBLib
{
importlib("stdole32.tlb");
importlib("stdole2.tlb"); [
uuid(218ACE7C-8358-4D65-BAB4-0FD11DE4081A),
helpstring("bbb Class")
]
coclass bbb
{
[default] interface Ibbb;
};
};
在第二个组件工作空间的StdAfx.h中加入
#import "D:\VC++\Test\aa\Debug\aa.dll" raw_interfaces_only, raw_native_types, no_namespace, named_guids当编译时提示:
D:\VC++\Test\bb\bb.idl(18) : error MIDL2025 : syntax error : expecting a type specification near "Iaaa"
D:\VC++\Test\bb\bb.idl(18) : error MIDL2026 : cannot recover from earlier syntax errors; aborting compilation 怎么办?