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

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__ */

应用示例:

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

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

12-16 06:27