I've a function in C++ void someFunc(char* arg1, int* arg2)
which I want to marshal the parameters as I use this function in C# (after importing the DLL)..
Can you pls tell me how I should marshall as I'm confused here.
[DllImport(Dllname)]
extern void someFunc([MarshallAsAttribute(UnmanagedType,LPStr)] string arg1, IntPtr arg2);
Should I use an IntPtr here? I cant pass the address of any int variable from C# so that it would land up in the pointer in C++?
The problem is int*
can be used for a lot of different scenarios in C. How you marshal this depends a bit on what the int* arg2
is meant to represent.
For example, if it's just setting a value of an int, you can marshal this as ref int
. However, if the int*
is representing an array, you'll want to pass an array (this is unlikely, however, as there is no length term, which is common when using an array via a pointer).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With