This forum is in archive mode. You will not be able to post new content.

Author Topic: [c++]Keybord layout(Need help invalid conversion from `char*' to `BYTE*)  (Read 1907 times)

0 Members and 1 Guest are viewing this topic.

Offline Stilius

  • NULL
  • Posts: 3
  • Cookies: 0
    • View Profile
Hy I need some help on Keyboard Layout:

With this function I load keyboard layout

Code: [Select]
HINSTANCE loadKeyboardLayout()
{
PKBDTABLES pKbd;
HINSTANCE kbdLibrary;
KbdLayerDescriptor pKbdLayerDescriptor = NULL;

char layoutFile[MAX_PATH]; //char
if(getKeyboardLayoutFile(layoutFile, sizeof(layoutFile)) == -1)
return NULL;

char systemDirectory[MAX_PATH];
GetSystemDirectory(systemDirectory, MAX_PATH);

char kbdLayoutFilePath[MAX_PATH];
snprintf(kbdLayoutFilePath, MAX_PATH, "%s\\%s", systemDirectory, layoutFile);

kbdLibrary = LoadLibrary(kbdLayoutFilePath);

pKbdLayerDescriptor = (KbdLayerDescriptor)GetProcAddress(kbdLibrary, "KbdLayerDescriptor");

if(pKbdLayerDescriptor != NULL)
pKbd = pKbdLayerDescriptor();
else
return NULL;

int i = 0;
do
{
INIT_PVK_TO_WCHARS(i, 1)
INIT_PVK_TO_WCHARS(i, 2)
INIT_PVK_TO_WCHARS(i, 3)
INIT_PVK_TO_WCHARS(i, 4)
INIT_PVK_TO_WCHARS(i, 5)
INIT_PVK_TO_WCHARS(i, 6)
INIT_PVK_TO_WCHARS(i, 7)
INIT_PVK_TO_WCHARS(i, 8)
INIT_PVK_TO_WCHARS(i, 9)
INIT_PVK_TO_WCHARS(i, 10)
i++;
}
while(pKbd->pVkToWcharTable[i].cbSize != 0);

pCharModifiers = pKbd->pCharModifiers;
pDeadKey = pKbd->pDeadKey;

return kbdLibrary;
}

and there I get layout keyboard:

Code: [Select]
int getKeyboardLayoutFile(char* layoutFile, DWORD bufferSize)
{
HKEY hKey;
DWORD varType = REG_SZ;

char kbdName[KL_NAMELENGTH];
GetKeyboardLayoutName(kbdName);

char kbdKeyPath[51 + KL_NAMELENGTH];
snprintf(kbdKeyPath, 51 + KL_NAMELENGTH,
"SYSTEM\\CurrentControlSet\\Control\\Keyboard Layouts\\%s", kbdName);

if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, (LPCTSTR)kbdKeyPath, 0, KEY_QUERY_VALUE, &hKey) =! ERROR_SUCCESS)
        return -1;

if (RegQueryValueEx(hKey, "Layout File", NULL, &varType, layoutFile, &bufferSize) != ERROR_SUCCESS) //jeigu ne ERROR_SUCCESS
    return -1; //this is error

RegCloseKey(hKey);

end gets 2 errors:
Code: [Select]
error: invalid conversion from 'char*' to 'BYTE*'|
error:   initializing argument 5 of 'LONG RegQueryValueExA(HKEY__*, const CHAR*, DWORD*, DWORD*, BYTE*, DWORD*)'|

on..
Code: [Select]
if (RegQueryValueEx(hKey, "Layout File", NULL, &varType, layoutFile, &bufferSize) != ERROR_SUCCESS) //jeigu ne ERROR_SUCCESS
    return -1; //this is error

How I understant conversion problem is on layoutFile variable. In first code how I can see it is char tipe. Any mind how to solve this error?








Offline Xires

  • Noob Eater
  • Administrator
  • Knight
  • *
  • Posts: 379
  • Cookies: 149
    • View Profile
    • Feed The Trolls - Xires
Try looking up C++ casting(things like 'static_cast', 'dynamic_cast', 'reinterpret_cast', etc.).  Also check WinAPI's definition of the BOOL type.  A 'char' is probably inappropriate for a reason.

Further help is available if you get stuck.  Good luck && have fun.
-Xires

 



Want to be here? Contact Ande, Factionwars or Kulverstukas on the forum or at IRC.