Lateloading of x86 / x64 bit DLL keyboard files and init defines
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Thread: Lateloading of x86 / x64 bit DLL keyboard files and init defines

  1. #1
    Join Date
    May 2000
    Location
    Porsgrunn, Telemark in Norway!
    Posts
    292

    Lateloading of x86 / x64 bit DLL keyboard files and init defines

    Hi

    I currently have an issue with the init of lateloading DLLs (keyboard files) that is compiled either with x86 or x64. The app is a simple C++ MFC application (32-bit)

    First, here is a summary of the lateloading of the keyboard files:
    Code:
    kbdLibrary = LoadLibrary(L"C:\\windows\\system32\\KBDUS.DLL");
    pKbdLayerDescriptor = (KbdLayerDescriptor)GetProcAddress(kbdLibrary, "KbdLayerDescriptor");
    PKBDTABLES pKbd = pKbdLayerDescriptor();
    The pKbdLayerDescriptor() fills an struct of: *KBD_LONG_POINTER PKBDTABLES;

    The definition of KBD_LONG_POINTER PKBDTABLES (from Microsofts kbd.h):
    Code:
    #if defined(BUILD_WOW6432)
        #define KBD_LONG_POINTER __ptr64
     #else
         #define KBD_LONG_POINTER
     #endif
    Now here is the mainissue, program is compiled with x86 but executed on a x64-system.
    * All keyboard files in %windir%\system32\ is x64 DLLs files and failes (because BUILD_WOW6432 doesn't exist)
    * Struct is partly filled, possible corrupt

    Same app running on a x86-system:
    * All keyboard files are loaded ok, because the keyboardfiles in %windir%\system32\ is x86.

    Taking a x86 KBDxx.DLL to a x64-system:
    * Loaded ok, without a problem

    Forcing the KBD_LONG_POINTER as __ptr64 on a x32-system:
    * All keyboard files fails to load (as expected)

    Forcing the KBD_LONG_POINTER as __ptr64 on a x64-system:
    * All keyboard files are loaded ok (as expected).

    Any tips on how to get this to work, without creating a kbd64.h containing the "same" defines?
    Is it possible to "redefine" during runtime?
    ==========================
    Lars Werner aka Large
    http://lars.werner.no/
    ==========================

  2. #2
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,475

    Re: Lateloading of x86 / x64 bit DLL keyboard files and init defines

    I guess you should either define BUILD_WOW6432 by compilation or supply 32-bit dll together with your App.
    Victor Nijegorodov

  3. #3
    Join Date
    May 2000
    Location
    Porsgrunn, Telemark in Norway!
    Posts
    292

    Re: Lateloading of x86 / x64 bit DLL keyboard files and init defines

    VictorN:
    That isn't really an option, since I want to use the already installed keyboard layouts that is available in the %windir%\system32\ directory.

    But it would "solve" the problem if I distributed the dlls with the installation.

    Not any other nifty solutions though?

    I guess I'll have to create a kbd64.h that manage the structs for x64 bit and do a x86/x64 check on the dll-files before loading.
    ==========================
    Lars Werner aka Large
    http://lars.werner.no/
    ==========================

  4. #4
    Join Date
    Jul 2012
    Posts
    4

    Re: Lateloading of x86 / x64 bit DLL keyboard files and init defines

    Quote Originally Posted by Large View Post
    VictorN:
    That isn't really an option, since I want to use the already installed keyboard layouts that is available in the %windir%\system32\ directory.

    But it would "solve" the problem if I distributed the dlls with the installation.

    Not any other nifty solutions though?

    I guess I'll have to create a kbd64.h that manage the structs for x64 bit and do a x86/x64 check on the dll-files before loading.
    Where you ever able to resolve this issue? I am having the exact same problem.

  5. #5
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,026

    Re: Lateloading of x86 / x64 bit DLL keyboard files and init defines

    Code:
    kbdLibrary = LoadLibrary(L"C:\\windows\\system32\\KBDUS.DLL");
    I wonder, is this a problem to detect running on x64? In case it is x64, the path to load from must be just C:\Windows\SysWOW64 instead of system32. That's it.
    Best regards,
    Igor

  6. #6
    Join Date
    Jul 2012
    Posts
    4

    Re: Lateloading of x86 / x64 bit DLL keyboard files and init defines

    Quote Originally Posted by Igor Vartanov View Post
    I wonder, is this a problem to detect running on x64? In case it is x64, the path to load from must be just C:\Windows\SysWOW64 instead of system32. That's it.
    That's what you would think to be the case but from what I have gathered SysWOW64/KBDUS.DLL is not purely 32 bit. I think my problem is that mingw __ptr64 doesnt do what it should be doing so I am going to test with msvc.

  7. #7
    Join Date
    May 2000
    Location
    Porsgrunn, Telemark in Norway!
    Posts
    292

    Re: Lateloading of x86 / x64 bit DLL keyboard files and init defines

    kwhat:
    I used the solution described from Igor by loading x86-dlls on a 64bit-system from the %windir%\SysWOW64 directory.
    On x86-systems I load them from the %windir%\system32.
    I seems to work on every layout, just not KBDKOR.dll nor KBDJPN.DLL.
    ==========================
    Lars Werner aka Large
    http://lars.werner.no/
    ==========================

  8. #8
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,026

    Re: Lateloading of x86 / x64 bit DLL keyboard files and init defines

    Quote Originally Posted by kwhat View Post
    from what I have gathered SysWOW64/KBDUS.DLL is not purely 32 bit.
    That's something new to me. Module architecture cannot be not purely 32 bit or a little bit 64 bit. It's either x86 or x64.

    C:\Windows\SysWOW64\KBDUS.DLL
    Code:
    Microsoft (R) COFF/PE Dumper Version 10.00.40219.01
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
    
    Dump of file KBDUS.DLL
    
    PE signature found
    
    File Type: DLL
    
    FILE HEADER VALUES
                 14C machine (x86)
                   3 number of sections
            4A5BDBD2 time date stamp Tue Jul 14 05:13:54 2009
                   0 file pointer to symbol table
                   0 number of symbols
                  E0 size of optional header
                2102 characteristics
                       Executable
                       32 bit word machine
                       DLL
    
    OPTIONAL HEADER VALUES
                 10B magic # (PE32)
                9.00 linker version
                   0 size of code
                1400 size of initialized data
                   0 size of uninitialized data
                   0 entry point
                1000 base of code
                1000 base of data
            5FFE0000 image base (5FFE0000 to 5FFE3FFF)
                1000 section alignment
                 200 file alignment
                6.01 operating system version
                6.01 image version
                6.01 subsystem version
                   0 Win32 version
                4000 size of image
                 400 size of headers
                C01F checksum
                   1 subsystem (Native)
                 540 DLL characteristics
                       Dynamic base
                       NX compatible
                       No structured exception handler
               40000 size of stack reserve
                1000 size of stack commit
              100000 size of heap reserve
                1000 size of heap commit
                   0 loader flags
                  10 number of directories
                1C90 [      4F] RVA [size] of Export Directory
                   0 [       0] RVA [size] of Import Directory
                2000 [     400] RVA [size] of Resource Directory
                   0 [       0] RVA [size] of Exception Directory
                   0 [       0] RVA [size] of Certificates Directory
                3000 [      B4] RVA [size] of Base Relocation Directory
                1CE0 [      1C] RVA [size] of Debug Directory
                   0 [       0] RVA [size] of Architecture Directory
                   0 [       0] RVA [size] of Global Pointer Directory
                   0 [       0] RVA [size] of Thread Storage Directory
                   0 [       0] RVA [size] of Load Configuration Directory
                   0 [       0] RVA [size] of Bound Import Directory
                   0 [       0] RVA [size] of Import Address Table Directory
                   0 [       0] RVA [size] of Delay Import Directory
                   0 [       0] RVA [size] of COM Descriptor Directory
                   0 [       0] RVA [size] of Reserved Directory
    
    
    SECTION HEADER #1
       .data name
         D2B virtual size
        1000 virtual address (5FFE1000 to 5FFE1D2A)
         E00 size of raw data
         400 file pointer to raw data (00000400 to 000011FF)
           0 file pointer to relocation table
           0 file pointer to line numbers
           0 number of relocations
           0 number of line numbers
    60000040 flags
             Initialized Data
             Execute Read
    
    RAW DATA #1
      5FFE1000: FF 00 1B 00 31 00 32 00 33 00 34 00 35 00 36 00  ...1.2.3.4.5.6.
      5FFE1010: 37 00 38 00 39 00 30 00 BD 00 BB 00 08 00 09 00  7.8.9.0.......
      5FFE1020: 51 00 57 00 45 00 52 00 54 00 59 00 55 00 49 00  Q.W.E.R.T.Y.U.I.
      5FFE1030: 4F 00 50 00 DB 00 DD 00 0D 00 A2 00 41 00 53 00  O.P......A.S.
    . . .
    C:\Windows\system32\KBDUS.DLL
    Code:
    Microsoft (R) COFF/PE Dumper Version 10.00.40219.01
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
    
    Dump of file KBDUS.DLL
    
    PE signature found
    
    File Type: DLL
    
    FILE HEADER VALUES
                8664 machine (x64)
                   3 number of sections
            4A5BDFCE time date stamp Tue Jul 14 05:30:54 2009
                   0 file pointer to symbol table
                   0 number of symbols
                  F0 size of optional header
                2022 characteristics
                       Executable
                       Application can handle large (>2GB) addresses
                       DLL
    
    OPTIONAL HEADER VALUES
                 20B magic # (PE32+)
                9.00 linker version
                   0 size of code
                1600 size of initialized data
                   0 size of uninitialized data
                   0 entry point
                1000 base of code
         5FFFFFF0000 image base (000005FFFFFF0000 to 000005FFFFFF3FFF)
                1000 section alignment
                 200 file alignment
                6.01 operating system version
                6.01 image version
                6.01 subsystem version
                   0 Win32 version
                4000 size of image
                 400 size of headers
               100BD checksum
                   1 subsystem (Native)
                 140 DLL characteristics
                       Dynamic base
                       NX compatible
               40000 size of stack reserve
                1000 size of stack commit
              100000 size of heap reserve
                1000 size of heap commit
                   0 loader flags
                  10 number of directories
                1E20 [      4F] RVA [size] of Export Directory
                   0 [       0] RVA [size] of Import Directory
                2000 [     400] RVA [size] of Resource Directory
                   0 [       0] RVA [size] of Exception Directory
                   0 [       0] RVA [size] of Certificates Directory
                3000 [      B4] RVA [size] of Base Relocation Directory
                1E70 [      1C] RVA [size] of Debug Directory
                   0 [       0] RVA [size] of Architecture Directory
                   0 [       0] RVA [size] of Global Pointer Directory
                   0 [       0] RVA [size] of Thread Storage Directory
                   0 [       0] RVA [size] of Load Configuration Directory
                   0 [       0] RVA [size] of Bound Import Directory
                   0 [       0] RVA [size] of Import Address Table Directory
                   0 [       0] RVA [size] of Delay Import Directory
                   0 [       0] RVA [size] of COM Descriptor Directory
                   0 [       0] RVA [size] of Reserved Directory
    
    
    SECTION HEADER #1
       .data name
         EC0 virtual size
        1000 virtual address (000005FFFFFF1000 to 000005FFFFFF1EBF)
        1000 size of raw data
         400 file pointer to raw data (00000400 to 000013FF)
           0 file pointer to relocation table
           0 file pointer to line numbers
           0 number of relocations
           0 number of line numbers
    60000040 flags
             Initialized Data
             Execute Read
    
    RAW DATA #1
      000005FFFFFF1000: 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00  ................
      000005FFFFFF1010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
      000005FFFFFF1020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
      000005FFFFFF1030: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
      000005FFFFFF1040: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
    . . .
    Last edited by Igor Vartanov; August 1st, 2012 at 03:37 AM.
    Best regards,
    Igor

  9. #9
    Join Date
    Jul 2012
    Posts
    4

    Lightbulb Re: Lateloading of x86 / x64 bit DLL keyboard files and init defines

    Quote Originally Posted by Large View Post
    kwhat:
    I used the solution described from Igor by loading x86-dlls on a 64bit-system from the %windir%\SysWOW64 directory.
    On x86-systems I load them from the %windir%\system32.
    I seems to work on every layout, just not KBDKOR.dll nor KBDJPN.DLL.
    Thanks for the reply. After spending most of the day trying to wrap my brain around why this wasn't working for me I finally figured out what the problem was. As it turns out GCC and subsequently MinGW do not support __ptr64 and simply ignore it. This turns out to be a problem when working with Wow64 libraries as they appear to be 64-bit aligned 32-bit pointers. I have been experimenting with __attribute__((mode(DI))) and __attribute__ ((aligned(8))). Both show promise however I cant seem to get mode(DI) working directly with pointers. Hopefully this will save someone a huge headache down the line as there is almost no information on the topic.

  10. #10
    Join Date
    May 2000
    Location
    Porsgrunn, Telemark in Norway!
    Posts
    292

    Re: Lateloading of x86 / x64 bit DLL keyboard files and init defines

    As a result of handling DLL-files between x86 and x64, I made a wrapper:
    http://www.codeproject.com/Articles/...riptor-in-32-6

    This should handle the problems described in this thread.
    ==========================
    Lars Werner aka Large
    http://lars.werner.no/
    ==========================

  11. #11
    Join Date
    Jul 2012
    Posts
    4

    Re: Lateloading of x86 / x64 bit DLL keyboard files and init defines

    I solved this issue very differently due to the GCC compatibility requirement of my project. Its not pretty, but it uses the same binary code for both native 32-bit and wow64 environments. I haven't tested it with the MSVC compiler, but there shouldn't be any reason it wouldn't work.

    Source code is available here: http://code.google.com/p/jnativehook...nicodeHelper.c

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center