.net 系统找不到指定的文件(Visual c+;+;) 我尝试从VisualC++(VS 2012)中的另一个.exe(Windows窗体)运行.exe(Win32),使用进程::开始< /COD> .
出于这个原因,我存储了Win32,Windows窗体位于其中。这个想法是:.net 系统找不到指定的文件(Visual c+;+;) 我尝试从VisualC++(VS 2012)中的另一个.exe(Windows窗体)运行.exe(Win32),使用进程::开始< /COD> .,.net,visual-c++,c++-cli,base-class-library,.net,Visual C++,C++ Cli,Base Class Library,出于这个原因,我存储了Win32,Windows窗体位于其中。这个想法是: 获取模块的完全限定路径:GetModuleFileName 从路径中删除文件名和反斜杠:PathRemoveFileSpec 添加Win32应用程序的名称:sprintf 将字符串^传递给Process::Start 构建并没有错误,但运行失败时会出现错误,如下图所示。我花了很多时间试图解决它,但没有结果。我怎样才能解决这个问题 #include "stdafx.h" #include <stdio.h>
- 获取模块的完全限定路径:
GetModuleFileName
- 从路径中删除文件名和反斜杠:
PathRemoveFileSpec
- 添加Win32应用程序的名称:
sprintf
- 将字符串^传递给
Process::Start
#include "stdafx.h"
#include <stdio.h>
#include <Windows.h>
#include <stdlib.h>
#include <string>
#include <cerrno>
#include <Shlwapi.h>
#include <msclr\marshal_cppstd.h>
using namespace std;
using namespace System;
using namespace msclr::interop;
//code...
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
TCHAR path[1000];
GetModuleFileName(NULL, path, 1000) ; // path: A pointer to a buffer that receives
// the fully qualified path of the module
PathRemoveFileSpec(path); // path: holds location only (TCHAR)
CHAR mypath[1000];
wcstombs(mypath, path, wcslen(path) + 1); // convert tchar to char (mypath)
// Formatting the string: constructing a string by substituting computed values at various
// places in a constant string
CHAR mypath2[1000];
sprintf(mypath2, "%s\\JoypadCodesApplication.exe", mypath);
String^ result;
result = marshal_as<String^>( mypath2 );
Process::Start(result);
}
#包括“stdafx.h”
#包括
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
使用名称空间系统;
使用名称空间msclr::interop;
//代码。。。
私有:系统::无效按钮1\u单击(系统::对象^sender,系统::事件参数^e)
{
TCHAR路径[1000];
GetModuleFileName(NULL,path,1000);//path:指向接收
//模块的完全限定路径
PathRemoveFileSpec(路径);//路径:仅保留位置(TCHAR)
CHAR-mypath[1000];
wcstombs(mypath,path,wcslen(path)+1);//将tchar转换为char(mypath)
//格式化字符串:通过在不同位置替换计算值来构造字符串
//放置在常量字符串中
CHAR mypath2[1000];
sprintf(mypath2,“%s\\JoypadCodesApplication.exe”,mypath);
字符串^result;
结果=封送(mypath2);
过程:开始(结果);
}
既然您正在调用.NET API来启动进程,那么您可以尝试使用.NET API来构建要调用的可执行文件的路径
using namespace System::Diagnostics;
using namespace System::IO;
using namespace System::Reflection;
String^ assemblyLocation = Assembly::GetExecutingAssembly()->Location;
String^ dir = Path::GetDirectoryName(assemblyLocation);
String^ childProcessPath = Path::Combine(dir, "JoypadCodesApplication.exe");
Process::Start(childProcessPath);
如果仍然不起作用,您是否验证了传递给
Process::Start()
的路径是否正确,exe是否位于您认为的位置?您是否正在运行64位机器?编辑:在回答这个问题之前,您是否验证了路径是否正确?您可能需要记录using指令,OP正在努力解决基本问题。@Andy.exe不在我所想的位置。有时,我们在寻找复杂的问题,即使解决方案非常简单。非常感谢。我还要看一看.NETAPI。