471,317 Members | 1,979 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,317 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 11819
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

30 posts views Thread by ajsiegel | last post: by
9 posts views Thread by skearney | last post: by
13 posts views Thread by Steve Jorgensen | last post: by
2 posts views Thread by Santy | last post: by
1 post views Thread by Aftab Alam | last post: by
3 posts views Thread by nhmark64 | last post: by
4 posts views Thread by Melson | last post: by
reply views Thread by rosydwin | last post: by

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.