Here is a simple test. The function pointer type FN_t appears twice in ITest::Test & ITest::Test2.
import "oaidl.idl";
import "ocidl.idl";
typedef void(* FN_t)();
[
uuid(f5d5eb17-45c7-4cce-a176-9ed2e1083d2a),
object,
local,
pointer_default(unique)
]
interface ITest : IUnknown {
HRESULT Test(FN_t pfn);
HRESULT Test2(FN_t pfn); // !error!
}
[
uuid(04f887d2-7412-497a-8189-72e710484bfa)
]
library TestLib {
importlib("stdole2.tlb");
[
uuid(072f49e3-b94c-4d94-a368-ee72db579600)
]
coclass Test {
[default] interface ITest;
}
}
The error message: midl\oleaut32.dll : error MIDL2020 : error generating type library : SetFuncAndParamNames failed : __MIDL____MIDL_itf_test_0000_00000000 (0x8002802C)
By commenting the !error! line, MIDL works well. So why and how to make the code work?
==================================================================================
I think I may answer myself.
For single ITest::Test method. The interface in generated typelib is:
interface ITest : IUnknown {
void _stdcall __MIDL____MIDL_itf_test_0000_00000000();
HRESULT _stdcall Test(ITest* pfn);
};
It seems that the typelib don't know what function pointer types are.
Then I add a wire_marshal attribute and it works:
import "oaidl.idl";
import "ocidl.idl";
typedef [unique] void *wirePointer;
typedef [wire_marshal(wirePointer)] void(__stdcall *FN_t)();
[
uuid(f5d5eb17-45c7-4cce-a176-9ed2e1083d2a),
object,
local,
pointer_default(unique)
]
interface ITest : IUnknown {
HRESULT Test(FN_t pfn);
HRESULT Test2(FN_t pfn); // ok!!!
}
[
uuid(04f887d2-7412-497a-8189-72e710484bfa)
]
library TestLib {
importlib("stdole2.tlb");
[
uuid(072f49e3-b94c-4d94-a368-ee72db579600)
]
coclass Test {
[default] interface ITest;
}
}
User contributions licensed under CC BY-SA 3.0