473,382 Members | 1,336 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,382 software developers and data experts.

How to transfer Unicode from C# through Win32API to Putty?


I made a program than can send text to Putty (A telnet/ssh client)
http://www.chiark.greenend.org.uk/~sgtatham/putty/
And I discovered that Unicode characters doesn't reach it

I'm using PostMessage with WM_CHAR, the text source is taken straight
from a textbox and sent character by character to putty (putty handle is
previously found with FindWindow)

private void sendText(string text)
{
foreach(char ch in text)
{
Win32.PostMessage(puttyHandle, 0x0102, ch, 0);
}
}

PostMessage is defined in Win32 namespace
0x0102 is WM_CHAR

[DllImport("User32.Dll")]
public static extern bool PostMessage(int hWnd, int Msg, int WPARAM, int
LPARAM);

ch is unicode, while it never reaches putty as one?
Am I doing something wrong?

(There is a possibility that putty doesn't treat WM_CHAR properly. I've
checked the source code for it, and found it converts wPARAM to unsigned
char)
--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #1
5 5742
Morten Wennevik <mo************@hotmail.com> wrote:

<snip>
ch is unicode, while it never reaches putty as one?
Am I doing something wrong?

(There is a possibility that putty doesn't treat WM_CHAR properly. I've
checked the source code for it, and found it converts wPARAM to unsigned
char)


There's also the possibility that whatever connection you've got
doesn't really support Unicode.

I'll forward your post to the author of Putty (a friend of mine from
university) and let you know the results.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
Jon Skeet <sk***@pobox.com> wrote:
(There is a possibility that putty doesn't treat WM_CHAR properly. I've
checked the source code for it, and found it converts wPARAM to unsigned
char)


Thinking about it, of course unsigned char in C is just a single byte,
so that indeed won't get the unicode values. The question is whether or
not Putty is expecting anyone to be posting unicode values to it in the
first place.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #3
Well, I'm using PostMessage, and if I understand it correctly, .net
framework automatically translates it to PostMessageW if it spots a unicode
character.

Also, I know putty receives something, but always a single ascii character
(I suspect whatever first or last byte of the unicode character).

As you mentioned, I suspect it is because it's cast into unsigned char.
I got the source code, and if I manage to compile it properly under Visual
Studio .Net I'll play around with the code to see if I can make something
work.

Thanks for your reply.

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #4
Morten Wennevik <mo************@hotmail.com> wrote:
Well, I'm using PostMessage, and if I understand it correctly, .net
framework automatically translates it to PostMessageW if it spots a unicode
character.

Also, I know putty receives something, but always a single ascii character
(I suspect whatever first or last byte of the unicode character).

As you mentioned, I suspect it is because it's cast into unsigned char.
I got the source code, and if I manage to compile it properly under Visual
Studio .Net I'll play around with the code to see if I can make something
work.

Thanks for your reply.


I've just had this from the author:

<quote>
PuTTY should be able to accept Unicode input from the keyboard, the
Windows clipboard etc, at all times. It will translate the Unicode into
whatever character set it is configured to believe the server is
speaking - so I suppose in that sense you could argue that whether it
`supported' Unicode depended on the connection configuration, although
I'd prefer to say that PuTTY supports Unicode always, and your
connection to the server might or might not be restricted to a subset
of it.

Checking the source, it appears we don't support arbitrary Unicode
coming in through WM_CHAR messages, and the reason why not is that we
believe WM_CHAR itself doesn't support it - we expect the parameter to
WM_CHAR to be in the system's default code page (typically Win1252). If
there is an extension to WM_CHAR which supports Unicode, then we
clearly ought to support it; if someone tells us about it it should be
easy enough to do so.
</quote>

So, do you have any documentation I could pass along which talks about
Unicode support in WM_CHAR messages?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #5
A few corrections and elaborations, inline....

"Jon Skeet" <sk***@pobox.com> wrote...
Morten Wennevik <mo************@hotmail.com> wrote:
Well, I'm using PostMessage, and if I understand it correctly, .net
framework automatically translates it to PostMessageW if it spots a unicode character.

This is incorrect. It uses PostMessageW depending on your pinvoke wrapper.
If you use CharSet.Auto on a NT-based platform or CharSet.Unicode ever, then
it will try to use PostMessageW.
Checking the source, it appears we don't support arbitrary Unicode
coming in through WM_CHAR messages, and the reason why not is that we
believe WM_CHAR itself doesn't support it - we expect the parameter to
WM_CHAR to be in the system's default code page (typically Win1252). If
there is an extension to WM_CHAR which supports Unicode, then we
clearly ought to support it; if someone tells us about it it should be
easy enough to do so.
This is incorrect. If the Window is a Unicode window, then it is supposed to
be expecting WM_CHAR to give it a WCHAR. If it is not a Unicode window, then
a CHAR is passed.
So, do you have any documentation I could pass along which talks about
Unicode support in WM_CHAR messages?


The WM_CHAR documentation should be clear enough, as should the windowing
system (I am looking at the source in Windows as I say this). You can have
them contact me offline at mi****@trigeminal.com if they need more info.

--
MichKa [MS]

This posting is provided "AS IS" with
no warranties, and confers no rights.

Nov 15 '05 #6

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

Similar topics

19
by: Gerson Kurz | last post by:
AAAAAAAARG I hate the way python handles unicode. Here is a nice problem for y'all to enjoy: say you have a variable thats unicode directory = u"c:\temp" Its unicode not because you want it...
8
by: Ivan Voras | last post by:
When concatenating strings (actually, a constant and a string...) i get the following error: UnicodeDecodeError: 'ascii' codec can't decode byte 0xfc in position 1: ordinal not in range(128) ...
4
by: LRW | last post by:
I'm sorry, I don't know if this is a mySQL issue, or a Putty error, or what. So if there's a better newsgroup for this question, please let me know. I'm using Putty to SSH into our remote Linux...
3
by: Kevin Ollivier | last post by:
Hi all, On Windows, it's very common to have a string of long directories in the pathname for files, like "C:\Documents and Settings\My Long User Name\My Documents\My Long Subdirectory...
0
by: OKI | last post by:
Hi. I have a PostgreSQL 7.4.3 DB in a debian box. I´ve created an Unicode DB in it. I connect to that linux from windows using PuTTY. My problem is that when I´m trying to insert data in that...
3
by: Christian Stooker | last post by:
Hi ! Yesterday I got a very interesting bug. I don't understand, why I got it, because I thinking about this function: that is safe. But I was not. The code: import sys,os
4
by: DanielGifford | last post by:
Hi- I'm trying to transfer files directly to a PDA via a Csharp program I'm writing. Does anyone know how to do this (I obviously can't use active sync). Ohh yes, I'm running Vista. ...
0
by: A3AN | last post by:
Hi. I receive a database backup on a daily basis. I then import this dump on another server which I use for software development. There is two db's being hosted on this server. We test software...
3
by: Pvt Ryan | last post by:
Background: Due to the large number of bots attempting to ssh to my server, I implemented portknocking (as the logs were just filled with crap). So to access port 2222 for ssh I would first...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.