If a COM interface has a definition in C++:
interface Ixxx {
....
HRESULT fn([in]LPWSTR pszName, [in]REFIID riid, [out]void** ppv);
I am declaring it in my COMImport as
[ComImport, Guid(...)]
Interface Ixxx {
....
void fn(
[In, MarshalAs(UnmanagedType.LPWStr)] string pszName,
[In, MarshalAs(UnmanagedType.LPStruct)] Guid riid,
[Out, MarshalAs(UnmanagedType.Interface, IidParameterIndex = 1)] out IInterface ppv);
Then, when I try to call the function...
IInterface obj;
Ixxx x =
string name="name";
try {
x.fn(name, typeof(IInterface).GUID, out obj);
}
catch {
...I am getting a protected memory violation. There is something amiss with the way I am declaring the void** parameter, I am sure, although it all seems to work ok when calling an API function with the same sort of signature.
Any ideas on how the marshalling should be declared?
What I have tried:
setting ppv as an IntPtr
passing riid by ref
leaving off the IidParameterIndex parameter
and, of course, google.