'System::String ^' to 'LPCWSTR'

前端 未结 4 2106
囚心锁ツ
囚心锁ツ 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:38

    I have found that

    String^ str = "C:\\my.dll";
    
    ::LoadLibraryEx(LPCWSTR)Marshal::StringToHGlobalAnsi(str).ToPointer(), 0, flags); 
    

    does not work, returning code 87. Instead,

    #include 
    
    CString s("C:\\my.dll");
    ::LoadLibraryEx((LPCWSTR)s, 0, flags);
    

    has been working like a charm and seems to be the least verbose method.

提交回复
热议问题