How do I call Foo(long[][]) (C#) from Managed C++ (old syntax)? -


I have Foo (long [] [] existing C # code with long signatures) Which I need to call from unmanaged C ++ ( not C ++ / CLI) I __gc [] to please the compiler / Code> and __gc * are unable to understand the correct combination.

With C ++ / CLI, this is straight forward:

  std :: vector < __n int64 & gt; Evens; Evens.push_back (2); Evens.push_back (4); Evens.push_back (6); Evens.push_back (8); Std :: vector & lt; __n int64 & gt; Odds; Odds.push_back (1); Odds.push_back (3); Odds.push_back (5); Odds.push_back (7); Std :: vector & lt; Std :: vector & lt; __n int64 & gt; & Gt; Ints; Ints.push_back (makes the same); Ints.push_back (odds); Array & lt; Array & lt; __n int64 & gt; ^ & Gt; ^ MgdInts = gcnew array & lt; Array & lt; __n int64 & gt; ^ & Gt; (Ints.size ()); For (size_t i = 0; i  Edit:  As I am using Visual Studio 2008, the "simple" solution is to insert the C ++ / CLI code into my file and compile it  / CLR ; Of course, if I did not have to do this then it would be easy (for example, files with other  .h  managed C ++) C # code changed due to auto-generated from a web context Can not. Change the sign from 

this foo (long [] [] long): Foo (Array Lamb's)

Then when you see the resulting type library in Olive.XA, you should see:

  HRESULT Foo ([in] SAFEARRAY (int64) long);  

From C ++, it is quite straightforward to call you can make Win32 to just make a safe, or I suggest that use CComSafeArray wrapper class in ATL and Use after that.

Although there are rich array definitions in both C # and C ++, the difference between the two is usually done on the basis of what type Library Marshalar, 99% of which is heritage and "VB compatible". The only array type, which is the SAFEARRAY support of Type Library Marshalar, what do you do when you follow the normal way of doing all this.

However, COM supports a rich array of systems (Confident arrays), which understands C #, it is hard to do, and you just rotate your C # DLL and your unmanaged C ++ Can not use the resulting type libraries in the program. Some techniques need to tweaking the C # code with ILDASM, for others you need to keep two definitions of the interface, one in C ++ and another in C #, and make sure they are in sync (There is no way to convert one into another), then for the C ++, to adjust the parameter with the size_is in the IDL, and this is a mess with Marshall AS in C # and indeed the only type of people do this, if They have an already published legacy interface they can not change. If this is your C # code, and you can define the interface, then I will not go there. However, the technology is available. Here's a refine: expect one week or more to get it through if you have not done anything like this before.


Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -