how to pre-define a com interface in a idl file?
-
There are two interfaces IA and IB, but they reference each other in their method. The problem is, if i declared IA before IB, IA would get a error because IB was unknown to it; if i declared IB before IA, IB would get the same error. I know i can fix this problem by replacing the parameters from IAs and IBs to IUnkown. but i want to know if there is a resolution like C++'s classes pre-defining?
-
There are two interfaces IA and IB, but they reference each other in their method. The problem is, if i declared IA before IB, IA would get a error because IB was unknown to it; if i declared IB before IA, IB would get the same error. I know i can fix this problem by replacing the parameters from IAs and IBs to IUnkown. but i want to know if there is a resolution like C++'s classes pre-defining?
IDL has forward declaration of interface, just like C/C++ has forward declarations, viz:
// cccc.idl : IDL source for cccc
//// This file will be processed by the MIDL tool to
// produce the type library (cccc.tlb) and marshalling code.import "oaidl.idl";
import "ocidl.idl";[
uuid(D39DD965-FC96-4C0A-AA62-CA3F5F117685),
version(1.0),
helpstring("cccc 1.0 Type Library")
]
library ccccLib
{
interface ITest2;
[
object,
uuid(7CD26371-4A6B-4234-A024-6690A53CA450),
nonextensible,
helpstring("Itest Interface"),
pointer_default(unique)
]
interface Itest : IUnknown
{
HRESULT DoSomething([in] ITest2* c);
};
[
object,
uuid(72a5a7e2-0256-428f-8bb5-42d39096892d),
nonextensible,
helpstring("Itest Interface"),
pointer_default(unique)
]
interface ITest2 : IUnknown
{
HRESULT DoSomething([in]Itest* c);
};
importlib("stdole2.tlb");
[
uuid(F8AAE058-76E9-4F2C-995A-FB5B6565CED6),
helpstring("test Class")
]
coclass test
{
[default] interface Itest;
interface ITest2;
};
};Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p CodeProject MVP for 2010 - who'd'a thunk it!
-
IDL has forward declaration of interface, just like C/C++ has forward declarations, viz:
// cccc.idl : IDL source for cccc
//// This file will be processed by the MIDL tool to
// produce the type library (cccc.tlb) and marshalling code.import "oaidl.idl";
import "ocidl.idl";[
uuid(D39DD965-FC96-4C0A-AA62-CA3F5F117685),
version(1.0),
helpstring("cccc 1.0 Type Library")
]
library ccccLib
{
interface ITest2;
[
object,
uuid(7CD26371-4A6B-4234-A024-6690A53CA450),
nonextensible,
helpstring("Itest Interface"),
pointer_default(unique)
]
interface Itest : IUnknown
{
HRESULT DoSomething([in] ITest2* c);
};
[
object,
uuid(72a5a7e2-0256-428f-8bb5-42d39096892d),
nonextensible,
helpstring("Itest Interface"),
pointer_default(unique)
]
interface ITest2 : IUnknown
{
HRESULT DoSomething([in]Itest* c);
};
importlib("stdole2.tlb");
[
uuid(F8AAE058-76E9-4F2C-995A-FB5B6565CED6),
helpstring("test Class")
]
coclass test
{
[default] interface Itest;
interface ITest2;
};
};Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p CodeProject MVP for 2010 - who'd'a thunk it!
Thanks for your reply. I have tried this method but fail, because i always use the right idl files generated by atl project wizards, and i failed because i spelt 'Interface IB' other than 'interface IB'.(VS also highlights 'Interface' and 'interface'!). Regards.