当前位置:天才代写 > tutorial > C语言/C++ 教程 > 奈何通过一个措施来生成另一个措施

奈何通过一个措施来生成另一个措施

2017-11-06 08:00 星期一 所属: C语言/C++ 教程 浏览:579

前不久各人都在接头奈何通过一个措施来生成另一个措施,我提出了将另一个措施当资源文件包括在措施中一起编译,然后在措施运行时按照需要再从头生成出来,下面是我的一个例子, 在这里,我将windows自带的写字板(writer.exe)当资源.

下面是源代码

//资源文件writer.exe长度为204800,在资源文件中界说为"CUSTOM"资源,编号为1111
  HRSRC  hMyRes;   //resource handle
  HGLOBAL  hgpt;    //resource pointer
  LPVOID  lpBuff;   //resource buffer pointer
  DWORD   rcSize=204800;  //resource size
  HANDLE  hFile;//file to write
  LPDWORD dwByte;//byte size had been write
  dwByte=&rcSize; //locate the resource and load the resource to memory and lock it
  hMyRes=FindResource((HMODULE)GetWindowLong(Handle,GWL_HINSTANCE),MAKEINTRE SOURCE(1111),"CUSTOM");
  if(hMyRes==NULL)
   ShowMessage(SysErrorMessage(GetLastError()));
  hgpt=LoadResource(NULL,hMyRes);
  if(hgpt==NULL)
   ShowMessage(SysErrorMessage(GetLastError()));
  lpBuff=LockResource(hgpt);
//now i will read the resource and write it to an file
  try
   {
   hFile=CreateFile("e:\\mywriter.exe",GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
   WriteFile(hFile,lpBuff,rcSize,dwByte,NULL);
   if(*dwByte!=204800)
    ShowMessage("Failed to write to file");
   }
   __finally
   {
   CloseHandle(hFile);
   }

在资源的添加与生成时,我用Borland ResourceWorkShop4.5没步伐做,最后是用vb6带的资源编辑器生成的res文件.

 

    关键字:

天才代写-代写联系方式