0

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;
    }
}
YOUKU
  • 13
  • 4
  • 1
    Your interface is not automation compatible. Do not attempt to place it into a type library - its format is physically incapable of adequately describe such interface. No automation client - a kind of client that could benefit from a type library - would be able to call this interface anyway. – Igor Tandetnik Dec 28 '14 at 03:24
  • COM's equivalent of a function pointer is an interface with a single method. – Hans Passant Dec 30 '14 at 08:41
  • @HansPassant But a local interface accepts function pointers – YOUKU Dec 30 '14 at 09:56

0 Answers0