Background:
I have written the following function in C++:
extern "C" __declspec(dllexport) int test(const char*, ...);
And I am using P/Invoke to call it from C#:
[DllImport("foo/bar.dll", EntryPoint = "test")]
public static unsafe extern int __unmanaged__test(byte* buffer, __arglist);
Problem:
I need to initialize the
__arglist
dynamically, meaning that I have an Array<object>
, which I have to convert into the __arglist
before calling the C++-function.
I have tried the following, but it returns an compiler error:
unsafe {
byte[] buffer = ....
object[] args = ....
// ....
fixed (byte* ptr = buffer)
return __unmanaged__test(ptr, __arglist(args)); // <--ERROR
}
Does anyone know a way to solve this problem?
for those who do not know what
__arlist
is: http://bartdesmet.net/blogs/bart/archive/2006/09/28/4473.aspx