A while ago, I had a C# program that needed to call some functions in a C++ dll. I used pInvoke for that purpose. Some of the data I needed to pass in were structs. So, I would use the pInvoke Signature Toolkit to find out how to create a C# struct that was equivalent to the struct that the C++ function took by reference. Then, I was able to pass these structs to the C++ code.
Now, I have sort of the opposite situation. I am in C++ code, and I am being handed _com_ptr_t object. This is essentially a pointer to a C# object. The C# object implements a COM interface with properties like get_Foo, set_Foo, etc., that I can use to pull values (generally, they are just basic data types like float, bool, int, etc.) from the C# object and stuff them into my C++ counterpart.
This works well, but it's a little bit slow. When I profile my code, it spends a lot of time in "clr". So, I'm hoping to find a faster way, where I can perhaps add a function to the COM interface that will copy the entire C# object into the C++ counterpart struct at once -- sort of like how I did it with pInvoke above, except I'm pulling the data from C++ code through a COM interface, rather than passing data TO C++ code through a pInvoke interface.
Does anybody know of a way to do that?