views:

23

answers:

1

Hello,

From a managed c++ function I want to invoke an unmanaged function that expects a 'const char *' as an argument.

Are a) and b) below correct? For b), do I need to pin_ptr 'hello'? What about a)? Thanks.

a) myFunction( "hello" );

b)

char hello[10] ;
strcpy( hello, "hello" );
myFunction( hello );
A: 

Both are fine. You don't need an extra strcpy in b) though, just do:

char hello[] = "hello";
myFunction( hello );

which now becomes pretty much the same as a).

Nikolai N Fetissov
Thanks. And why there's no need to pin them? Because they are on the stack?
Martín
Because they are not dynamically allocated. a) is probably in read-only part of the data segment, b) is on the stack.
Nikolai N Fetissov