64位Windows上的程序崩溃 [英] Programcrash on 64-Bit windows

查看:126
本文介绍了64位Windows上的程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我正在编写一个使用注册表加载键盘布局的函数.整个程序在32位Windows下工作正常,但在64位Windows上崩溃.

Hello,

I''m writing a function which load a keyboardlayout using the registry. The whole programm works fine under a 32-Bit windows but it crash on a 64-Bit windows.

// headerfile

#define TYPEDEF_VK_TO_WCHARS(n) typedef struct _VK_TO_WCHARS##n { \
  BYTE  VirtualKey; \
  BYTE  Attributes; \
  WCHAR wch[n]; \
} VK_TO_WCHARS##n, *KBD_LONG_POINTER PVK_TO_WCHARS##n;

TYPEDEF_VK_TO_WCHARS(1)
TYPEDEF_VK_TO_WCHARS(2)
TYPEDEF_VK_TO_WCHARS(3)
TYPEDEF_VK_TO_WCHARS(4)
TYPEDEF_VK_TO_WCHARS(5)
TYPEDEF_VK_TO_WCHARS(6)
TYPEDEF_VK_TO_WCHARS(7)
TYPEDEF_VK_TO_WCHARS(8)
TYPEDEF_VK_TO_WCHARS(9)
TYPEDEF_VK_TO_WCHARS(10)

typedef struct _VK_TO_WCHAR_TABLE {
  PVK_TO_WCHARS1 pVkToWchars;
  BYTE           nModifications;
  BYTE           cbSize;
} VK_TO_WCHAR_TABLE, *KBD_LONG_POINTER PVK_TO_WCHAR_TABLE;

#define INIT_PVK_TO_WCHARS(i, n) \
if((pKbd->pVkToWcharTable[i].cbSize - 2) / 2 == n) \
  pVkToWchars##n = (PVK_TO_WCHARS##n)pKbd->pVkToWcharTable[i].pVkToWchars; \

  
// sourcefile
HINSTANCE loadKeyboardLayout() {
  PKBDTABLES pKbd;
  HINSTANCE kbdLibrary;
  KbdLayerDescriptor pKbdLayerDescriptor = NULL;

  char layoutFile[MAX_PATH];

  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) // crash at this line on an 64-Bit windows
    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);
  return kbdLibrary;
}

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, (LPBYTE) layoutFile,
                      &bufferSize) != ERROR_SUCCESS) return -1;

  RegCloseKey(hKey);

  return 1;
}



我希望任何人都可以帮助我. :)


关于cookieexploit



I hope anyone can help me. :)


Regards cookieexploit

推荐答案

我回想起其他用户在将依赖注册表的32位程序移植到64位计算机时遇到问题的阅读,尽管还没有打扰我的win7个人计算机上的注册表访问.

您应该进入调试模式,以确定哪条线失败.至少,至少应该经常尝试使用MessageBox来评估程序失败的地方.

我认为这是注册表访问的一个窍门,尽管我希望您会发现麻烦不大.
I recall reading of other users experiencing problems when porting 32 bit programs that rely on the registry to 64 bit machines, though have yet to bother to play with registry access on my win7 pc.

You should be stepping in Debug mode to determine which line fails. At the very, very least you should have tried a MessageBox every so often to gauge where your program is failing.

I''d think it be some trick with the registry access, though you''ll find it with little trouble, I expect.


这篇关于64位Windows上的程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆