当前位置: 代码迷 >> WinCE >> 内存泄漏,请帮忙看看有关问题出在哪里
  详细解决方案

内存泄漏,请帮忙看看有关问题出在哪里

热度:111   发布时间:2016-04-28 13:29:05.0
内存泄漏,请帮忙看看问题出在哪里?
void   CRS2USBDlg::OnTimer(UINT   nIDEvent)  
{
//   TODO:   Add   your   message   handler   code   here   and/or   call   default

HKEY   hKey   =   HKEY_LOCAL_MACHINE;
DWORD   numSubKey   =   0;
DWORD i;
DWORD       sizeSubKey;
TCHAR subKey[255];
TCHAR   szValue[MAX_REG_LENGTH];

unsigned   char   keyValue[255];
DWORD   dwType   =   REG_SZ;
DWORD   cbData   =   MAX_REG_LENGTH;

int   iVNSCounter   =   0;

memset(keyValue,   0,   255);


switch(nIDEvent)
{
case   TIMER_USB_STATUS:

//   Operation   registry   to   get   info



RegOpenKeyEx(g_HKEY,  
L "Drivers\\Active ",
0,  
KEY_READ,
&hKey);


RegQueryInfoKey(hKey,
NULL,
NULL,
NULL,
&numSubKey,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL);

if(numSubKey)
{
for(i=0;   i <numSubKey;   i++)
{
subKey[0]   =   '\0 ';
sizeSubKey   =   255;

RegEnumKeyEx(hKey,
i,
subKey,
&sizeSubKey,
NULL,
NULL,
NULL,
NULL);


memset(szValue,   0,   sizeof(szValue));
wcscpy(szValue,   L "Drivers\\Active\\ ");
wcscat(szValue,   subKey);

if(RegOpenKeyEx(g_HKEY,   szValue,   0,   KEY_READ,   &hKey)==ERROR_SUCCESS)
{

if(RegQueryValueEx(hKey,   TEXT( "Key "),   NULL,   &dwType,   keyValue,   &cbData)==ERROR_SUCCESS)
{

SetDlgItemText(IDC_STATIC_TEMP,   (LPCTSTR)keyValue);

CString   sTmp;
GetDlgItemText(IDC_STATIC_TEMP,   sTmp);

CString   s1( "Drivers\\USB\\ClientDrivers\\Venus_USB ");
if(sTmp.Compare(s1)==0)
{
iVNSCounter++;
}
}

}

}
}

break;
default:
break;
}

------解决方案--------------------
貌似你没调用RegCloseKey关闭注册表句柄,当然内存泄漏了!
------解决方案--------------------
代码发给我 我帮你改,[email protected]!
  相关解决方案