Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / November 2006

Tip: Looking for answers? Try searching our database.

Print Chinese in Delphi successful but in C# failed.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
franchdream - 12 Nov 2006 14:22 GMT
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_______


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.