Observe this most trivial IDL file:
import "unknwn.idl";
typedef struct _MyStruct
{
DWORD len;
[size_is(len)] BYTE *buffer;
} MyStruct;
[
object,
uuid(903C11E8-46A0-4E6E-B54C-6619B6A42CCB),
pointer_default(unique)
]
interface IMyIntf : IUnknown
{
[local]
HRESULT Func([in] MyStruct *pObj);
};
[
uuid(BAC6289C-503C-4ADD-B27A-4F22D726C109),
version(1.0),
]
library Lib
{
importlib("stdole2.tlb");
[
uuid(76D40083-C27F-45FB-88DC-C3E7DF9B5988)
]
coclass MyClass
{
[default] interface IMyIntf;
};
};
Here is how I compile it:
z:\Work>del 1.tlb
z:\Work>midl /W1 /nologo /char signed /env win32 /Oicf /tlb "1.tlb" /robust 1.idl
Processing .\1.idl
1.idl
Processing C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\unknwn.idl
unknwn.idl
Processing C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\wtypes.idl
wtypes.idl
Processing C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\basetsd.h
basetsd.h
Processing C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\guiddef.h
guiddef.h
Processing C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\oaidl.idl
oaidl.idl
Processing C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\objidl.idl
objidl.idl
Processing C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\oaidl.acf
oaidl.acf
z:\Work>tlbimp 1.tlb
Microsoft (R) .NET Framework Type Library to Assembly Converter 4.0.30319.1
Copyright (C) Microsoft Corporation. All rights reserved.
TlbImp : warning TI3016 : The type library importer could not convert the signature for the member 'Lib._MyStruct.buffer'.
TlbImp : Type library imported to Lib.dll
z:\Work>
Notice the TlbImp warning. The produced interop assembly is:
namespace Lib
{
[StructLayout(LayoutKind.Sequential, Pack=4), ComConversionLoss]
public struct _MyStruct
{
public uint len;
[ComConversionLoss]
public IntPtr buffer;
}
[ComImport, Guid("903C11E8-46A0-4E6E-B54C-6619B6A42CCB"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IMyIntf
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
void Func([In] ref _MyStruct pObj);
}
[ComImport, Guid("903C11E8-46A0-4E6E-B54C-6619B6A42CCB"), CoClass(typeof(MyClassClass))]
public interface MyClass : IMyIntf
{
}
[ComImport, TypeLibType(TypeLibTypeFlags.FCanCreate), ClassInterface(ClassInterfaceType.None), Guid("76D40083-C27F-45FB-88DC-C3E7DF9B5988")]
public class MyClassClass : IMyIntf, MyClass
{
// Methods
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
public virtual extern void Func([In] ref _MyStruct pObj);
}
}
The presence of the ComConversionLoss
attribute makes me feel bad, so
my question is how do I get rid of this warning?
P.S. My question may appear an exact duplicate of What causes "The type library importer could not convert the signature for the member" warnings?. However, it is not, because I compile on the command line and the warning does not disappear anywhere.