当前位置: 首页 > news >正文

C++ DLL DEMO

头文件dlltest.h

#pragma once
#include "pch.h"
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <bitset>extern "C" __declspec(dllexport) void debugService(uint32_t debugFlags, const std::string& logFileName);

dlltest.cpp

#include "pch.h"
#include "dlltest.h"#define DEBUGvoid logMessage(const std::string& message, uint32_t debugFlags, const std::string& logFileName) {
#ifdef DEBUGstd::ostream* outStream;std::ofstream logFile;if (logFileName.empty()) {outStream = &std::cout;}else {logFile.open(logFileName, std::ios_base::app);if (!logFile.is_open()) {std::cerr << "无法打开日志文件。" << std::endl;return;}outStream = &logFile;}if (debugFlags & 0x04) {*outStream << message << std::endl;}else {for (char c : message) {*outStream << " 0x" << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(c);}*outStream << std::endl;}if (logFile.is_open()) {logFile.close();}
#endif
}__declspec(dllexport) void debugService(uint32_t debugFlags, const std::string& logFileName) {std::string inputData = "123456789";std::string outputData = "987654321";logMessage("输入数据: " + inputData, debugFlags, logFileName);logMessage("输出数据: " + outputData, debugFlags, logFileName);
}

main

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <bitset>
#include "../Dlltest/dlltest.h"int main() {uint32_t debugFlags = 0x00000004; // 设置调试标志std::string logFileName = ""; // 空字符串表示标准输出debugService(debugFlags, logFileName);return 0;
}

输入数据: 123456789
输出数据: 987654321


http://www.mrgr.cn/news/20720.html

相关文章:

  • Node.js 入门:中间件与安全性深度解析
  • android面试:解释一下 AsyncTask是什么?
  • 【生日视频制作】奔驰大G提车交车仪式感广告展示牌AE模板修改文字软件生成器教程特效素材【AE模板】
  • Linux系统性能调优技巧
  • 瞬时流量过大,如何实现服务熔断、降级和限流
  • docker-network
  • 三大技术都有的零信任厂商,他来打擂了!
  • 练习实践-git工具-id:1-git 工具的基础命令
  • Android中Fragment的高级用法
  • 全国科普日知识竞赛答题
  • 网页开发 HTML
  • 飞速了解Conda的作用和安装使用教程
  • Qt实现几何、颜色、不透明度动画
  • 解决商店汽水兑换问题——利用贪心算法与循环结构
  • 4-2.Android Camera 之预览图像编码模板(SurfaceView)
  • zabbix4.0创建自定义监控项
  • 【Boost】Asio库学习(二)
  • C# 排序算法之快速排序
  • 利用全核范数去噪技术优化彩色图像处理
  • Electron32-Vue3OS桌面管理os模板|vite5+electron32+arco后台os系统