.NET C#: Is it possible to import TLB (semi-)automatically and add PreserveSig to one type?

会有一股神秘感。 提交于 2019-12-25 04:42:56

问题


I have this large IDL that I am importing into a C# project.

Everything was fine until I had to use one interface that is not quite compatible with HRESULT -> COMException conversion (I can go into details here but that shouldn't be relevant).

Is it possible to add PreserveSig to that one type somehow? I would like to avoid the option of declaring all COM interfaces manually in C#. If there was a way to get a c# source file instead of assembly from tlbimp, that would suit me, but AFAIK there is no such way.

Any other options? Thanks.


回答1:


You could decompile the interop library with Ildasm.exe, edit the declaration and put it back again with ilasm.exe. Use a sample C# declaration to know how to edit it.

Or you could just declare that one interface in C#. The name doesn't matter, only the GUID has to match. Open the interop library in Reflector and copy/paste the interface declaration into your C# code. Change the interface name and modify the method that causes the problem.



来源:https://stackoverflow.com/questions/3994848/net-c-is-it-possible-to-import-tlb-semi-automatically-and-add-preservesig-t

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!