VC 방출 리소스 파일 DLL, EXE 등...

1355 단어 VCMFC
/**
@Name:    ReleaseResFile
@Brief	           
@Param:   WORD wResID			  ID
@Param:   LPCTSTR szResType		    
@Param:   LPCTSTR szFileName	        
@Return:    TRUE,  FALSE
*/
BOOL ReleaseResFile(WORD wResID, LPCTSTR szResType, LPCTSTR szFileName)
{ 
	if (szResType == NULL || szFileName == NULL)
	{
		return FALSE;
	}

	//      
	DWORD dwShareMode = FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE;
	HANDLE  hFile = CreateFile(szFileName, GENERIC_WRITE, dwShareMode, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); 
	if (hFile == INVALID_HANDLE_VALUE ) 
	{ 
		return FALSE; 
	} 

	HRSRC  hrsc = FindResource(NULL, MAKEINTRESOURCE(wResID), szResType);	//     
	HGLOBAL hG =  LoadResource(NULL, hrsc);			//     
	DWORD  dwSize = SizeofResource(NULL,  hrsc);	//       
	if(dwSize <= 0)
	{
		return FALSE;
	}

	//      
	DWORD   dwWrite = 0;    
	WriteFile(hFile, hG, dwSize, &dwWrite, NULL);
	CloseHandle(hFile); 

	return dwWrite > 0; 
} 

----------------------------------------------------------
//     DLL
	CHAR szProxyDLL[MAX_PATH] = {0};
	GetModuleFileName(NULL, szProxyDLL, sizeof(szProxyDLL));
	PathRemoveFileSpec(szProxyDLL);
	CString strProxyDLL(szProxyDLL);
	strProxyDLL += "\\ProxyDLL.dll";
	ReleaseResFile(IDR_PROXY_DLL, "DLL", strProxyDLL.GetBuffer());

좋은 웹페이지 즐겨찾기