我整个上午都在搜寻google,但找不到我想要的东西。我正在为MFC修改的Visual Studio中创建一个常规DLL。也就是说,在项目向导中,我选择了
Win32 Project -> DLL -> MFC
我做了而不是,只是从向导的主列表中单击MFC DLL,这是所有在线教程所描述的。
我的问题很简单。在.cpp文件中,我只需要知道是否应该在
_tmain
函数内部或外部实现我的方法(在.h文件中声明)。 里面有一条评论说
//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;
}
最佳答案
由于您无法在其他函数中实现函数/方法,因此您的方法实现需要超出_tmain
函数的范围。
您引用的注释块可以替换以提供库的初始化实现。
因此,如果您要声明一个类似于SayHello
的函数,则可能看起来像这样:testmfcdllblah.h
:
// Declaration
void SayHello(void);
testmfcdllblah.cpp
:void _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
// .. all the other stuff ..
// TODO: code your application's behavior here.
SayHello();
// .. the rest of the other stuff ..
}
void SayHello()
{
AfxMessageBox("Hello!");
}