【发布时间】:2013-02-28 14:43:32
【问题描述】:
我整个早上都在搜索谷歌,但我找不到我要找的东西。我正在为 MFC 修改的 Visual Studio 中创建一个常规 DLL。也就是说在项目向导中,我选择了
Win32 Project -> DLL -> MFC
我做了不只是从向导的主列表中单击 MFC DLL,这是所有在线教程所描述的。
我的问题很简单。在 .cpp 文件中,我只需要知道我应该实现我的方法(在 .h 文件中声明)内部还是外部 _tmain 函数。
里面有一条评论说
//TODO: code your applications behavior here
但我不确定这是否是我的实现所在。
作为参考,这里是 .cpp 文件:
// testmfcdllblah.cpp : Defines the exported functions for the DLL application.
//
#include "stdafx.h"
#include "testmfcdllblah.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// The one and only application object
CWinApp theApp;
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
HMODULE hModule = ::GetModuleHandle(NULL);
if (hModule != NULL)
{
// initialize MFC and print and error on failure
if (!AfxWinInit(hModule, NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
_tprintf(_T("Fatal Error: MFC initialization failed\n"));
nRetCode = 1;
}
else
{
// TODO: code your application's behavior here.
}
}
else
{
// TODO: change error code to suit your needs
_tprintf(_T("Fatal Error: GetModuleHandle failed\n"));
nRetCode = 1;
}
return nRetCode;
}
【问题讨论】:
-
DLL 不包含主函数...如果 MFC 不同的话会很好奇。
-
我认为这里的 _tmain 函数仅用于允许与 MFC 兼容,这意味着在外部实现我的方法。但他们实际上并没有说在哪里实施它们,所以我不太确定......
-
查看this 文章。
-
感谢您的文章,但这是我查看的仅适用于 MFC 的 DLL 的文章之一,我的是经过修改以与 MFC 一起使用的常规 DLL。
-
Dll 可以有一个 main 函数,就像它们可以定义一个 PE32 入口点一样;)