从一个程序中生成另一个程序(资源法)
岁数大了,QQ也不闪了,微信也不响了,电话也不来了,但是图老师依旧坚持为大家推荐最精彩的内容,下面为大家精心准备的从一个程序中生成另一个程序(资源法),希望大家看完后能赶快学习起来。
下面是源代码
//资源文件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_WR99vE,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文件.