从c++启动一个c#应用程序,并在该应用程序上执行一个任务
Launch a C# Application from C++ and performing a task on that application
我看了这篇文章,实现了我的c#应用程序的打开。我的c#应用程序打开一个文件夹并绘制一个图形。我是否有可能告诉我的c#应用程序从c++打开哪个文件夹,然后一旦看到图形并关闭c#程序,它就返回到c++应用程序。
编辑:谢谢马修,我把它修好了
关于我的CreateProcess lpCommandLine变量的另一个查询:(下面是代码)
CString sFolderPath = "C:Documents and Settings...";
int nStrBuffer = sFolderPath.GetLength() + 50;
LPTSTR szParam = _tcsdup(sFolderPath.GetBuffer(nStrBuffer));
nRet = ::CreateProcess(szCmdline,// pointer to name of executable module
szParam,// pointer to command line string
NULL,// pointer to process security attributes
NULL,// pointer to thread security attributes
FALSE,// handle inheritance flag
DETACHED_PROCESS,// creation flags
NULL,// pointer to new environment block
NULL,// pointer to current directory name
&sui,// pointer to STARTUPINFO
&pi );// pointer to PROCESS_INFORMATION
我正确地获得了变量szParam,但是当应用程序打开时,没有复制完整的文件名。例如:在上述情况下,只有"和设置...."被复制,因为"C:Documents"部分被留下。你能指出我的错误吗?
c#实现:[STAThread]
static void Main(string[] args)
{
foreach (string result in args)
{
MessageBox.Show(result);
}
}
这当然是可能的。
c++ CreateProcess()
有一个参数叫做lpCommandLine
。
你需要在c++中做的是传递lpCommandLine
一个字符串,它有你想打开的文件夹的名字。如果文件夹路径包含空格,则需要将字符串用双引号括起来。
在你的c#程序中,你将有一个static void Main(string[] args)
。args
参数将包含您从c++程序传递的文件夹名称,以便您可以适当地对其进行操作。
对于等待c#程序退出的c++程序,它需要使用WaitForSingleObject()
来等待c#程序退出,使用从CreateProcess()
返回的进程句柄。
如下所示:http://www.codeproject.com/Tips/333559/CreateProcess-and-wait-for-result
相关文章:
- FFmpeg:制作一个应用程序比直接使用ffmepg更好吗
- 如何将一个窗口保留在另一个应用程序窗口的前面
- 将库链接到另一个应用程序时,CMAKE 找不到库
- 调试控制台 ChessEngine.exe "used"在另一个应用程序(国际象棋 GUI)中
- 在 Windows 10 中将一个应用程序放在另一个应用程序前面
- 将数据从一个应用程序单向发送到另一个应用程序的最佳做法
- 当电子的窗口隐藏时如何激活另一个应用程序窗口
- 与 Python 中子进程中的另一个应用程序的交互式会话
- 如何将Qt嵌入到另一个应用程序中(非阻塞方式)
- 调试从 Linux 中的另一个C++应用程序启动的 python 脚本
- 在 Linux 上编译一个 c++ 应用程序,并在 TI TIVA TM4C123GH6PM上刷新它
- 另一个应用程序用 c++ 在 Windows 上的线程中破坏 QTimer
- 为什么我需要运行一个应用程序作为Papi库工作的根源
- 发送消息WM_SETTEXT不适用于 MFC 应用程序的另一个应用程序
- 当从一个应用程序调用时,在DLL方法中创建COM接口指针是有效的,但当从另一个应用软件调用时则无效
- 在Qt和C++中从另一个应用程序启动一个应用软件会产生问题
- 在另一个应用程序中嵌入python时,如何在子模块(即scipy.optimize.nnls)中导入或调用函数
- 如何从Windows上的Windows API上的另一个应用程序获得应用程序宽度和高度
- QT应用程序在OSX中启动另一个应用程序
- mfc c++通过编辑控件设置另一个应用程序的HWND地址