'System::String ^' to 'LPCWSTR'

前端 未结 4 2095
囚心锁ツ
囚心锁ツ 2020-12-17 19:45

I want to convert System::String ^ to LPCWSTR.

for

FindFirstFile(LPCWSTR,WIN32_FIND_DATA); 

Please help.

4条回答
  •  眼角桃花
    2020-12-17 20:41

    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:

     [DllImport("kernel32.dll", CharSet=CharSet.Auto)]
     static extern IntPtr FindFirstFile
         (string lpFileName, out WIN32_FIND_DATA lpFindFileData);
    

    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

提交回复
热议问题