以前做過易語言的安裝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);
參數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:h附ttp://d附ownload.csdn附.net/detail/e附xpenf/8258881
附件D3DX9_39.dll:htt附p://dow附nload.csdn.net/de附tail/expenf/8258附099