Vc dll中导出类的方法

class _declspec(dllimport) circle
class _declspec(dllimport) circle
#pragma comment("lib", "dll.lib")
就用这三句话轻松搞定,什么def文件都他妈的狗屁

大家可以下载源代码http://www.84250.com/BLOG/attachments/month_200512/14_230909_1xp4Vcdll.rar

#include "windows.h"

class _declspec(dllimport) circle //导出类circle
{
public:
  circle();
  int getnum();
  void setnum(int arg);
private:
  int num;
};

circle::circle()        {num=2;}
int circle::getnum()      {return num;}
void circle::setnum(int arg)  {num=arg;}

/**************************************************
dllMain函数可有可无,因为它并不做什么工作,系统会自动生成的
***************************************************/
BOOL APIENTRY DllMain( HANDLE hModule,
           DWORD ul_reason_for_call,
           LPVOID lpReserved
           )
{
return TRUE;
}


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


class _declspec(dllimport) circle //导出类circle
{
public:
  circle();
  int getnum();
  void setnum(int arg);
private:
  int num;
};

void CExeDlg::OnButton1()
{
  circle a;
  CString temp;
  temp.Format("%d",a.getnum());
  MessageBox(temp);
  
  a.setnum(1000);
  temp.Format("%d",a.getnum());
  MessageBox(temp);  
}

普通win32 DLL ,用__declspec(dllexport)修饰导出类
或者建立一个MFC 扩展DLL

做成MFC扩展DLL,然后在导出的类前面加AFX_EXT_CLASS
和一般的dll一样,仅是
在类前面加上AFX_EXT_CLASS ,如
class AFX_EXT_CLASS Cxx : public CObject
{
.....
};
 

你可能感兴趣的:(Vc dll中导出类的方法)