【发布时间】:2011-01-03 09:01:22
【问题描述】:
我使用的是 Windows 7,我必须在该窗口中运行一个程序,但该程序在 Windows XP 中运行。这是一个 Visual C++ 程序,我为此使用 Visual Studio 2008。当我运行我的应用程序时,它不会抛出任何错误,但它不会在“c:\program files\”中创建目录。那么谁能帮我创建目录和exe文件?
这是我正在使用的代码:
char szAppPath[MAX_PATH];
char szFileName[MAX_PATH];
DWORD dwResult;
WIN32_FIND_DATA FindFileData;
HANDLE hFind;
dwResult = ExpandEnvironmentStrings( NULL, szAppPath, MAX_PATH); // "%ProgramFiles%"
// do same for NSim directory
strcat(szAppPath,"\\NSim");
hFind = FindFirstFile(szAppPath, &FindFileData);
if (hFind == INVALID_HANDLE_VALUE)
{
//Directory Does't Exists create New
if(!CreateDirectory(szAppPath,NULL)) //Throw Error
{
MessageBox("Unable to Create N-SIM directory","NSim Installer");
return ;
}
}
else
{
//check if is directory or not
if(!(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
MessageBox("Can't Create N-SIM directory\n Another file with same name exists","NSim Installer");
return ;
}
FindClose(hFind);
}
//***************************************N-SIM Application****************************
strcpy(szFileName, szAppPath);
HRSRC hRes;
if( bRegister == FALSE)
{
strcat(szFileName,"\\NSim.exe"); //make same name of the Client & Server in program file
hRes = FindResource(NULL, MAKEINTRESOURCE(IDR_LANSIMSERVER),RT_RCDATA);
if(flagUpgrade ==0)
{
CString trial = installationDate(); //----- Detemine Expiry Date -----
setRegistry(trial);
}
}
【问题讨论】:
-
字符串转义很差。而不是
C:\NSim写C:\\NSim。 -
显然在重新格式化时,İsmail 'cartman' Dönmez “修复”了字符串转义问题...
-
我已经在我的程序中使用了它,但它仍然没有创建文件夹。请提供另一种解决方案
-
@goreSplatter:字符串在原始源代码中已正确转义,但由于文本未格式化为源代码,因此未显示。 Ismail 修复的只是代码格式——我检查了,因为我同意你的观点,这样的东西不应该被“编辑”。
-
@Cody 感谢您指出这一点。由于我还差一点rep,所以我看不到源...
标签: c++ windows visual-c++ windows-7 uac