Click here to Skip to main content
15,885,767 members
Articles / Desktop Programming / MFC

Loading keyboard layout (KbdLayerDescriptor) in 32/64-bit environment

Rate me:
Please Sign up or sign in to vote.
4.75/5 (12 votes)
13 Aug 2012Ms-PL3 min read 44.5K   2.2K   17  
When loading a keyboard dll as a 32-bit application on a 64-bit system, the keyboard-dll-files does not work as expected, this class fixes that problem
#pragma  once
#include "kbd.h"
#include "kbd64.h"

//Loaddefs for a 32/64-bit handle of keyboard-loading
typedef PKBDTABLES(* KbdLayerDescriptor)(VOID);
typedef PKBDTABLES64(* KbdLayerDescriptor64)(VOID);
typedef PVOID(*PFN_KBDLAYERDESCRIPTOR)(VOID);

class CKLL
{
public:
	CKLL(void);
	~CKLL(void);

	//Public functions to return info regarding the keyboard-dll loaded
	BOOL	LoadDLL(CString sKeyboardDll);
	USHORT	GetVKCount();
	CString	GetChar(USHORT iVK);
	CString GetSC(USHORT iVK);

	//Return TRUE if x64, false if not...
	BOOL	Is64BitWindows();

private:
	//Our loaded DLL
	HMODULE hHandle;
	void	UnloadDLL();

	//The actual DLL-function that init and fill the array
	PFN_KBDLAYERDESCRIPTOR pfnKbdLayerDescriptor;

	//32-bit variables
	PKBDTABLES KbdTables;
	void Fill32();

	//64-bit variables
	PKBDTABLES64 KbdTables64;
	void Fill64();

	//////////////////////////////////////////////////////////////////////////
	//Structs to handle all keys assigned to a VK
	struct VK_STRUCT
	{
		USHORT nVK;
		CUIntArray aSC;
		CStringArray aChar;
	};

	//Variable to keep track of VKs
	CPtrArray m_vkarray;

	//Function to add / clear new VK-char
	void AddVKChar(USHORT nVK, CString wChar);	//Returns the characters for the available VK
	void AddVKSC(USHORT nVK, USHORT nSC);		//Returns the scan code for the available VK
	int VKExist(USHORT nVK);					//Returns the number in the array for the VK
	void ClearVKChar();							//Clears the table
};

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
Engineer A/S Norske Shell (Dutch Shell)
Norway Norway
----------------------------------
Visit http://lars.werner.no/ for my blog!
----------------------------------
Retired programmer, Norway never had the jobs I wanted Smile | :)

Comments and Discussions