473,654 Members | 3,098 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.PostMessa ge(puttyHandle, 0x0102, ch, 0);
}
}

PostMessage is defined in Win32 namespace
0x0102 is WM_CHAR

[DllImport("User 32.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 5759
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.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
Jon Skeet <sk***@pobox.co m> 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.co m>
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.co m>
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.co m> 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****@trigemin al.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
11874
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 to, but because its for example read from _winreg which returns unicode. You do an os.listdir(directory). Note that all filenames returned are now unicode. (Change introduced I believe in 2.3).
8
2549
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) Now I don't think either string is unicode, but I'm working with win32api so it might be... :) The point is: I know all values will fit in a particular code page (iso-8859-2), so how do I change the 'ascii' codec in the above error into something...
4
2846
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 server. On one of our mySQL databases, we have a table of users. One of the fields used to store passwords we have as type "BLOG" and we use the ENCODE/DECODE to encrypt passwords. Now, when we do a select of a row from that table, because the
3
2453
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 Name\...". For a wxPython application I'm working on, this has actually caused me to run into what appears to be Python's pathname length limit for opening files. (247 chars on Win) Yes, I can hear people saying "yipes!" but this stuff does happen...
0
986
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 DB an error occurs when data has accents. I suppose that this is due to the terminal doesn´t insert data in Unicpde format, but I don´t know how to do to insert data in correct format.
3
2898
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
8262
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. -Thanks
0
9789
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 upgrades against these two db's. The "refresh" needs to be completed at least once a day, sometimes 4-5 times a day. I need the quickest way of doing this task. I have extremely limited knowledge on scripting. What I need is something that I can just...
3
5972
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 need to connect on port 3333 which opens port 2222 for 60secs. (obv I just made those ports up) I wanted to continue to use putty under windows to connect to my
0
8375
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8290
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8707
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8482
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8593
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7306
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6161
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2714
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
2
1593
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.