-1

I currently have a C# method in an interface that has the following parameters when viewed in ITypeLib

HRESULT _stdcall SomeMethod ([in] Is_interface* inst, 
           [in] SAFEARRAY(long) bid);

The above method is in an interface and is defined in C#.After generating a type library I am attempting to create an implementation of that interface in C++. However I cannot figure out the type required for

[in] SAFEARRAY(long) bid

I am currently trying something like this

virtual HRESULT STDMETHODCALLTYPE SomeMethod (Is_interface* inst, CComSafeArray<long> bid);

Any suggestions on what the equivalent of [in] SAFEARRAY(long) bid should be for the class implementing the C# interface.

4

1 回答 1

3

SAFEARRAY is the default interop type for an array. Just a plain int[] will do. For example:

[InterfaceType(ComInterfaceType.InterfaceIsDual)]
[ComVisible(true)]
public interface IFoo {
    void Method(object inst, int[] array);
}

Produces this type library entry, obtained with OleView.exe, File + View TypeLib command:

[
  odl,
  uuid(2380B019-1E69-386E-BB6E-ECEF45257086),
  version(1.0),
  dual,
  oleautomation,
  custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, "ClassLibrary1.IFoo")    

]
interface IFoo : IDispatch {
    [id(0x60020000)]
    HRESULT Method(
                    [in] VARIANT inst, 
                    [in] SAFEARRAY(long) array);
};
于 2013-03-18T22:07:35.937 回答