C++ MFC VS2013 安裝D3DX9_39.dll

以前做過易語言的安裝D3DX9_39.dll,現在想用VS2013編寫一個。//功能:將D3DX9_39.dll移到系統目錄下


=====================================下面是VS2013

取運行目錄:GetModuleFileName

複製文件:CopyFile

結束:exit 

    or

[HANDLE hself = GetCurrentProcess(); 

TerminateProcess(hself, 0);]

文件是否存在:PathFileExists

//獲取主程序所在路徑,存在sPath中 
CString sPath;  
GetModuleFileName(NULL,sPath.GetBufferSetLength (MAX_PATH+1),MAX_PATH); 
 sPath.ReleaseBuffer ();  
int nPos; 
  nPos=sPath.ReverseFind ('\\'); 
 sPath=sPath.Left (nPos);  
 AfxMessageBox(sPath);

通過GetModuleFileName函數取運行目錄
參數1:hModule,可空;
參數2:lpFilename,存儲Filename的內存;
參數3:nSize,The size of the lpFilename buffer。

通過CopyFile函數複製文件
參數1:lpExistingFileName,源文件名;
參數2:lpNewFileName,目標文件名;
參數3:bFailIfExists,若目標文件存在,是否覆蓋?(無論覆蓋與否,系統都不會提示。)

CopyFile(_T("F:\\..\\D3DX9_39.dll"),_T( "C:\\D3DX9_39.dll"), FALSE);//我們是Unicode編程,所以要加_T

通過PathFileExists函數判斷文件是否存在

參數1:strDBPath,文件路徑。

#include <shlwapi.h>
#pragma comment(lib,"Shlwapi.lib") //如果沒有這行,會出現link錯誤
if (PathFileExists(strDBPath))
{
   //存在
}
else //不存在


//完整代碼

#include <shlwapi.h>
#pragma comment(lib,"Shlwapi.lib") //如果沒有這行,會出現link錯誤

	if (PathFileExists(_T("F:\\CE-000-000.1\\英雄聯盟\\橘子v1025_\\D3DX9_39.dll")))
	{
		//存在
		CopyFile(_T("F:\\CE-000-000.1\\英雄聯盟\\橘子v1025_\\D3DX9_39.dll"), _T("C:\\Windows\\System32\\D3DX9_39.dll"), FALSE);//我們是Unicode編程,所以要加_T

		HANDLE hself = GetCurrentProcess();

		TerminateProcess(hself, 0); 



	}
	else //不存在

		MessageBox(_T("文件不存在"));

附件安裝D3DX9_39.exe:http://download.csdn.net/detail/expenf/8258881

附件D3DX9_39.dll:http://download.csdn.net/detail/expenf/8258099

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章