VC는 dll을 자원에 통합합니다. (다른 파일도 마찬가지입니다.)

2608 단어 VC
g_MakeResourceFromExe      DLL SYS ID IDR_DLL1 WinIo32.dll
 ID IDR_SYS1 WinIo32.sys.ReleaseExe           ,  ,  
      :
bool CtestDlg::g_MakeResourceFromExe(CString szExPathName, CString szResName, int nResID)
{
	HRSRC hSrc = FindResource(NULL,MAKEINTRESOURCE(nResID),szResName);
	if(hSrc == NULL) return false;
	HGLOBAL hGlobal = LoadResource(NULL,hSrc);
	if(hGlobal == NULL) return false;
	LPVOID lp = LockResource(hGlobal);
	DWORD dwSize = SizeofResource(NULL,hSrc);
	CFile file;
	if(file.Open(szExPathName,CFile::modeCreate|CFile::modeWrite))
	{
		file.Write(lp,dwSize);
		file.Close();
	}
	FreeResource(hGlobal);
	return true;
}

void CtestDlg::ReleaseDLL()
{//   DLL    WinIo32.dll       ,ID=IDR_DLL1
	CString rc_dll = _T("WinIo32.dll");
	CString rc_sys = _T("WinIo32.sys");
	CFileFind find;
	if(!find.FindFile(rc_dll))
	{
		g_MakeResourceFromExe(rc_dll,_T("DLL"),IDR_DLL1);
		//  WinIo32.dll   :  ,  ,  
		DWORD dwAttributes = FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_READONLY;
		SetFileAttributes(rc_dll,dwAttributes);  
	}

	if(!find.FindFile(rc_sys))
	{
		g_MakeResourceFromExe(rc_sys,_T("SYS"),IDR_SYS1);
		//  WinIo32.dll   :  ,  ,  
		DWORD dwAttributes = FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_READONLY;
		SetFileAttributes(rc_sys,dwAttributes);  
	}
	find.Close();
}
        WinIo32.dll.    dll        .      :
typedef int (_stdcall *InitializeWinIoFun)();
InitializeWinIoFun InitializeWinIo = 0;

typedef int (_stdcall *GetPortValFun)(WORD wPortAddr, PDWORD pdwPortVal, BYTE bSize);
//typedef int (__cdecl *MYPROC)(short int* , short int* , short );  
GetPortValFun GetPortVal = 0;

typedef int (_stdcall *ShutdownWinIoFun)();
ShutdownWinIoFun ShutdownWinIo = 0;

HMODULE hDllInst = ::LoadLibrary(_T("WinIo32.dll"));

if (hDllInst)
	{
		InitializeWinIo = (InitializeWinIoFun)GetProcAddress(hDllInst, "InitializeWinIo");
		GetPortVal = (GetPortValFun)GetProcAddress(hDllInst, "GetPortVal");
		ShutdownWinIo = (ShutdownWinIoFun)GetProcAddress(hDllInst, "ShutdownWinIo");
	}
 
	int   bResult   =   InitializeWinIo(); 

좋은 웹페이지 즐겨찾기