开发者

Do I need a pin_ptr to pass a literal string?

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开发者_Python百科( hello, "hello" );
myFunction( hello );


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜