Two weeks ago, the CLR InterOP team released a new version of tlbimp. I should have written a blog to introduce it, but I have been busy with the development of new CLR InterOP functions and it is difficult to spare time. Two minor functions are added in this version:
1./V2 Switch
In the new tlbimp version, we cannot change the behavior of the new version at will, to avoid program compilation errors or incorrect Behaviors Caused by compatibility issues when users adopt the new version. This switch is used to tell tlbimp to adopt the new version and ignore compatibility requirements. Currently, the/V2 switch has only one function (more will be added in the future): Convert variant_bool in struct/Union to bool, instead of short in the previous version, which makes it easier for users to use. In fact, many users require this change. The previous version of tlbimp converts variant_bool to short because the old version of InterOP externaler (should be. Net V1.0) does not support this conversion. After that, although marshaler supports this behavior, we have never had the opportunity to modify tlbimp. The release of tlbimp in codeplex gave us a great opportunity to modify tlbimp to support the functions we always wanted but didn't do, and we don't have to wait for the next version.
2./preservesig Switch
This feature is also required by many users. Once opened, all methods in the interface/class will be labeled with the preservesigattribute attribute, and the prototype of the function will be changed accordingly. At the same time, the returned hresult will not be converted to the corresponding one.. Net exception. In many cases, when calling COM, it is expected that the call fails and corresponding processing is performed, and the failure is very common. In this case, converting hresult to exception is completely unnecessary performance loss. If this switch is enabled, the CLR does not automatically convert the hresult into an exception. Instead, the user needs to check the returned hresult and use a method similar to the failed and succeeded macros. It is not convenient to throw an exception before use, but it provides more flexibility to avoid unnecessary performance overhead.
If you are interested, you can find the latest version here:
Http://www.codeplex.com/clrinterop/Release/ProjectReleases.aspx? Releaseid = 17579