user32.dll api and keyboard layout

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dan

    #1

    user32.dll api and keyboard layout

    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 programmaticall y 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("user 32.dll")]
    private static extern long LoadKeyboardLay out(
    string pwszKLID, // input locale identifier
    uint Flags // input locale identifier options
    );
    [DllImport("user 32.dll")]
    private static extern long GetKeyboardLayo utName(
    System.Text.Str ingBuilder pwszKLID //[out] string that receives the name
    of the locale identifier
    );

    sample call:

    LoadKeyboardLay out("00000409", KLF_ACTIVATE);


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: user32.dll api and keyboard layout

    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]
    - mvp@spam.guard. caspershouse.co m

    "Dan" <dfusi@hotmail. com> wrote in message
    news:43c2a6e6$0 $335$5fc30a8@ne ws.tiscali.it.. .[color=blue]
    > 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 programmaticall y 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("user 32.dll")]
    > private static extern long LoadKeyboardLay out(
    > string pwszKLID, // input locale identifier
    > uint Flags // input locale identifier options
    > );
    > [DllImport("user 32.dll")]
    > private static extern long GetKeyboardLayo utName(
    > System.Text.Str ingBuilder pwszKLID //[out] string that receives the
    > name of the locale identifier
    > );
    >
    > sample call:
    >
    > LoadKeyboardLay out("00000409", KLF_ACTIVATE);
    >[/color]


    Comment

    • Willy Denoyette [MVP]

      #3
      Re: user32.dll api and keyboard layout

      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" <dfusi@hotmail. com> wrote in message
      news:43c2a6e6$0 $335$5fc30a8@ne ws.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 programmaticall y 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("user 32.dll")]
      | private static extern long LoadKeyboardLay out(
      | string pwszKLID, // input locale identifier
      | uint Flags // input locale identifier options
      | );
      | [DllImport("user 32.dll")]
      | private static extern long GetKeyboardLayo utName(
      | System.Text.Str ingBuilder pwszKLID //[out] string that receives the
      name
      | of the locale identifier
      | );
      |
      | sample call:
      |
      | LoadKeyboardLay out("00000409", KLF_ACTIVATE);
      |
      |


      Comment

      Working...