首先下载并安装 Boost;
在CFree中编写代码如下;
#include
#include "resource.h"
#include
//#include "C://local//boost_1_70_0//boost//regex.hpp"
using namespace std;
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
HINSTANCE hInst;
TCHAR szClassName[] = TEXT("boostDemo");
boost::regex exampleregex( "boost::regex" );
boost::cmatch result;
int WINAPI
WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
HWND hwnd;
MSG messages;
WNDCLASSEX wincl;
hInst = hThisInstance;
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = MAKEINTRESOURCE (IDC_BOOSTDEMO);
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
if (!RegisterClassEx (&wincl))
return 0;
hwnd = CreateWindowEx (
0,
szClassName,
TEXT("boostDemo"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
500,
200,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL
);
ShowWindow (hwnd, nFunsterStil);
while (GetMessage (&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
LRESULT CALLBACK
WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
RECT rt;
char szBuffer[100];
char *buf = "This is boost::regex example";
switch (message)
{
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDM_boost:
hdc=GetDC(hwnd);
if( boost::regex_search( buf, result, exampleregex ) )
{
//std::cout << result.str() << std::endl;
wsprintf(szBuffer, "%s",result.str());
TextOut(hdc,20,20,szBuffer,lstrlen(szBuffer));
}
break;
case IDM_ABOUT:
MessageBox (hwnd, TEXT ("boostDemo v1.0\nCopyright (C) 2020\n by bo"),
TEXT ("boostDemo"), MB_OK | MB_ICONINFORMATION);
break;
case IDM_EXIT:
DestroyWindow(hwnd);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
break;
case WM_CREATE:
break;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
GetClientRect(hwnd, &rt);
EndPaint(hwnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage (0);
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
把boost目录拷贝到CFree的包含目录;
然后就能 #include
此示例调用Boost的正则库;还需要相关的lib和dll文件;
照此文操作;
https://blog.csdn.net/bcbobo21cn/article/details/106147889
拷贝lib和dll到当前工程目录;
然后工程设置如下;
然后构建;出现错误;
ld.exe: cannot find -lboost_regex-vc142-mt-x64-1_70
编译是没有问题;链接时候出错;
现在lib和dll有了;配置和 https://blog.csdn.net/bcbobo21cn/article/details/106147889 一样的;
为什么另一文会成功呢;看下CFree目录;当要使用自己的netapi32.lib和netapi32.dll时,CFree的库目录下有如下;
libnetapi32.a文件;目前要使用boost_regex-vc142-mt-x64-1_70.lib和dll;但是CFree的lib目录下没有 boost_regex-vc142-mt-x64-1_70.lib对应的.a文件;所以不能构建;
那么目前CFree 还不能支持Boost库;