2017-02-18 2 views
0

나는 C++ 응용 프로그램에서 작업 해왔고 SaveFileDialog에서 디렉토리 이름을 가져 오는 방법을 알아 냈습니다. 텍스트를 저장하여 동일한 파일에 저장하는 방법을 알아 냈습니다. 폴더를 만들지 만 새 FileWithPathName을 LPCTSTR로 변환하려고하면 코드가 할당되지 않습니다.C++ SaveFileDiolog 정보를 LPCTSTR로 변환하는 방법

나는이 사이트를 수색했기 때문에 내가 무엇을 찾고 있는지에 대한 명확한 예를 찾을 수 없다. 누군가가 나에게 이것을 명확한 링크로 인도 할 수 있거나 내가 뭘 잘못하고 있는지 말해 주면 좋을 것입니다. ;-)

  FileInfo^ fi = gcnew FileInfo(saveFileDialog1->FileName); 

      String^ fileNameWithPath = gcnew String(fi->DirectoryName) + "newName.txt"; 

      //LPCWSTR lfileNameWithPath = (LPCWSTR)(pfileNameWithPath[0]); // get temporary LPSTR // fails to get initialized 
      //LPCTSTR lfileNameWithPath = (LPCTSTR)(Marshal::StringToHGlobalAnsi(fileNameWithPath)).ToPointer(); // data returned like Chinese characters. epic fail 
+0

이것은 ++ ++/CLI가 아닌 C C입니다. 변경된 태그. –

+0

thx Mr. Butterworth 's. 나는 어느 것이 사용할 지 토론하고 있었다. –

+0

https://msdn.microsoft.com/en-us/library/bb384865.aspx –

답변

1

변환 방법에는 몇 가지가 있습니다. 당신은 사용할 수 있습니다

#include <msclr/marshal.h> 
using namespace msclr::interop; 
using namespace System; 

String^ fileNameWithPath = gcnew String(fi->DirectoryName) + "newName.txt"; 

marshal_context context; 
LPCTSTR lfileNameWithPath = context.marshal_as<LPCTSTR>(fileNameWithPath); 

here

+0

핵심 정보가 포함 항목 및 최고 사용 명세서에 있습니다. 이제 모든 것이 작동합니다. 중요한 항목을 보내 주셔서 감사합니다. –

관련 문제