R
repekto.argosoft
Hi,
I'm working with Marshalling. I got an idea to pass an object to the
Native side as a byte array i.e. as void* in terms of C.
For example:
I have a .NET structure Point that contains two fields X and Y that
means that the byte array representation will look in the memory like
this: "XXXXYYYY" First four bytes are X and second for bytes are Y.
Then I marshall this array to the C-style function. I declare this
function in C# code this way:
[DllImport( "ImageProcessor.dll",
CharSet = CharSet.Auto,
EntryPoint = "Uninitialize" )]
private static extern int PassPoint_native(byte[] serializedPoint);
This function is declared on the native part this way:
int PassPoint_native(CPoint* point);
where CPoint class is following:
struct CPoint
{
int X;
int Y;
}
The byte array passed to the function PassPoint will be mapped to the
class CPoint and I get the object in terms of C/C++.
This is a simple example, but I think it can be used in more complex
cases.
Is it possible to represent the C# object as a raw byte array?
Kind regards,
Eugene.
I'm working with Marshalling. I got an idea to pass an object to the
Native side as a byte array i.e. as void* in terms of C.
For example:
I have a .NET structure Point that contains two fields X and Y that
means that the byte array representation will look in the memory like
this: "XXXXYYYY" First four bytes are X and second for bytes are Y.
Then I marshall this array to the C-style function. I declare this
function in C# code this way:
[DllImport( "ImageProcessor.dll",
CharSet = CharSet.Auto,
EntryPoint = "Uninitialize" )]
private static extern int PassPoint_native(byte[] serializedPoint);
This function is declared on the native part this way:
int PassPoint_native(CPoint* point);
where CPoint class is following:
struct CPoint
{
int X;
int Y;
}
The byte array passed to the function PassPoint will be mapped to the
class CPoint and I get the object in terms of C/C++.
This is a simple example, but I think it can be used in more complex
cases.
Is it possible to represent the C# object as a raw byte array?
Kind regards,
Eugene.