问题
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