天天看點

ICE專題:利用ICE編寫程式的幾個注意點

利用ICE寫程式時,一定要注意的幾件事

1、用Windows作為伺服器是一件非常不爽的事。

2、在windows下寫用戶端的時候,一定要用slice2xxx.exe的版本,否則在vc中可能編譯過去,會有一些奇怪的問題,可能是vc中的stl與stl_port還會有一定的本質差別。

3、涉及到漢字的時候,一定要記得将utf8碼轉換成gbk碼,要不 一定是亂碼

附轉碼程式:

// stdafx.h : include file for standard system include files,

//  or project specific include files that are used frequently, but

//      are changed infrequently

//

#if !defined(AFX_STDAFX_H__2843B98C_6C05_4A40_9CBC_51BD61B69760__INCLUDED_)

#define AFX_STDAFX_H__2843B98C_6C05_4A40_9CBC_51BD61B69760__INCLUDED_

#if _MSC_VER > 1000

#pragma once

#endif // _MSC_VER > 1000

#define VC_EXTRALEAN  // Exclude rarely-used stuff from Windows headers

#undef _WINDOWS_

#include <afxwin.h>         // MFC core and standard components

#include <afxext.h>         // MFC extensions

#include <afxdtctl.h>  // MFC support for Internet Explorer 4 Common Controls

#ifndef _AFX_NO_AFXCMN_SUPPORT

#include <afxcmn.h>   // MFC support for Windows Common Controls

#endif // _AFX_NO_AFXCMN_SUPPORT

//{{AFX_INSERT_LOCATION}}

// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_STDAFX_H__2843B98C_6C05_4A40_9CBC_51BD61B69760__INCLUDED_)

#include "StdAfx.h"

void ConvertGBKToUtf8(CString& strGBK);

void ConvertUtf8ToGBK(CString& strUtf8);

#include "UTF8.h"

void ConvertGBKToUtf8(CString& strGBK) {

    int len=MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)strGBK, -1, NULL,0);

    unsigned short * wszUtf8 = new unsigned short[len+1];

    memset(wszUtf8, 0, len * 2 + 2);

    MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)strGBK, -1, wszUtf8, len);

    len = WideCharToMultiByte(CP_UTF8, 0, wszUtf8, -1, NULL, 0, NULL, NULL); 

    char *szUtf8=new char[len + 1];

    memset(szUtf8, 0, len + 1);

    WideCharToMultiByte (CP_UTF8, 0, wszUtf8, -1, szUtf8, len, NULL,NULL);

    strGBK = szUtf8;

    delete[] szUtf8;

    delete[] wszUtf8;

}

void ConvertUtf8ToGBK(CString& strUtf8) {

    int len=MultiByteToWideChar(CP_UTF8, 0, (LPCTSTR)strUtf8, -1, NULL,0);

    unsigned short * wszGBK = new unsigned short[len+1];

    memset(wszGBK, 0, len * 2 + 2);

    MultiByteToWideChar(CP_UTF8, 0, (LPCTSTR)strUtf8, -1, wszGBK, len);

    len = WideCharToMultiByte(CP_ACP, 0, wszGBK, -1, NULL, 0, NULL, NULL); 

    char *szGBK=new char[len + 1];

    memset(szGBK, 0, len + 1);

    WideCharToMultiByte (CP_ACP, 0, wszGBK, -1, szGBK, len, NULL,NULL);

    strUtf8 = szGBK;

    delete[] szGBK;

    delete[] wszGBK;

本文轉自斯克迪亞部落格園部落格,原文連結:http://www.cnblogs.com/sgsoft/archive/2007/05/02/734482.html,如需轉載請自行聯系原作者