关于调用Fnthex32.dll实现对汉字的转换的问题

skyhorsemp 2008-09-27 03:35:16
为实现斑马打印机对汉字的打印,需调用Fnthex32.dll的函数GETFONTHEX()对汉字进行转换,但是调用此函数时,系统都异常中断,还请各位帮忙解决!

[相关线索]:

函数声明:/*Global External Functions*/
function int GETFONTHEX(string outstr,string fontname,string outstrname,&
int orient,int height,int width,int bold,int italic,&
ref string hexbuf) library "fnthex32.dll"

函数调用:/*在BUTTON控件中CLICKED事件中添加*/
integer int_filenum
string named,cBuf

GETFONTHEX("条码测试", "宋体", "chnstr01", 0, 50, 0, 1, 0, cBuf)

//测试汉字转换是否成功//
named='test.txt'
int_filenum=FileOpen(named,StreamMode!,write!,Lockwrite!,Append!)
filewrite(int_filenum,cBuf)
fileclose(int_filenum)

错误提示:
"Error:Error calling external function %s at ling 4 in cliked event of object cb_1 of w_test"

P.S: 之前使用的PB版本为9.0.0.5507,在网上看到有的网友说是PB的BUG,遂升级至9.0.3.8836也没有得到解决
...全文
1241 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
guiguzihanbo 2009-01-09
  • 打赏
  • 举报
回复
楼上的哥们,你的程序好用吗?我急用看到留言速联系。QQ38843799
yanger601 2009-01-05
  • 打赏
  • 举报
回复
我写的一个代码,看看有没有用
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Text;

/// <summary>
/// BarCodeTool 的摘要说明
/// </summary>
public class BarCodeTool
{
/// <summary>
/// 获取字体编码
/// </summary>
/// <param name="printText">打印文本</param>
/// <param name="printFont">字体名称</param>
/// <param name="Orientation">旋转方向</param>
/// <param name="height">高度</param>
/// <param name="width">宽度</param>
/// <param name="IsBold">是否粗体</param>
/// <param name="IsItalic">是否斜体</param>
/// <returns></returns>
public static ConverFontToImageResult getFontText(string printText, string printFont, Orientation Orientation, int height, int width, bool IsBold, bool IsItalic)
{
ConverFontToImageResult result = null;
try
{
StringBuilder buder = new StringBuilder(3000);
string temp = string.Empty;
int bold = IsBold ? 1 : 0;
int italic = IsItalic ? 1 : 0;

int count = GETFONTHEX(printText, printFont, 0, height, width, bold, italic, buder);
if (count > 0)
{
//temp = Marshal.PtrToStringAnsi(ptrIn);
result = new ConverFontToImageResult();
temp = buder.ToString();
string[] data = temp.Split(',');

result.ImageName = data[0].Replace("~DG", "");
result.Instruction = "~DG";
result.TotalSize = data[1];
result.RowSize = data[2];
result.ImageData = data[3];
}
}
catch (Exception ex)
{

}

return result;
}


[DllImport(@"E:\BarCode\Bin\Fnthex32.dll", CharSet = CharSet.Ansi)]
public static extern int GETFONTHEX(
string chnstr,
string fontname,
int orient,
int height,
int width,
int bold,
int italic,
StringBuilder param1);
}


public class ConverFontToImageResult
{
private string imageName;
/// <summary>
/// 文件名称
/// </summary>
public string ImageName
{
get { return imageName; }
set { imageName = value; }
}

private string instruction;
/// <summary>
/// 图片指令
/// </summary>
public string Instruction
{
get { return instruction; }
set { instruction = value; }
}
private string imageData;
/// <summary>
/// 图片数据
/// </summary>
public string ImageData
{
get { return imageData; }
set { imageData = value; }
}

private string totalSize;
/// <summary>
/// 总共字节数
/// </summary>
public string TotalSize
{
get { return totalSize; }
set { totalSize = value; }
}
private string rowSize;
/// <summary>
/// 每行字节数
/// </summary>
public string RowSize
{
get { return rowSize; }
set { rowSize = value; }
}

/// <summary>
/// 获取包装过的数据字符串
/// </summary>
/// <returns></returns>
public string GetDateString()
{
return string.Format("{0}{1},{2},{3},{4}", this.Instruction, this.ImageName, this.TotalSize, this.RowSize, this.ImageData);
}


/// <summary>
/// 获取包装过的数据字符串
/// </summary>
/// <returns></returns>
public string GetDateString(string iamgeName)
{
return string.Format("{0}{1},{2},{3},{4}", this.Instruction, iamgeName, this.TotalSize, this.RowSize, this.ImageData);
}
}

public enum Orientation
{
Orien0,
Orien90,
Orien180,
Orien270
}
skyhorsemp 2008-10-06
  • 打赏
  • 举报
回复
问题解决了。

GETFONTHEX申明的参数有问题,按如下申明和调用,程序运行正常。

函数声明:/*Global External Functions*/
function int GETFONTHEX(string outstr,string fontname,&
int orient,int height,int width,int bold,int italic,&
ref string hexbuf) library "fnthex32.dll"

pcwe2002 2008-09-27
  • 打赏
  • 举报
回复
GETFONTHEX在C中是如何申明的
kenshu 2008-09-27
  • 打赏
  • 举报
回复
你看看

GETFONTHEX

有没有分大小写.
skyhorsemp 2008-09-27
  • 打赏
  • 举报
回复
谢谢kenshu给予回复。

1.cBuf = space(1000)//开多少,看你硬件供应商的说明.

添加进去,问题依然存在。

2.function long GETFONTHEX

修改过后,问题依然存在。

kenshu 2008-09-27
  • 打赏
  • 举报
回复
而且,还有一个,

function int GETFONTHEX
很大机会是
function long GETFONTHEX //比如VC6的int,PB就是LONG了。
kenshu 2008-09-27
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 kenshu 的回复:]
cBuf这个无论如何必须先申请空间

cBuf = space(1000)//开多少,看你硬件供应商的说明.

---------------------------------------
但你不是这个错,函数名区分大小写.一般用C编程的,不会全部用大写.
[/Quote]

"函数名区分大小写"是指
function int GETFONTHEX

kenshu 2008-09-27
  • 打赏
  • 举报
回复
cBuf这个无论如何必须先申请空间

cBuf = space(1000)//开多少,看你硬件供应商的说明.

---------------------------------------
但你不是这个错,函数名区分大小写.一般用C编程的,不会全部用大写.

680

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder API 调用
社区管理员
  • API 调用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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