谁有在VC中利用代码页(code page)进行代码转换的经验?请进来.

salt_stone 2003-06-09 01:12:52
我目前只会在 unicode 和 ascii 之间互转,
而我面对的问题是如何把 IBM 的 EBCDIC 码转成ascii.
(包括对中文的转换!! 不带中文的我用TC2.0随便写了个小程序就转了:) )
...全文
408 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
salt_stone 2003-06-17
  • 打赏
  • 举报
回复
to stoneliuwg(白猫黑猫):
不好意思,可能是我比较笨,但我确实看不懂你的程序.
你的程序除了在main函数中有一行设置代码页以外,后面的代码即没有涉及代码页,
也没有涉及代码转换.我不明白你怎样能够把带中文的EBCDIC码字符串转换成
ascii或者unicode.不过,还是要谢谢你的回复.


stoneliuwg 2003-06-15
  • 打赏
  • 举报
回复
#include <windows.h>
HANDLE hOut;
void ShadowWindowLine(char *str); // 在具有阴影效果的窗口中显示一行字符,窗口为居中显示
void DrawBox(bool bSingle, SMALL_RECT rc); // 绘制边框
void main()
{
 hOut = GetStdHandle(STD_OUTPUT_HANDLE); // 获取标准输出设备句柄
 SetConsoleOutputCP(437); // 设置代码页
 ShadowWindowLine("Display a line of words, and center the window with shadow.");
 CloseHandle(hOut); // 关闭标准输出设备句柄
}

void ShadowWindowLine(char *str)
{
 CONSOLE_SCREEN_BUFFER_INFO bInfo; // 窗口缓冲区信息
 GetConsoleScreenBufferInfo( hOut, &bInfo ); // 获取窗口缓冲区信息
 // 计算显示窗口大小和位置
 int x1, y1, x2, y2, chNum = strlen(str);
 x1 = (bInfo.dwSize.X - chNum)/2 - 2;
 y1 = bInfo.dwSize.Y/2 - 2;
 x2 = x1 + chNum + 4;
 y2 = y1 + 5;
 WORD att1 = BACKGROUND_INTENSITY; // 阴影属性
 WORD att0 = FOREGROUND_RED |FOREGROUND_GREEN |FOREGROUND_BLUE |  
       FOREGROUND_INTENSITY |
       BACKGROUND_RED | BACKGROUND_BLUE; // 文本属性

 WORD attText = FOREGROUND_RED |FOREGROUND_INTENSITY; // 文本属性
 // 设置阴影
 COORD posShadow = {x1+1, y1+1}, posText = {x1, y1};
 for (int i=0; i<5; i++){
  FillConsoleOutputAttribute(hOut, att1, chNum + 4, posShadow, NULL);
  posShadow.Y++;
 }
 // 填充窗口背景
 for (i=0; i<5; i++){
  FillConsoleOutputAttribute(hOut, att0, chNum + 4, posText, NULL);
  posText.Y++;
 }
 // 写文本和边框
 posText.X = x1 + 2;
 posText.Y = y1 + 2;
 WriteConsoleOutputCharacter(hOut, str, strlen(str), posText, NULL);
 SMALL_RECT rc = {x1, y1, x2-1, y2-1};
 DrawBox(true, rc);
 SetConsoleTextAttribute(hOut, bInfo.wAttributes); // 恢复原来的属性
}

void DrawBox(bool bSingle, SMALL_RECT rc)
{
 char chBox[6];
 if (bSingle) {
  chBox[0] = (char)0xda; // 左上角点
  chBox[1] = (char)0xbf; // 右上角点
  chBox[2] = (char)0xc0; // 左下角点
  chBox[3] = (char)0xd9; // 右下角点
  chBox[4] = (char)0xc4; // 水平
  chBox[5] = (char)0xb3; // 坚直
 } else {
  chBox[0] = (char)0xc9; // 左上角点
  chBox[1] = (char)0xbb; // 右上角点
  chBox[2] = (char)0xc8; // 左下角点
  chBox[3] = (char)0xbc; // 右下角点
  chBox[4] = (char)0xcd; // 水平
  chBox[5] = (char)0xba; // 坚直
 }
 COORD pos = {rc.Left, rc.Top};
 WriteConsoleOutputCharacter(hOut, &chBox[0], 1, pos, NULL);

 for (pos.X = rc.Left + 1; pos.X  WriteConsoleOutputCharacter(hOut, &chBox[4], 1, pos, NULL);

 pos.X = rc.Right;
 WriteConsoleOutputCharacter(hOut, &chBox[1], 1, pos, NULL);

 for (pos.Y = rc.Top+1; pos.Y {
  pos.X = rc.Left;
  WriteConsoleOutputCharacter(hOut, &chBox[5], 1, pos, NULL);
  pos.X = rc.Right;
  WriteConsoleOutputCharacter(hOut, &chBox[5], 1, pos, NULL);
 }
 pos.X = rc.Left; pos.Y = rc.Bottom;
 WriteConsoleOutputCharacter(hOut, &chBox[2], 1, pos, NULL);
 
 for (pos.X = rc.Left + 1; pos.X  WriteConsoleOutputCharacter(hOut, &chBox[4], 1, pos, NULL);

 pos.X = rc.Right;
 WriteConsoleOutputCharacter(hOut, &chBox[3], 1, pos, NULL);
}

 
  需要说明的是,上述程序在不同的字符代码页面(code page)下显示的结果是不同的。例如,中文Windows操作系统的默认代码页是简体中文(936),在该代码页面下值超过128的单字符在Windows NT/XP是显示不出来的。下表列出了可以使用的代码页。

代码页(Code page) 说 明
1258 越南文
1257 波罗的海文
1256 阿拉伯文
1255 希伯来文
1254 土耳其语
1253 希腊文
1252 拉丁文(ANSI)
1251 斯拉夫文
1250 中欧文
950 繁体中文
949 韩文
936 简体中文
932 日文
874 泰文
850 使用多种语言(MS-DOS拉丁文)
437 MS-DOS美语/英语
salt_stone 2003-06-12
  • 打赏
  • 举报
回复
to duwenyong(啸海)
不好意思,我刚才仔细看了一下上面的说明,好像两个函数中针对string 这个
参数的说明里都没有提到中文,而只是一般的可见字符而已。
这样的话,这两个函数对我的意义就不是很大。因为我一开始就说过了,要包括
对中文的转换,不带中文的我已经用别的程序转换了,就是带中文的我转不了。
我在问题中提到代码页(code page)的使用,主要是因为IBM 的 Pcomm 就是靠它
来进行代码转换的,所以才希望有人介绍以下使用代码页(code page)的经验。//hehe
salt_stone 2003-06-12
  • 打赏
  • 举报
回复
to duwenyong(啸海)
首先谢谢你的帮助,不过因为我没有使用过 SNA Server ,
所以能不能请你帮我找一些例子程序以供我参考。
此外,我有一个和hwndhwnd(何宗键) 类似的担心:
这个功能不会是必须先启动一个SNA 或者Pcomm 的 session 才能使用吧。//hehe

顺便问一下,前两天回答问题的 ShLikeWater(若水) 是你吗?
如果是的话,我就不用分开给分了。:)


to hwndhwnd(何宗键)
谢谢你的关注和回复,有空大家多交流一下。
毕竟懂大机又能在PC上开发的人不是很多。//hehe

hwndhwnd 2003-06-12
  • 打赏
  • 举报
回复
不会转换个代码页,要让我安装sna server吧。
duwenyong 2003-06-12
  • 打赏
  • 举报
回复
Converting From ASCII-EBCDIC Using CPICs CMCNVI and CMCNVO
ID: Q188689



--------------------------------------------------------------------------------
The information in this article applies to:

Microsoft SNA Server, versions 3.0, 3.0SP1, 3.0SP2, 3.0SP3, 4.0, 4.0SP1

--------------------------------------------------------------------------------


SYMPTOMS
SNA Server's CPIC libraries now provide data conversion support through the use of two new CPIC function calls.



Convert_Outgoing (CMCNVO) - The Convert_Outgoing() call is designed to translate text strings from ASCII to EBCDIC and is issued before sending data to a computer that uses EBCDIC encoding (for example, the host).


Convert_Incoming (CMCNVI) - The Convert_Incoming() is designed to translate text strings from EBCDIC to ASCII and is typically issued after receiving data from a computer that uses EBCDIC encoding.


NOTE: These function calls do not take a conversation ID as input and can therefore, be used even if an active conversation does not exist.



RESOLUTION

SNA Server 3.0
To resolve this problem, obtain the latest service pack for SNA Server version 3.0. For additional information, please see the following article in the Microsoft Knowledge Base:

Q184307 How to Obtain the Latest SNA Server Version 3.0 Service Pack


SNA Server 4.0
To resolve this problem, obtain the latest service pack for SNA Server version 4.0. For additional information, please see the following article in the Microsoft Knowledge Base:

Q215838 How to Obtain SNA Server Version 4.0 U.S Service Pack 2





STATUS
Microsoft has confirmed this to be a problem in SNA Server 3.0, 3.0 SP 1, 3.0 SP 2, 3.0 SP 3, 4.0, 4.0 SP 1. This problem was first corrected in SNA Server 3.0 Service Pack 4.



MORE INFORMATION
The function call definitions for CMCNVO and CMCNVI are listed below.

Convert_Incoming()
The Convert_Incoming call (function name cmcnvi) converts a string of EBCDIC characters into ASCII.

NOTE: The return conversion can be performed using Convert_Outgoing.

CM_ENTRY Convert_Incoming(
unsigned char FAR *string,
CM_INT32 FAR *string_length,
CM_INT32 FAR *return_code
);
Parameters
string

Supplied parameter. Specifies the EBCDIC string to be converted. It may contain any of the following characters:

Uppercase A-Z, lowercase a-z, 0-9, the period (.) and space
characters, and the special characters < > + - ( ) &
* ; : , ' ? / _ = ".

string_length characters of this string will be replaced by ASCII equivalents.
string_length

Supplied parameter. Specifies the number of characters to be converted (1 - 32767).

return_code

The code returned from this call. The valid return codes are listed below.

Return Codes:

CM_OK Primary return code; the call executed successfully, the string parameter now contains the converted ASCII string.

CM_PROGRAM_PARAMETER_CHECK Primary return code; the string_length parameter specified an invalid value.

CM_PRODUCT_SPECIFIC_ERROR Primary return code; a product-specific error occurred and has been logged in the product's error log.

State Changes:

The conversation can be in any state. There is no state change.

Remarks:

When data is being received in buffer format in a basic conversation the data buffer may contain multiple logical records; each consisting of a two- byte length field (NN), followed by the data. The application must extract and convert each data string separately (not including the NN bytes). It must not attempt to convert the whole buffer in one operation, because this will make the NN values invalid.
Convert_Outgoing()
The Convert_Outgoing call (function name cmcnvo) converts a string of ASCII characters into EBCDIC.

NOTE: The return conversion can be performed using Convert_Incoming.

CM_ENTRY Convert_Outgoing(
unsigned char FAR *string,
CM_INT32 FAR *string_length,
CM_INT32 FAR *return_code
);
Parameters:

string - Supplied parameter. Specifies the ASCII string to be converted. It may contain any of the following characters:



Uppercase A-Z, lowercase a-z, 0-9, the period (.) and space
characters, and the special characters < > + - ( ) & * ; : , ' ?
/ _= ".

string_length characters of this string will be replaced by EBCDIC
equivalents.
string_length - Supplied parameter. Specifies the number of characters to be converted (1 - 32767).

return_code - The code returned from this call. The valid return codes are listed below.

Return Codes:

CM_OK Primary return code; the call executed successfully, the string parameter now contains the converted EBCDIC string.

CM_PROGRAM_PARAMETER_CHECK Primary return code; the string_length parameter specified an invalid value.

CM_PRODUCT_SPECIFIC_ERROR Primary return code; a product-specific error occurred and has been logged in the product's error log.

State Changes:

The conversation can be in any state. There is no state change.

Remarks:

When data is being received in buffer format in a basic conversation the data buffer may contain multiple logical records; each consisting of a two- byte length field (NN), followed by the data. The application must extract and convert each data string separately (not including the NN bytes). It must not attempt to convert the whole buffer in one operation, because this will make the NN values invalid.

For more information concerning character conversion support, please see the following Microsoft Knowledge Base article:


Q139114 SNA Server Support for ASCII-EBCDIC Character Conversion

Additional query words: ebcdic ascii convert conversion CPI-c appc

Keywords :
Version : WINDOWS:3.0,3.0SP1,3.0SP2,3.0SP3,4.0,4.0SP1
Platform : WINDOWS
Issue type : kbbug


Last Reviewed: July 8, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.




--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources.
duwenyong 2003-06-12
  • 打赏
  • 举报
回复

Platform SDK: SNA Server
Convert_Outgoing
The Convert_Outgoing call (function name cmcnvo) converts a string of ASCII characters into EBCDIC. Note that the return conversion can be performed using Convert_Incoming.

CM_ENTRY Convert_Outgoing(
unsigned char FAR *string,
CM_INT32 FAR *string_length,
CM_INT32 FAR *return_code
);

Parameters
string
Supplied parameter. Specifies the ASCII string to be converted. The string may contain any of the following characters:
uppercase A-Z
lowercase a-z
0-9
the period (.)
space characters
the special characters < > + - ( ) & * ; : , ' ? / _= ".
string_length characters of this string will be replaced by EBCDIC equivalents.

string_length
Supplied parameter. Specifies the number of characters to be converted (1 - 32767).
return_code
The code returned from this call. The valid return codes are listed below.
Return Codes
CM_OK
Primary return code; the call executed successfully and the string parameter now contains the converted EBCDIC string.
CM_OPERATION_NOT_ACCEPTED
Primary return code; the string_length parameter specified an invalid value.
CM_PRODUCT_SPECIFIC_ERROR
Primary return code; a product-specific error occurred and has been logged in the product's error log.
State Changes
The conversation can be in any state.

There is no state change.

Remarks
When data is being received in buffer format in a basic conversation, the data buffer may contain multiple logical records, each consisting of a two-byte length field (NN) followed by the data. The application must extract and convert each data string separately (excluding the length field value). The applications must not attempt to convert the whole buffer in one operation, because this will make the length field values invalid.

Built on Tuesday, May 09, 2000
duwenyong 2003-06-12
  • 打赏
  • 举报
回复

Platform SDK: SNA Server
Convert_Incoming
The Convert_Incoming call (function name cmcnvi) converts a string of EBCDIC characters into ASCII. Note that the return conversion can be performed using Convert_Outgoing.

CM_ENTRY Convert_Incoming(
unsigned char FAR *string,
CM_INT32 FAR *string_length,
CM_INT32 FAR *return_code
);

Parameters
string
Supplied parameter. Specifies the EBCDIC string to be converted. The string may contain any of the following characters:
uppercase A-Z
lowercase a-z
0-9
the period (.)
space characters
the special characters < > + - ( ) & * ; : , ' ? / _= ".
string_length characters of this string will be replaced by ASCII equivalents.

string_length
Supplied parameter. Specifies the number of characters to be converted (1 - 32767).
return_code
The code returned from this call. The valid return codes are listed below.
Return Codes
CM_OK
Primary return code; the call executed successfully and the string parameter now contains the converted ASCII string.
CM_OPERATION_NOT_ACCEPTED
Primary return code; the string_length parameter specified an invalid value.
CM_PRODUCT_SPECIFIC_ERROR
Primary return code; a product-specific error occurred and has been logged in the product's error log.
State Changes
The conversation can be in any state.

There is no state change.

Remarks
When data is being received in buffer format in a basic conversation, the data buffer may contain multiple logical records, each consisting of a two-byte length field (NN) followed by the data. The application must extract and convert each data string separately (excluding the length field value). The applications must not attempt to convert the whole buffer in one operation, because this will make the length field values invalid.

Built on Tuesday, May 09, 2000
salt_stone 2003-06-10
  • 打赏
  • 举报
回复
还是没人会吗?
salt_stone 2003-06-10
  • 打赏
  • 举报
回复
to ShLikeWater(若水)
谢谢你的回复.
不过我是晚上才看到的,你已经不在站上了,无法和你联系.
你能不能把上面这个函数所需的头文件和具体的用法等再详细一点写出来,有例子程序更好.
因为我手头这台机器上刚好没有MSDN,所以查不到.
//hehe
ShLikeWater 2003-06-10
  • 打赏
  • 举报
回复
CM_ENTRY Convert_Incoming()
salt_stone 2003-06-09
  • 打赏
  • 举报
回复
没人会吗?

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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