vc 加载外部资源,释放DLL
#include "stdafx.h"
#include "resource.h" #include <Windows.h> #include <stdio.h> int wmain(int argc,wchar_t* argv[]) { DWORD dwWrite=0; WORD wResID; HANDLE hFile = CreateFileA("test.dll",GENERIC_WRITE,FILE_SHARE_WRITE,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL); if (hFile == INVALID_HANDLE_VALUE) { printf("Getlasterror:%d.\r\n",GetLastError()); return 0; } HRSRC hrsc = FindResource(NULL,MAKEINTRESOURCE(IDR_TEST1),L"Test"); HGLOBAL hG = LoadResource(NULL, hrsc); DWORD dwSize = SizeofResource( NULL, hrsc); WriteFile(hFile,hG,dwSize,&dwWrite,NULL); CloseHandle( hFile ); return TRUE; }
新建立一个DLL,从资源读取,在这个之前,我们必须得在资源里把DLL引入进去。在运行程序的时候,将释放DLL。
记录引入资源头文件!!!!!!!