Function pointer typedef only allowed once in MIDL?

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;
    }
}
c++
visual-c++
com
atl
midl
asked on Stack Overflow Dec 27, 2014 by YOUKU • edited Dec 30, 2014 by YOUKU

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0