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

user32.dll api and keyboard layout

Dan
Sorry if this post may sound a bit off-topic, but I could not find a
specialized newsgroup. I have created a dotnet 2.0 library containing some
user controls and written in C#. One of the controls (an extension of
RichTextControl) needs to programmatically change the keyboard layout, so it
imports some user32.dll API functions (see below). This control works fine
in Windows XP, but it crashes under Win64 systems when trying to call the
user32 API. How can I change the code so that it runs under Win64 or where
could I find more information about porting API-dependent dotnet code under
this OS?

Thank you in advance!

Code snippets:

// API DECLARATIONS
private const uint KLF_ACTIVATE = 1; // activate the layout
private const int KL_NAMELENGTH = 9; // length of the keyboard buffer

[DllImport("user32.dll")]
private static extern long LoadKeyboardLayout(
string pwszKLID, // input locale identifier
uint Flags // input locale identifier options
);
[DllImport("user32.dll")]
private static extern long GetKeyboardLayoutName(
System.Text.StringBuilder pwszKLID //[out] string that receives the name
of the locale identifier
);

sample call:

LoadKeyboardLayout("00000409", KLF_ACTIVATE);
Jan 9 '06 #1
2 12091
Dan,

What is the crash that you get? The declarations that you have given
don't look like they should give you a problem.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Dan" <df***@hotmail.com> wrote in message
news:43********************@news.tiscali.it...
Sorry if this post may sound a bit off-topic, but I could not find a
specialized newsgroup. I have created a dotnet 2.0 library containing some
user controls and written in C#. One of the controls (an extension of
RichTextControl) needs to programmatically change the keyboard layout, so
it imports some user32.dll API functions (see below). This control works
fine in Windows XP, but it crashes under Win64 systems when trying to call
the user32 API. How can I change the code so that it runs under Win64 or
where could I find more information about porting API-dependent dotnet
code under this OS?

Thank you in advance!

Code snippets:

// API DECLARATIONS
private const uint KLF_ACTIVATE = 1; // activate the layout
private const int KL_NAMELENGTH = 9; // length of the keyboard buffer

[DllImport("user32.dll")]
private static extern long LoadKeyboardLayout(
string pwszKLID, // input locale identifier
uint Flags // input locale identifier options
);
[DllImport("user32.dll")]
private static extern long GetKeyboardLayoutName(
System.Text.StringBuilder pwszKLID //[out] string that receives the
name of the locale identifier
);

sample call:

LoadKeyboardLayout("00000409", KLF_ACTIVATE);

Jan 9 '06 #2
The retuns from the API's are not longs! One is an IntPtr (a Handle or void*
in Win32) the other a bool.
IntPtr's are plaform dependent values!

Check the documentation for the API's.

Willy.

"Dan" <df***@hotmail.com> wrote in message
news:43********************@news.tiscali.it...
| Sorry if this post may sound a bit off-topic, but I could not find a
| specialized newsgroup. I have created a dotnet 2.0 library containing some
| user controls and written in C#. One of the controls (an extension of
| RichTextControl) needs to programmatically change the keyboard layout, so
it
| imports some user32.dll API functions (see below). This control works fine
| in Windows XP, but it crashes under Win64 systems when trying to call the
| user32 API. How can I change the code so that it runs under Win64 or where
| could I find more information about porting API-dependent dotnet code
under
| this OS?
|
| Thank you in advance!
|
| Code snippets:
|
| // API DECLARATIONS
| private const uint KLF_ACTIVATE = 1; // activate the layout
| private const int KL_NAMELENGTH = 9; // length of the keyboard buffer
|
| [DllImport("user32.dll")]
| private static extern long LoadKeyboardLayout(
| string pwszKLID, // input locale identifier
| uint Flags // input locale identifier options
| );
| [DllImport("user32.dll")]
| private static extern long GetKeyboardLayoutName(
| System.Text.StringBuilder pwszKLID //[out] string that receives the
name
| of the locale identifier
| );
|
| sample call:
|
| LoadKeyboardLayout("00000409", KLF_ACTIVATE);
|
|
Jan 9 '06 #3

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

Similar topics

30
by: ajsiegel | last post by:
Arthur wrote: >> And either intuitively, or consciously, he is doing something that >> offsets it from something truly intergrated into the core of the >> language. By breakling all of his own...
9
by: skearney | last post by:
When I was in boy scouts, as part of learning Morse code, I was told that the inventor of the typewriter originally put the letter 'e' under the left middle finger, just below its present position....
13
by: Steve Jorgensen | last post by:
Well, it seems that Microsoft, or whatever powers that be have decided it's time for us to have yet another standard keyboard layout change. I think I see that the point of this one was to reduce...
2
by: Rudi | last post by:
Hello all, posting my question in this newsgroup is about the last alternative I can think of to resolve my problem. The standard keyboard layout in the office is AZERTY. Still, my access xp...
2
by: Santy | last post by:
Hi! Suppose I detected, using DInput, the 1 key is pressed. I wanna get the shift+1 symbol on the current culture-keyboard.... For example.... In my spanish keyboard, shift+1 yields a "!". This...
1
by: Aftab Alam | last post by:
Hello All I want to change the keyboard layout dynaically, ie if a use focuses on my application the keyboard layout gets set to Arabic and if on any other application it should be english ?? How...
3
by: nhmark64 | last post by:
Hi, Sometimes when I am cutting and pasting it looks like the keyboard layout changes; for instance ',' and 'w' are interchanged. Is there a better way to fix this problem than exiting then...
4
by: Melson | last post by:
Hi Can anyone help. I would like to replace the keys on the PC keyboard. For example, when I press Q button it displays A on the screen in any programs (MS Words, Note, Lotus....). And also when...
3
tpgames
by: tpgames | last post by:
I'm looking for a program or command line or anything that would allow me to have more than the maximum 4 keyboard layout language groups that keyboard preferences in Ubuntu restricts me too. I can...
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: 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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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...
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
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...
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,...

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.