CArray marshalling

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a legacy dll that has an important function that takes a
CArray<WORD,WORD>& as it's only parameter.

The dll is used by a number of internal applications and so can't be
changed. I am attempting to write a C# wrapper for this, so my team can begin
to port our applications to .Net.

I need to know how to pass a .net type by ref into this function to get the
array back.
 
Silly,

You can't expose this type. Rather, your wrapper would take a
IDictionary<short, short> and return IDictionary<short, short>. Then, your
wrapper would perform the conversion to/from CArray<WORD, WORD> to
IDictionary<short, short>.

If you are not using .NET 2.0, then you would expose a IDictionary
interface (or take it in), and use that.

Hope this helps.
 
Silly said:
I have a legacy dll that has an important function that takes a
CArray<WORD,WORD>& as it's only parameter.

The dll is used by a number of internal applications and so can't be
changed. I am attempting to write a C# wrapper for this, so my team can
begin
to port our applications to .Net.

I need to know how to pass a .net type by ref into this function to get
the
array back.

You can't do that. CArray cannot be exported anyway, it's (I guess) an MFC
template, and templates (such as ATL, STL MFC you name it) are not
exportable, they can only be used "as is" within the "realm" of a MFC
application.
Only option is to write a managed wrapper class using MC++ or C++/CLI
(vs2005) , and marshal the CArray to a managed array to be returned to C#.

Willy.
 
Thankyou both for your replies.

I have now been banging my head against this for a while and am not getting
anywhere. Any further expansion on this (maybe an example;) would be
gratefully received.

I have tried a number of methods, includeing the IDictionary and simply
returning an element of the CArray. I seem to get StackOverflowExceptions a
lot, but have no idea how to solve this. I know I am getting the correct
responses back from the function, but when my wrapper gets to return the
exception is thrown.

Any help will be gratefully received :-)
 
Silly said:
Thankyou both for your replies.

I have now been banging my head against this for a while and am not
getting
anywhere. Any further expansion on this (maybe an example;) would be
gratefully received.

I have tried a number of methods, includeing the IDictionary and simply
returning an element of the CArray. I seem to get StackOverflowExceptions
a
lot, but have no idea how to solve this. I know I am getting the correct
responses back from the function, but when my wrapper gets to return the
exception is thrown.

Any help will be gratefully received :-)

Please post your code.

Willy.
 
It's OK, I've somehow managed to solve the problem at the moment. I've
decided to start by getting the first element of the array, as will usually
only be one element, and then use another function to get the next elements.

The key came with creating a static CArray that I can then use in my
function. I then simply get the first element and the size and return these.
If there is more than 1 element the user can call a second function to get
the remainder one at a time.

All I've got to do now is sort out the other 10 functions that aren't
working properly :-S (but that will be for a differnet post!)

Thanks for your previous help.

Silly
 
Back
Top