473,408 Members | 1,746 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Print Chinese in Delphi successful but in C# failed.

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;ext ernal
'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!


Nov 12 '06 #1
4 2155
I have resolved it.
Nov 12 '06 #2
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 :-)

--

//\/\\3rL1n_______
Nov 12 '06 #3
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.
Nov 13 '06 #4
thanks for you message.
--

//\/\\3rL1n_______
Nov 13 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

177
by: C# Learner | last post by:
Why is C syntax so uneasy on the eye? In its day, was it _really_ designed by snobby programmers to scare away potential "n00bs"? If so, and after 50+ years of programming research, why are...
0
by: slchslch | last post by:
Hi all, I have search through multiple forum to look for the respective solution for this problem but still i do not find any solution to this problem. I have Samsung SGH-D520 on hand which...
9
by: James Wong | last post by:
Hi, I use the RichTextBox in my program. It will use different language in this RichTextBox (chinese and english characters), and it set the "DualFont" and use different fonts. By the way, how...
1
by: franchdream | last post by:
IntPtr pBytes; Int32 dwCount; dwCount = szString.Length; pBytes = Marshal.StringToCoTaskMemAnsi(szString); string yang = Marshal.PtrToStringAnsi(pBytes); ........ WritePrinter(hPrinter, pBytes,...
15
by: Jim B. Wilson | last post by:
Am I nuts? Or only profoundly confused? I expected the this little script to print "0": class foo(int): def __init__(self, value): self = value & 0xF print foo(0x10) Instead, it prints...
2
by: Taras_96 | last post by:
Hi everyone, Firstly, I would like to know if you can open chinese filenames under win2000 using PHP 5.0? I have a file named 中国.php, and try to open it using fopen(‘中国.php','r');....
1
by: stepby | last post by:
Hi All, I have use the ajax with the server side language ASP. I find the when passing the parameter with the chinese character, the chinese character cannot show orderly and become "wrong code" ....
10
by: Iwan Budihalim | last post by:
Who can help? I'm trying to implement an encrypted (plain text) communication between a Delphi application and an ASP.NET. My choice is AES/rijndael-128. For both sides, i use standard modules: ...
2
by: Flying Kite | last post by:
Hi All, I want to know how to print chinese characters on Zebra Printer, following code working fine with English string, but it's not working for Chinese string. It shows ASCII characters instead...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.