Udostępnij za pośrednictwem


CFile::SetFilePath

Wywołanie tej funkcji do określenia ścieżki pliku. na przykład, jeśli ścieżka pliku nie jest dostępny podczas CFile obiektu, wywołanie SetFilePath do dostarczenia.

virtual void SetFilePath(
   LPCTSTR lpszNewName 
);

Parametry

  • lpszNewName
    Ciąg określający ścieżkę nowy wskaźnik.

Uwagi

[!UWAGA]

SetFilePathOtwórz plik lub nie utworzyć plik; po prostu kojarzy CFile obiekt z nazwą ścieżki może być używany.

Przykład

TCHAR* pstrName = _T("C:\\test\\SetPath_File.dat");

// open a file
HANDLE hFile = ::CreateFile(pstrName, GENERIC_WRITE, FILE_SHARE_READ,
   NULL, CREATE_ALWAYS, 0, NULL);

if (hFile != INVALID_HANDLE_VALUE)
{
   // attach a CFile object to it
   CFile myFile(hFile);

   // At this point, myFile doesn't know the path name for the file
   // it owns because Windows doesn't associate that information
   // with the handle. Any CFileExceptions thrown by this object
   // won't have complete information.

   // Calling SetFilePath() remedies that problem by letting CFile
   // know the name of the file that's associated with the object.

   myFile.SetFilePath(pstrName);

   // write something to the file and flush it immediately
   DWORD dwValue = 1234;
   myFile.Write(&dwValue, sizeof(dwValue));
   myFile.Flush();

   // destroying the CObject here will call ::CloseHandle() on the file
} 

Wymagania

Nagłówek: afx.h

Zobacz też

Informacje

Klasa CFile

Wykres hierarchii

CFile::GetFilePath

CFile::CFile