리소스 실행시에 파일로 내보내기 Posted by 빵빵빵 2009/06/11 17:04 전산(컴퓨터)/PC-Windows 전산(컴퓨터)/PC-Windows #include <io.h> #include <stdlib.h> HMODULE hModule = GetModuleHandle(NULL); TCHAR szFilename[MAX_PATH]; TCHAR Drive[_MAX_DRIVE]; TCHAR Path[_MAX_DIR]; TCHAR Filename[_MAX_FNAME]; TCHAR Ext[_MAX_EXT]; GetModuleFileName(NULL, szFilename, sizeof(szFilename)); _tsplitpath_s(szFilename, Drive, _MAX_DRIVE, Path, _MAX_DIR, Filename, _MAX_FNAME, Ext, _MAX_EXT); TCHAR szFile[MAX_PATH]; // Extract "file.fnt" _stprintf_s(szFile, MAX_PATH, _T("%s%sfile.fnt"), Drive, Path); if( (_waccess( szFile, 0 )) == -1 ) // 파일이 존재하지 않을 경우 { HRSRC hrsrc = FindResource(hModule, (LPCTSTR)IDR_MY_FONT, _T("MyFILE")); DWORD dwSize = SizeofResource(hModule, hrsrc); HGLOBAL hGlobal = LoadResource(hModule, hrsrc); CHAR *pData = (CHAR *) LockResource(hGlobal); CFile file; CFileException e; if (file.Open(szFile, CFile::modeCreate | CFile::modeWrite | CFile::typeBinary, &e)) { file.Write(pData, dwSize); file.Close(); } else { TCHAR szErr[1024]; e.GetErrorMessage(szErr, 1024); AfxMessageBox(szErr); } DeleteObject(hGlobal); } // Extract "file.dat" _stprintf_s(szFile, MAX_PATH, _T("%s%sfile.dat"), Drive, Path); if( (_waccess( szFile, 0 )) == -1 ) // 파일이 존재하지 않을 경우 { HRSRC hrsrc = FindResource(hModule, (LPCTSTR)IDR_MY_DATA, _T("MyFILE")); DWORD dwSize = SizeofResource(hModule, hrsrc); HGLOBAL hGlobal = LoadResource(hModule, hrsrc); CHAR *pData = (CHAR *) LockResource(hGlobal); CFile file; CFileException e; if (file.Open(szFile, CFile::modeCreate | CFile::modeWrite | CFile::typeBinary, &e)) { file.Write(pData, dwSize); file.Close(); } else { TCHAR szErr[1024]; e.GetErrorMessage(szErr, 1024); AfxMessageBox(szErr); } DeleteObject(hGlobal); } 2009/06/11 17:04 2009/06/11 17:04 Tags 리소스 저장 Trackback: 0 Comment: 0 이 글에는 트랙백을 보낼 수 없습니다