How you use technique described here to work with C structures from .Net?
Ofcourse I need a code example – on 3 parts: C declaring parts, C++ wrapping around C and C# acsessing.
So what I wonder Is
C structture A has as one of its params structure B which consists of at least 2 types one of which is pointer to some variable C which should be declared.
We whant to have access from C# .Net to all A and B structures and its params and that variable C.
How to do such thing?
Suppose these are the C structs in a file named structs.h
In a new VC++ DLL project, enable Common Language RunTime Support (Old Syntax) and make sure C++ Exceptions are disabled. Build this for release target.
Then create a new C# Console Application and reference the .dll file we just built. In Project Properties > Build, check “Allow unsafe code”.
As you can see, the original StructA is in a way eliminated!! And I’m not aware of any other way to access C structure members directly from C# due to access issues.