基于C/C++的Chinese中文编码dll封装使用

Chinese.c

#include<stdio.h>
#include "chinese.h"
#define UNZ_OK                          (0)
#define Z_ERRNO							(-1)
#define UNZ_ERRNO                       (Z_ERRNO)

typedef  char*(*Format_gbk)(const char*);
typedef  char*(*Format_utf8)(const char*);


//定义API函数变量
HMODULE chineselDll;
int chinese_load = UNZ_ERRNO;
static Format_gbk	_Format_gbk;
static Format_utf8	_Format_utf8;


int chinese_init() {
	char path[] = "D:\\D-Pro\\Summary\\libcurl\\chinese\\Debug\\chinese.dll";
	if (chinese_load == UNZ_OK)
		return UNZ_OK;
	chineselDll = LoadLibrary(path);
	if (chineselDll != NULL) {
		_Format_gbk = (Format_gbk)GetProcAddress(chineselDll, "format_gbk");
		_Format_utf8 = (Format_gbk)GetProcAddress(chineselDll, "format_utf8");
		chinese_load = UNZ_OK;
		return UNZ_OK;
	}
	return UNZ_ERRNO;
}
char* format_gbk(const char *text) {
	chinese_init();
	return _Format_gbk(text);
}
char* format_utf8(const char* text) {
	chinese_init();
	return _Format_utf8(text);
}

chinese.h

#pragma once
#ifndef	__CHINESE_H__
#define __CHINESE_H__
#ifdef __cplusplus
extern "C" {
#endif
char* format_gbk(const char* text);
char* format_utf8(const char* text);
#ifdef __cplusplus
}
#endif

#endif	/* __CHINESE_H__ */

应用示例:

 printf("\nresult:%s", result);

 printf("\nresult:%s", format_gbk(result));

相关推荐

  1. 使用 bert-base-chinese-ner 模型实现中文NER

    2023-12-16 05:56:02       11 阅读
  2. 使用.cc域名优势

    2023-12-16 05:56:02       13 阅读

最近更新

  1. TCP协议是安全的吗?

    2023-12-16 05:56:02       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-16 05:56:02       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-16 05:56:02       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-16 05:56:02       18 阅读

热门阅读

  1. go-zero开发入门之gateway深入研究1

    2023-12-16 05:56:02       34 阅读
  2. lua安装

    lua安装

    2023-12-16 05:56:02      44 阅读
  3. Vue中实现分布式动态路由的基本实现步骤介绍

    2023-12-16 05:56:02       36 阅读
  4. RabbitMQ 命令

    2023-12-16 05:56:02       44 阅读
  5. Python录制和绘制音频

    2023-12-16 05:56:02       45 阅读
  6. 10129 - Play on Words (UVA)

    2023-12-16 05:56:02       45 阅读
  7. word如何快速制作简易代码块

    2023-12-16 05:56:02       39 阅读
  8. 「CocoaPods」Podfile文件模板

    2023-12-16 05:56:02       44 阅读
  9. MySQL DQL

    MySQL DQL

    2023-12-16 05:56:02      37 阅读