VC++读取资源中文件

时间:2022-08-05 22:28:37
//查找目标资源
HRSRC hResource = FindResource(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR_MAINPROG), TEXT("exe"));
if(hResource)
{
     //加载资源
     HGLOBAL hg = LoadResource(GetModuleHandle(NULL), hResource); 
     if(hg) 
     {
         //锁定资源
         LPVOID pData = LockResource(hg);
         if(pData)
         {
              //获取资源大小
              DWORD dwSize = SizeofResource(GetModuleHandle(NULL), hResource);
              CFile rFile;
              if(rFile.Open("C:\\ZTXClient.exe", CFile::modeCreate | CFile::modeReadWrite))
              {
                   rFile.WriteHuge(pData, dwSize);
                   rFile.Close();
              }
         }
     }
}