Search code examples
c#delphipinvoke

How do I write DllGetClassObject as a C# delegate?


There is a dll method exported written in delphi: DllGetClassObject: function(const CLSID, IID: TGUID; var Obj): HResult; stdcall;

I need to write equivalent method in c# as a delegate. How should it looks like?


Solution

  • Like this:

    [UnmanagedFunctionPointer(CallingConvention.StdCall)]
    public delegate uint DllGetClassObjectDelegate(
        [MarshalAs(UnmanagedType.LPStruct)]
        Guid rclsid,
        [MarshalAs(UnmanagedType.LPStruct)]
        Guid riid,
        [MarshalAs(UnmanagedType.IUnknown, IidParameterIndex=1)]
        out object ppv
    );
    

    Source: http://blog.kutulu.org/2012/01/com-interop-part-9-custom-activations.html?m=1