Print Chinese in Delphi successful but in C# failed.

F

franchdream

DELPHI code:
unit test1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
RadioGroup1: TRadioGroup;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
//procedure DrawToCanvas(Cav: Tcanvas;x,y:integer);Stdcall;external
'KwBarDll.dll';
procedure Epson_Text8d(M:Smallint;F:byte;S:string);stdcall; external
'Epson.dll';
procedure Epson_Text(M:Smallint;F:byte;S:string);stdcall;external
'Epson.dll';
procedure EpsonPrnLn(S:string);stdcall;external 'Epson.dll';
function GetDefaultPrinter:string;stdcall;external 'Epson.dll';
procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
begin
for i:=0 to Memo1.Lines.Count-1 do
begin
if RadioGroup1.ItemIndex=0 then
Epson_Text8d(14,0,Memo1.Lines);
if RadioGroup1.ItemIndex=1 then
Epson_Text(18,0,Memo1.Lines);// print procedure
if RadioGroup1.ItemIndex=2 then
EpsonPrnLn(Memo1.Lines);
end;
end;

procedure TForm1.FormShow(Sender: TObject);
begin
Label1.Caption:='printer's name£º'+GetDefaultPrinter;
end;

end.

It can print Chinese character,but my C# code:

[DllImport("Epson.dll", EntryPoint = "Epson_Text", CallingConvention =
CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true,
ExactSpelling = true)]
public static extern void Epson_Text(Int16 M, byte F, string S);
.........
string st = "ÖÐÎÄÊDz»ÊDZàÂëÓÐʲôҪÇó";
Epson_Text(18, 0, st);

It can't work.
Anyone has suggest for me. Thanks!
 
M

Merlin

I have resolved it.

Cool... Glad to read it. But can you say how you solved it, so I will
not have read your message for nothing... thanks in advance :)
 
F

franchdream

The dll is writed by Delphi, and the .NET pass the String parameter to DLL
is unicode on NT or XP. So
[DllImport("Epson.dll", EntryPoint = "Epson_Text", CallingConvention =
CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true,
ExactSpelling = true)]
is wrong . It should be
[DllImport("Epson.dll", EntryPoint = "Epson_Text", CallingConvention =
CallingConvention.StdCall, CharSet = CharSet.Ansi, SetLastError = true,
ExactSpelling = false)]
"ExactSpelling = false", why? Because the .NET must change the function'
name of the EntryPoint if the ExactSpelling is true.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top