0

I need to use BITS COM https://msdn.microsoft.com/en-us/library/windows/desktop/aa362708(v=vs.85).aspx in our .NET project. I cannot use 3rd party libraries which wrap BITS interface but frankly speaking there is not a big choice anyway. So, apparently I'm stuck with generating RCW (https://msdn.microsoft.com/en-us/library/5dxz80y2(v=vs.110).aspx) and the most conventional way of doing it is tlbimp.exe which did its work but with warnings. In the result I have one structure marked as ComConversionLoss

[ComConversionLoss]
[StructLayout(LayoutKind.Explicit, Size = 8, Pack = 4)]
public struct BG_AUTH_CREDENTIALS_UNION {
}

Most likely it happened because it is a union in C++ and tlbimp.exe did not know how to generate it right. The only suggestion for cases like that was to decompile generated DLL with ildasm.exe fix it and recompile again. I think technically I can do it but I would rather not if there is a better way I possibly don't know about. I, also, found tlbimp2.exe which didn't help in my case so I'm looking for a better alternative to tlbimp.exe which would be able to handle this case and ideally generate COM wrappers with IDisposable implementation for deterministic control of the COM objects lifetime but this is a separate question. First of all, I need that other tool to handle my case (C++ union types) properly. Does anybody know such a tool?

Alex
  • 655
  • 1
  • 8
  • 16

1 Answers1

0

As a general rule, .NET was developed to replace COM entirely. There is downward compatibility between .NET and COM. But the order of preference is clearly: .NET Code (MSIL) > COM > native code.

There is a somewhat commonly used 3rd party .NET BITS Library. You would be better off just using that as opposed to doing COM interop at all. https://stackoverflow.com/a/2299642/3346583 Sharp BITS is avalible open source, so I asume you can use it for your coding needs.

Community
  • 1
  • 1
Christopher
  • 9,634
  • 2
  • 17
  • 31
  • I understand your point and just to avoid switching the discussion into "why don't use wrappers" way I stated "I cannot use 3rd party libraries which wrap BITS interface". I saw Sharp BITS. It's just a wrapper around BITS COM but accordingly to our company policy I cannot use it. The question was where to find a better alternative to tlbimp.exe if there is one which would generate RCW for BITS COM correctly. – Alex Mar 23 '17 at 13:55
  • 1
    You could always Lobby to get that policy changed. As realities of Programming change, the Policies regarding it must adapt. Company Policies might actually be to static to be used here - something easier to change like design guidelines migth be better. For example my computerclub had the Monthly Fee in the Statue. Wich requires a notar to change for legal reasons. They made one change to statues saying "for the exact values see fee sheet". Now they can change the fee without any further notar being in the loop, as the fee sheet is much simpler. – Christopher Mar 30 '17 at 11:01