效果:一个win32的工程去调用MFC里面的函数(通过导出成.dll或者.lib)一 .MFC生成的是静态的 :生成.lib
1.建立一个MFC工程如MFCtest ,在MFCtestDlg.h 下面添加
#pragma once
#include <afxwin.h>
#include "Resource.h"
#ifdef AAAA_BBBB
#define DLL_EXP __declspec(dllexport)
#else
#define DLL_EXP __declspec(dllimport)
#endif
public:
int test();
2. class /*DLL_EXP*/ CMFCtestDlg : public CDialog
3. MFCtestDlg.cpp里面
CMFCtestDlg::CMFCtestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMFCtestDlg::IDD, pParent)
{
// m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);//注释掉这个
}
int CMFCtestDlg::test()
{
return 123;
}
4.属性->配置属性 –>C/C++预处理器 -》预处理器定义 添加 AAAA_BBBB
配置属性-> 配置类型 :静态库(.lib)
5.编译生成 MFCtest.lib
6. test2
// Test2.cpp : 定义控制台应用程序的入口点。
#include "stdafx.h"
#include "Test2.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
#include "../../MFCtest/MFCtest/MFCtestDlg.h"
#pragma comment(lib, "E:\\test\\MFCtest\\Debug\\MFCtest.lib")
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
CMFCtestDlg dlg(NULL);
printf("test return %d\n", dlg.test());
return 0;
}
动态的话记得把 .dll拷贝到debug去