简体   繁体   English

从Win32控制台应用程序驱动MFC应用程序

[英]Drive MFC Application from Win32 Console Application

I have a situation where I need to essentially run some unit tests against a MFC application. 我遇到的情况是,我基本上需要针对MFC应用程序运行一些单元测试。

I basically have some gtest code in Win32 Console application that needs to be able to create a instance in code of the MFC application and basically do some assertions etc... 我基本上在Win32控制台应用程序中有一些gtest代码,需要能够在MFC应用程序的代码中创建实例并基本上执行一些断言等。

I tried to create a Win32 console application with MFC header included. 我试图创建一个包含MFC标头的Win32控制台应用程序。 I then included the header file of my MFC applicaton class. 然后,我包括了MFC applicaton类的头文件。 However, whenever I try to create an instance ie CWindowApplicationApp the_app in my console application, I receive linking error 但是,每当我尝试在控制台应用程序中创建实例(即CWindowApplicationApp the_app时,都会收到链接错误

This is some of the source code from my console application 这是我的控制台应用程序中的一些源代码

CWindowApplicationApp the_app;

using namespace std;

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;

// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
    // TODO: change error code to suit your needs
    _tprintf(_T("Fatal Error: MFC initialization failed\n"));
    nRetCode = 1;
}
else
{

}

return nRetCode;
}

error LNK2019: unresolved external symbol "public: __thiscall CWindowApplicationApp::CWindowApplicationApp(void)" (??0CWindowApplicationApp@@QAE@XZ) referenced in function "void __cdecl `dynamic initializer for 'the_app''(void)" (??__Ethe_app@@YAXXZ) 错误LNK2019:未解析的外部符号“公共:__ thiscall CWindowApplicationApp :: CWindowApplicationApp(void)”(?? 0CWindowApplicationApp @@ QAE @ XZ)在函数“ void __cdecl'the_app”(void)的动态初始化程序”中引用(?? __ Ethe_app @@ YAXXZ)

Any help? 有什么帮助吗? I have included the header file paths 我已经包含了头文件路径

The linker is telling you it doesn't know where to find the object code for CWindowApplicationApp's constructor. 链接器告诉您它不知道在哪里可以找到CWindowApplicationApp的构造函数的对象代码。

You need to link with whatever object files define CWindowApplicationApp (typically WindowApplicationApp.obj), as well as any other object files that are referred to by WindowApplicationApp.obj (very dependent on your app structure). 您需要链接定义CWindowApplicationApp任何对象文件(通常是WindowApplicationApp.obj),以及WindowApplicationApp.obj引用的任何其他对象文件(非常取决于您的应用程序结构)。

You are on the wrong road. 您走错了路。 It is not possible to create an instance of an application inside another application. 无法在另一个应用程序内创建该应用程序的实例。 What will work is to add some test code into the application and rebuild it. 起作用的是将一些测试代码添加到应用程序中,然后重新构建它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM