能力值:
( LV2,RANK:10 )
|
-
-
2 楼
loadResource. findResource
|
能力值:
( LV6,RANK:85 )
|
-
-
3 楼
直接给代码
HINSTANCE instance = AfxGetInstanceHandle();
//定位我们的自定义资源,这里因为我们是从本模块定位资源,所以将句柄简单地置为NULL即可
HRSRC hRsrc = FindResource(instance, MAKEINTRESOURCE(res_id), TEXT("Dll"));
if (NULL == hRsrc)
return FALSE;
//获取资源的大小
DWORD dwSize = SizeofResource(instance, hRsrc);
if (0 == dwSize)
return FALSE;
//加载资源
HGLOBAL hGlobal = LoadResource(instance, hRsrc);
if (NULL == hGlobal)
return FALSE;
//锁定资源
LPVOID pBuffer = LockResource(hGlobal);
if (NULL == pBuffer)
return FALSE;
FILE * f = fopen("写出文件的路径",wb");
if (f == NULL)
return FALSE;
fwrite(pBuffer,1,dwSize,f);
fclose(f);
|
能力值:
( LV2,RANK:10 )
|
-
-
4 楼
BOOL _ReleaseRes(LPCTSTR strFileName,WORD wResID,LPCTSTR strFileType)
{
// 查找资源文件中、加载资源到内存、得到资源大小
HRSRC hrsc = FindResource(NULL, MAKEINTRESOURCE(wResID), strFileType);
if (hrsc == NULL)
{
return FALSE;
}
HGLOBAL hG = LoadResource(NULL, hrsc);
if (hG == NULL){
return FALSE;
}
DWORD dwSize = SizeofResource(NULL, hrsc);
// 创建文件
HANDLE hFile = CreateFile( strFileName,
GENERIC_WRITE,
FILE_SHARE_WRITE,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
if ( hFile == INVALID_HANDLE_VALUE )
{
return FALSE;
}
// 写入文件
DWORD dwWrite = 0;
if(!WriteFile(hFile,hG,dwSize,&dwWrite,NULL))
{
CloseHandle(hFile);
return FALSE;
}
CloseHandle(hFile);
return TRUE;
}
|
|
|