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[i]);
if RadioGroup1.ItemIndex=1 then
Epson_Text(18,0,Memo1.Lines[i]);// print procedure
if RadioGroup1.ItemIndex=2 then
EpsonPrnLn(Memo1.Lines[i]);
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!
franchdream - 12 Nov 2006 19:28 GMT
I have resolved it.
Merlin - 12 Nov 2006 20:39 GMT
> 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 :-)

Signature
//\/\\3rL1n_______
franchdream - 13 Nov 2006 01:09 GMT
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.
Merlin - 13 Nov 2006 21:23 GMT
thanks for you message.

Signature
//\/\\3rL1n_______