如何在C++中将一个.exe链接到另一个.exe
How to link one .exe to another .exe in C++
我有两个.exe
。它们需要在运行时使用彼此的函数。一个是基于目录的应用程序.exe
,另一个是主要应用程序.exe
。现在主应用程序需要使用基于对话框的应用程序功能。但是在编译时,它可以机器人能够定位called function
的存在,因为dialog based applications .lib
不可用。因为如果我将基于对话框的应用程序设为.lib
,那么程序将在运行时失败。所以,我需要拨打一个.exe
到另一个.exe
。当我尝试打电话时,
TestClass tc;/* Call dialog based application exe functions*/
tc.MyTest();
它抛出错误,例如
1>CallExe.obj : error LNK2001: unresolved external symbol "public: __thiscall TestClass::~TestClass(void)" (??1TestClass@@QAE@XZ)
1>CallExe.obj : error LNK2001: unresolved external symbol "public: void __thiscall TestClass::MyTest(void)" (?MyTest@TestClass@@QAEXXZ)
1>CallExe.obj : error LNK2001: unresolved external symbol "public: __thiscall TestClass::TestClass(void)" (??0TestClass@@QAE@XZ)
Main application.cpp
int _tmain(int argc, _TCHAR* argv[])
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
TestClass tc;/* Call dialog based application exe functions*/
tc.MyTest();
// set the size of the structures
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
LPCTSTR szCmdline = (LPCTSTR)(TEXT("Dialog.exe"));
// start the program up
if(!CreateProcess(TEXT("D:\Rasmi's\Personal\Visual Studio\Dialog\Debug\Dialog.exe"), // the path
argv[1], // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi ) // Pointer to PROCESS_INFORMATION structure
)
{cout << "Unable to createn";}
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
return 0;
}
在Dialog.exe
TestClass::TestClass(void)
{
}
TestClass::~TestClass(void)
{
}
void TestClass::MyTest()
{
cout << "This is my Test Class n";
}
您可以使用以下代码来启动 exe 。
char exePath[200];
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE; //SW_SHOWDEFAULT; //Hide the DOS or Console Window
si.hStdInput;
cstring sPrjPath="D:\Rasmi's\Personal\Visual Studio\Dialog\Debug";
sprintf(exePath,"Dialog.exe %s", sPrjPath);
::SetCurrentDirectory(sPrjPath);
if( !CreateProcess( NULL, // No module name (use command line).
exePath, // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
NORMAL_PRIORITY_CLASS,// No creation flags.
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi ) // Pointer to PROCESS_INFORMATION structure.
)
{
WaitForSingleObject( pi.hProcess, INFINITE );
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
return;
}
WaitForSingleObject( pi.hProcess, INFINITE );
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
正如其他人提到的,你有一个基本的设计问题。 你还没有说为什么需要两个可执行文件,但是如果你确实需要两个单独的应用程序相互交互,那么你就需要使用某种形式的进程间通信。
如果两个应用程序只需要共享公共代码来显示对话框窗体,但不需要相互交互,则可以创建一个 DLL 项目来包含共享代码。 然后,您的两个应用程序都将与此 DLL 链接。 有关示例,请参阅 MFC 扩展 DLL。
嗯,你不能那样做。如果你想在调用过程和函数等应用程序之间进行交互,你需要使用XML-RPC之类的东西,如果我理解正确的话
最简单的方法是使用 SendMessage() 将WM_USER消息发送到基于对话框的应用程序,并在消息循环中捕获它(使用 FindWindow() 获取句柄)。如果您有任何参数要传递,请考虑使用 WM_COPYDATA。
相关文章:
- 调试控制台 ChessEngine.exe "used"在另一个应用程序(国际象棋 GUI)中
- C++ |DLL / EXE - 如何从导出的类调用另一个类方法?
- 是否可以将 EXE 文件作为 lib 文件链接到另一个项目?
- 如何将一个 exe 项目链接到另一个 exe 项目中的类
- 将32位和64位应用程序(具有相同代码)编译为一个EXE
- 在另一个C 程序的窗口中打开.exe
- 如何在C++程序中打开一个新的cmd.exe并获取其句柄
- 运行EXE形成另一个EXE并传递参数
- 找出一个正方形逻辑中可能的网格数量,但代码不接受超过六个输入,它停止并说.exe停止工作
- 将数据从一个.exe传递到另一个
- 没有一个Inspect.exe,magnify.exe,nardator.exe运行
- 是否可以使用 C++ 在我的程序中嵌入另一个 exe
- 一个奇怪的"Project.exe has triggered a breakpoint."?
- 调用外部函数(从一个exe到另一个exe)
- 从另一个 exe 运行 Exe
- 将一个exe嵌入到另一个exe中,以便生成单个exe
- 如何使用visual studio 2015创建一个.exe,我可以在桌面上运行
- 这是ntoskrnl.exe中tolower实现中的一个大错误吗
- .exe vs .dll 作为一个程序的模块
- 在 Visual Studio 2012 中将 C 和 C++ 代码编译为一个.exe文件