473,226 Members | 1,405 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,226 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 12076
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...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.