Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Easiest way to pass modifyable System.String as modifyable LPTSTR?

Tags:

c++

string

.net

BOOL PathFindOnPath( LPTSTR pszFile, LPCTSTR *ppszOtherDirs );

I am calling this API from managed C++. My pszFile is in a System.String.

What is the easiest way to pass this as LPTSTR? (Considering its an inout parameter)

I have tried pin_ptr and interior_ptr but neither seems to be accepted by the compiler.

like image 862
BillyG Avatar asked May 14 '26 16:05

BillyG


1 Answers

You need to marshal across a (pre-allocated) StringBuilder instead of a String reference. For details, see this MSDN article on Marshaling.

like image 87
Reed Copsey Avatar answered May 16 '26 06:05

Reed Copsey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!