linux下c++编程 转码 GBKTOUTF8问题

老杂鱼 2009-10-10 10:13:36
setup.cpp:
#include "setup.h"
#define __cdn_win32_platform__
#define CP_GB2312 20936
class CodingTransformer
{
public:
// UTF-8 TO GB2312
int UTF_8ToGB2312(char* pOut, int iBufSize, char *pText, int iLenth);
//GB2312 TO UTF-8
int GB2312ToUTF_8(char* pOut, int iBufSize,char *pText, int iLenth);
};
int CodingTransformer::UTF_8ToGB2312(char* pOut, int iBufSize, char *pText, int pLen)
{
#ifdef __cdn_win32_platform__
WCHAR* pWtemp = new WCHAR[pLen];
int iWcharLenth = ::MultiByteToWideChar(CP_UTF8,0,pText,-1,pWtemp,pLen);
if (0 == iWcharLenth)
{
DWORD dwLastErr = GetLastError();
printf("alexaroma:CodingTransformer err,err:%d\n", dwLastErr);
delete pWtemp;
return 0;
}
int iMultByteLenth = ::WideCharToMultiByte(CP_GB2312, NULL, pWtemp,
iWcharLenth, pOut,
iBufSize, NULL, NULL);
if (0 == iMultByteLenth)
{
DWORD dwLastErr = GetLastError();
printf("alexaroma:CodingTransformer err,err:%d\n", dwLastErr);
delete pWtemp;
return 0;
}
delete pWtemp;
return iMultByteLenth;
#else//__cdn_win32_platform__
iconv_t cd;
int rc;
char **pin = &pText;
char **pout = &pOut;
int outlen = iBufSize;
cd = iconv_open("GB2312","UTF-8");
if(cd==0)return -1;
memset(pOut,0,strlen(pOut));
if(iconv(cd,pin,(size_t *)&pLen,pout,(size_t *)&outlen) == -1)
{
iconv_close(cd);
return outlen;
}
iconv_close(cd);
return -1;
#endif//__cdn_win32_platform__
}
int CodingTransformer::GB2312ToUTF_8(char* pOut, int iBufSize, char *pText, int pLen)
{
#ifdef __cdn_win32_platform__
WCHAR* pWtemp = new WCHAR[pLen];
int iWcharLenth = ::MultiByteToWideChar(CP_GB2312, MB_PRECOMPOSED,
pText, -1, pWtemp, pLen);
if (0 == iWcharLenth)
{
DWORD dwLastErr = GetLastError();
printf("alexaroma:CodingTransformer err,err:%d\n", dwLastErr);
delete pWtemp; return 0;
}
int iMultByteLenth = ::WideCharToMultiByte(CP_UTF8, 0, pWtemp,
iWcharLenth, pOut,
iBufSize, NULL, NULL);
if (0 == iMultByteLenth)
{
DWORD dwLastErr = GetLastError();
printf("alexaroma:CodingTransformer err,err:%d\n", dwLastErr);
delete pWtemp;
return 0;
}
delete pWtemp;
return iMultByteLenth;
#else//__cdn_win32_platform__
iconv_t cd;
int rc;
char **pin = &pText;
char **pout = &pOut;
int outlen = iBufSize;
cd=iconv_open("UTF-8","GB2312");
if(cd==0)return -1;
memset(pOut,0,strlen(pOut));
if(iconv(cd,pin,(size_t *)&pLen,pout,(size_t *)&outlen) == -1)
{
iconv_close(cd);
return outlen;
}
iconv_close(cd);
return -1;
#endif//__cdn_win32_platform__
}

setup.h:
#ifndef SC_SETUP_H
#define SC_SETUP_H
#include "../ScriptMgr.h"
#include "Cell.h"
#include "CellImpl.h"
#include "GridNotifiers.h"
#include "GridNotifiersImpl.h"
#include "Unit.h"
#include "GameObject.h"
#include "sc_creature.h"
#include "sc_gossip.h"
#include "sc_instance.h"
#include "CombatAI.h"
#include "PassiveAI.h"
#include "Chat.h"
#include "DBCStructure.h"
#include "DBCStores.h"
#ifdef WIN32
#include <windows.h>
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return true;
}
#endif
#endif
/*
//TODO:UTF8
char* Utf8ToGBK(const char* strUtf8);
char* GBKToUtf8(const char* strGBK);
*/
#define __cdn_win32_platform__
#define CP_GB2312 20936
//UTF-8 TO GB2312
int UTF_8ToGB2312(char* pOut, int iBufSize, char *pText, int iLenth);
//GB2312 TO UTF-8
int GB2312ToUTF_8(char* pOut, int iBufSize, char *pText, int iLenth);

Onescript.cpp:
#define GOSSIP_TEXT_TAVERN GB2312ToUTF_8(" 【主菜单】")

以上代码可以WIN下用也可以在LINUX下用
可是编译出错:
Onescript.cpp.cpp(358) : error C2660: “GB2312ToUTF_8”: 函数不接受 1 个参数
主要是我不懂C++,请教高人给修改修改!
...全文
599 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
pcboyxhy 2009-10-11
  • 打赏
  • 举报
回复
Onescript.cpp.cpp第358行,函数调用时参数填的不对
sdbradycn 2009-10-10
  • 打赏
  • 举报
回复
太深奥了。。。。

65,183

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧