473,586 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(Se nder: TObject);
procedure FormShow(Sender : TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
//procedure DrawToCanvas(Ca v: Tcanvas;x,y:int eger);Stdcall;e xternal
'KwBarDll.dll';
procedure Epson_Text8d(M: Smallint;F:byte ;S:string);stdc all; external
'Epson.dll';
procedure Epson_Text(M:Sm allint;F:byte;S :string);stdcal l;external
'Epson.dll';
procedure EpsonPrnLn(S:st ring);stdcall;e xternal 'Epson.dll';
function GetDefaultPrint er:string;stdca ll;external 'Epson.dll';
procedure TForm1.Button1C lick(Sender: TObject);
var i:integer;
begin
for i:=0 to Memo1.Lines.Cou nt-1 do
begin
if RadioGroup1.Ite mIndex=0 then
Epson_Text8d(14 ,0,Memo1.Lines[i]);
if RadioGroup1.Ite mIndex=1 then
Epson_Text(18,0 ,Memo1.Lines[i]);// print procedure
if RadioGroup1.Ite mIndex=2 then
EpsonPrnLn(Memo 1.Lines[i]);
end;
end;

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

end.

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

[DllImport("Epso n.dll", EntryPoint = "Epson_Text ", CallingConventi on =
CallingConventi on.StdCall, CharSet = CharSet.Unicode , SetLastError = true,
ExactSpelling = true)]
public static extern void Epson_Text(Int1 6 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 2165
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("Epso n.dll", EntryPoint = "Epson_Text ", CallingConventi on =
CallingConventi on.StdCall, CharSet = CharSet.Unicode , SetLastError = true,
ExactSpelling = true)]
is wrong . It should be
[DllImport("Epso n.dll", EntryPoint = "Epson_Text ", CallingConventi on =
CallingConventi on.StdCall, CharSet = CharSet.Ansi, SetLastError = true,
ExactSpelling = false)]
"ExactSpell ing = 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
6938
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 programming languages still being designed with C's syntax? These questions drive me insane. Every waking minute...
0
2714
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 is able to display the Chinese & Thai font on the phone menu's by using the pre-set system language. Using the same code in java J2ME game to display...
9
4853
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 can I print out this content to printer easily? Thanks! James
1
2587
by: franchdream | last post by:
IntPtr pBytes; Int32 dwCount; dwCount = szString.Length; pBytes = Marshal.StringToCoTaskMemAnsi(szString); string yang = Marshal.PtrToStringAnsi(pBytes); ........ WritePrinter(hPrinter, pBytes, dwCount, ref dwWritten); I want to know why I can't print Chinese used this method. I can only print the ASCII of these Chinese.
15
1372
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 "16" (at least on python 2.4.4 (Linux) and 2.5 (Wine).
2
5377
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');. I save the source file as UTF-8. I get the error: Warning: fopen(中国.php) : failed to open stream: No such file or directory in...
1
2423
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" . Anyone encounter this problem ? For the javascript coding function createRequest() {
10
7801
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: Delphi: TDCP_rijndael Component (DCPcrypt Cryptographic Component Library v2) from cityinthesky (www.cityinthesky.com) ASP.NET : Standard library...
2
6696
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 of Chinese characters, on my machine I installed language pack and currently set language as Chinese PRC but still it's not working. Option...
0
7912
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7959
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8216
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6614
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.