3

この最も単純な IDL ファイルを観察します。

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;
    };
};

コンパイル方法は次のとおりです。

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>

TlbImp 警告に注意してください。作成された相互運用アセンブリは次のとおりです。

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);
    }
}

属性が存在ComConversionLossすると気分が悪くなります。私の質問は、この警告を取り除くにはどうすればよいですか?

PS 私の質問は、「タイプライブラリインポーターがメンバーの署名を変換できませんでした」という警告の原因は何ですか? . ただし、コマンドラインでコンパイルしても警告がどこにも消えないため、そうではありません。

4

0 に答える 0