导出类 和安全使用

来源:互联网 发布:常州协同工作软件 编辑:程序博客网 时间:2024/05/21 22:54

1:类构造私有化

2:不直接操作成员变量

3: static CGameUpdate* CreateGameUpdateInstance(); 创建类

 

#pragma once

class __declspec(dllexport) CGameUpdate
{
private:
 CGameUpdate(void);
public:
 ~CGameUpdate(void);
 
 static CGameUpdate* CreateGameUpdateInstance();
 DWORD m_dwXXX;
 BOOL SetVersion(DWORD dwVersion);
 DWORD m_dwVersion;
 DWORD GetVersion();
};

 

 

 

CGameUpdate* CGameUpdate::CreateGameUpdateInstance()
{
 return new CGameUpdate();
}

 

 

 

 

; YeookDll.def : Declares the module parameters for the DLL.

LIBRARY

EXPORTS
    ; Explicit exports can go here
 CreateGameUpdateInstance

 

 

 

 

#include "../YeookDll/GameUpdate.h"
#pragma comment(lib,"../bin/YeookDll.lib")
void CYeookMainDlg::OnBnClickedButton1()
{
 // TODO: Add your control notification handler code here
 CGameUpdate* pTheGameUpdate = CGameUpdate::CreateGameUpdateInstance();
 DWORD dwRet = pTheGameUpdate->GetVersion();
 CString strTemp;
 strTemp.Format(_T("%d"), dwRet);
 AfxMessageBox(strTemp);
}