To convert a System::String ot LPCWSTR in C++/CLI you can you use the Marshal::StringToHGlobalAnsi function to convert managed strings to unmanaged strings.
and CLR will do managed to native type marshaling automatically.
[Edit] I just realized you're using C++/CLI. In that case, you can also use implicit P/Invoke, which is a feature which only C++ supports (opposed to C# and VB.NET). This articles shows several examples:
To convert a System::String ot LPCWSTR in C++/CLI you can you use the Marshal::StringToHGlobalAnsi function to convert managed strings to unmanaged strings.
I have found that
does not work, returning code 87. Instead,
has been working like a charm and seems to be the least verbose method.
You need to use P/Invoke. Check this link: http://www.pinvoke.net/default.aspx/kernel32/FindFirstFile.html
Simply add the
DllImport
native function signature:and CLR will do managed to native type marshaling automatically.
[Edit] I just realized you're using C++/CLI. In that case, you can also use implicit P/Invoke, which is a feature which only C++ supports (opposed to C# and VB.NET). This articles shows several examples:
How to: Convert Between Various String Types in C++/CLI
The easiest way to do this in C++/CLI is to use
pin_ptr
: