using C++/CLI DLL in C#

R

Rudolf Meier

Hi

I try to build a C++/CLI DLL as a Wrapper for my C++ DLL... now, this works
more or less if I only have input-parameters... but I have a function like
this in native C++

void GetParams(BOOL* p_bool, int* p_int, wchar_t* p_str);

And those parameters are filled by this function (and yes, I know that the
buffer behind p_str has to be large enough to do this)... now, my problem
is, how can I write a C++/CLI Wrapper function for this and how do I call
this in C#??

I tryed to use BOOL^ and calling it by "ref myBOOL" and all those things,
but all I got were compiler errors... so, I hope someone can help me here...

thanks
MR - Rudolf Meier
 
W

William DePalo [MVP VC++]

I try to build a C++/CLI DLL as a Wrapper for my C++ DLL... now, this
works more or less if I only have input-parameters... but I have a
function like this in native C++

void GetParams(BOOL* p_bool, int* p_int, wchar_t* p_str);

And those parameters are filled by this function (and yes, I know that the
buffer behind p_str has to be large enough to do this)... now, my problem
is, how can I write a C++/CLI Wrapper function for this and how do I call
this in C#??

You have two choices.

1) Use Platform/Invoke to define GetParams() as public, static, external
function, use unsafe code blocks in the C# source, and set the assembly
properties to allow unsafe code. That's the awfully ugly approach.

2) Rename and redefine GetParams() in your C++/CLI to have a more natural
signature .Net - i.e. lose the pointers. Use C++ interop (aka "it just
works" aka IJW) or P/Invoke to call the "real" GetParams() from the C++/CLI
source.

Regards,
Will
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top