(转)将DuiLib编译成静态库
发布日期:2021-06-30 22:04:30 浏览次数:2 分类:技术文章

本文共 2543 字,大约阅读时间需要 8 分钟。

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

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

\3rd\DuiLib\UIlib.h

/// @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

Uilib.h末尾要包含一个库

/// @todo 编译静态库需要额外链接的库, 否则被链接的程序无法编译通过// #pragma comment(lib,"oledlg.lib")// #pragma comment(lib,"winmm.lib")#pragma comment(lib,"comctl32.lib")// #pragma comment(lib,"Riched20.lib")
主程序中要引用atlbase.h 和 tchar.h

// testDuiLibStaticLib.cpp : Defines the entry point for the application.//#include "stdafx.h"#include "testDuiLibStaticLib.h"#include 
#pragma comment(lib, "DuiLib.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; duiFrame.Create(NULL, _T("DUIWnd"), UI_WNDSTYLE_FRAME, WS_EX_WINDOWEDGE); duiFrame.ShowModal(); return 0;}
// stdafx.h : include file for standard system include files,// or project specific include files that are used frequently, but// are changed infrequently//#pragma once#include "targetver.h"#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的情况下,使用主程序 + 多个静态库进行分层设计, 还是蛮优雅的.

转载地址:https://lostspeed.blog.csdn.net/article/details/19098213 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:note : Release program embedded resource
下一篇:(转)VisualSVN-Server 在Win8 本本上无法安装

发表评论

最新留言

第一次来,支持一个
[***.219.124.196]2024年04月26日 15时51分14秒