How to share data between C# and C++ Dll

B

blackbiscuit

Dear All,

Currently, I am developing a C# application which will load some old C+
+ Dlls. Those Dlls used to work properly with C++ applications which
would export a global variable to cooperate with Dlls.

Now, the problem is how I can export a global variable from C# for
those old C++ Dlls.

Thanks for your kind suggestions.

Best Wishes,
Tony
 
S

Stanimir Stoyanov

Hi Tony,

Because of the managed nature of your C# application, the address of any
variable that is not pinned can change at any time the Garbage Collector is
executed. What kind of information do you want to share -- it is a reference
type, integral value or a structure?

If you are sharing a structure it would not suffer the 'managed'
complications if you allocated a chuck of memory, bound it to your C# struct
variable and called a function to your C++ DLL which stores its address in a
pointer. Then you could use it from the C++ library.
 

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