在 DLL 中启动应用程序
Start Application within a DLL
所以我想创建一个包含应用程序的Dll。我的代码:
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch(ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
StartApp();
break;
}
return TRUE;
}
和启动应用程序功能:
void StartApp()
{
//some declartions
iPtr->Start();
}
问题是函数 Start() 在一个连续循环中运行(就像 while(true)),我认为这就是问题所在,因为 dll 永远不会中断并返回 true。我尝试在不同的线程中运行它,但这不起作用。
所以我的问题是我能做什么来使用 dll?
如果 DllMain 没有完成并且不返回 TRUE 有问题吗?
是的,有一个问题是 DllMain 不返回,如文档所述:
When a DLL entry-point function is called because a process is loading, the function returns TRUE to indicate success. For processes using load-time linking, a return value of FALSE causes the process initialization to fail and the process terminates. For processes using run-time linking, a return value of FALSE causes the LoadLibrary or LoadLibraryEx function to return NULL, indicating failure. (The system immediately calls your entry-point function with DLL_PROCESS_DETACH and unloads the DLL.) The return value of the entry-point function is disregarded when the function is called for any other reason.
源。
您可以为 StartApp 函数创建一个包装函数,并通过 dll 公开它。之后,您可以从可执行文件调用导出的 StartApp 函数(在加载 dll 之后)。确保从其他线程调用它,因为它会阻塞。
- QSerialPort 在应用程序启动之前正在使用中
- C++ - 从 MFC 应用程序启动记事本,并将其默认标题从 "Untitled - Notepad" 更改为其他内容
- 在应用程序启动时停靠 QDockWidget?
- 在应用程序启动时读取文件
- osX - 如何从我的 QT 应用程序启动另一个程序
- 如何跟踪 C++14 中的控制台应用程序启动的次数?
- 调试从 Linux 中的另一个C++应用程序启动的 python 脚本
- 添加新对话框后,MFC 应用程序启动失败并"DLL Initialization Failed"
- 在应用程序启动之前做某事
- 基于CDialog的应用程序启动时,如何将我的辅助对话框窗口带到顶部
- 在Qt和C++中从另一个应用程序启动一个应用软件会产生问题
- 在 C++/STL/MFC 应用程序启动早期发生的致命异常中,是否可以信任堆栈回溯符号名称?
- 从控制台应用程序启动窗口应用程序
- 如何从另一个C++控制台应用程序启动/结束C++控制台应用程序
- 从 MFC(c++) 应用程序启动的可执行 jar 中获取返回值
- 从 MFC 应用程序启动 Java 时,在 MFC 应用程序中显示等待光标,直到它完成其进程
- 从控制台应用程序启动控制台应用程序
- Windows应用程序启动我的控制台
- 从应用程序启动 Linux 服务时避免套接字继承C++
- 如何在应用程序启动后隐藏其命令提示符