(转)将DuiLib编译成静态库

时间:2025-01-24 13:44:20

现在的工程要求是一个PE文件输出, 需要将DuiLib编译成静态库链接进主程序.

需要在中修改2处, 在主程序中还要加一处.

\3rd\DuiLib\

/// @todo 这是编译成静态库的设置
/// 下面被注释掉的是原版DuiLibDll的设置
#define UILIB_API 

// #if defined(UILIB_EXPORTS)
// #if defined(_MSC_VER)
// #define UILIB_API __declspec(dllexport)
// #else
// #define UILIB_API 
// #endif
// #else
// #if defined(_MSC_VER)
// #define UILIB_API __declspec(dllimport)
// #else
// #define UILIB_API 
// #endif
// #endif

末尾要包含一个库

/// @todo 编译静态库需要额外链接的库, 否则被链接的程序无法编译通过

// #pragma comment(lib,"")
// #pragma comment(lib,"")
#pragma comment(lib,"")
// #pragma comment(lib,"")

主程序中要引用 和

//  : Defines the entry point for the application.
//

#include ""
#include ""

#include <>
#pragma comment(lib, "")
using namespace DuiLib;

class CDuiFrameWnd : public CWindowWnd, public INotifyUI
{
public:
	virtual LPCTSTR GetWindowClassName() const { return _T("DUIMainFrame"); }
	virtual void    Notify(TNotifyUI& msg) {}

	virtual LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
	{
		LRESULT lRes = 0;

		if( uMsg == WM_CREATE ) 
		{
			CControlUI *pWnd = new CButtonUI;
			pWnd->SetText(_T("Hello World"));   // 设置文字
			pWnd->SetBkColor(0xFF00FF00);       // 设置背景色

			m_PaintManager.Init(m_hWnd);
			m_PaintManager.AttachDialog(pWnd);
			return lRes;
		}

		if( m_PaintManager.MessageHandler(uMsg, wParam, lParam, lRes) ) 
		{
			return lRes;
		}

		return __super::HandleMessage(uMsg, wParam, lParam);
	}

protected:
	CPaintManagerUI m_PaintManager;
};

int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
	CPaintManagerUI::SetInstance(hInstance);

	CDuiFrameWnd duiFrame;
	(NULL, _T("DUIWnd"), UI_WNDSTYLE_FRAME, WS_EX_WINDOWEDGE);
	();

	return 0;
}

//  : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//

#pragma once

#include ""

#define WIN32_LEAN_AND_MEAN             // Exclude rarely-used stuff from Windows headers
// Windows Header Files:
#include <>
#include <>
#include <>

// C RunTime Header Files
#include <>
#include <>
#include <>
#include <>


// TODO: reference additional headers your program requires here

主程序中只包含UI层, 然后开分别的的工程实现另外2个层 : 业务逻辑层 + 基础支撑层.

对于不同的程序,差别就是各层根据项目的区别有不同.

在程序不能包含Dll的情况下,使用主程序 + 多个静态库进行分层设计, 还是蛮优雅的.