最近写一个内存遍历工具,需要读取进程内存地址,发现如果传入的地址是无效的,就发生内存违例错误,翻了一下书、google了一下,终于搞定了。虽然没技术含量,记录下来,以便以后查看。
BOOL CMyListCtrl::ShowData(PVOID lpAdd) { CString strTmp; //lpAdd=(PVOID)0x12345; WCHAR szWideProgID[1024];
strTmp.Format(TEXT("0x%x"),(DWORD)lpAdd); this->InsertItem(0, strTmp);//地址 __try{ //开EHs-c-选项 strTmp.Format(TEXT("%x"),*(const long *)lpAdd); this->SetItemText(0,1,strTmp); //整数型
strTmp.Format(TEXT("%e"),*(const float *)lpAdd); this->SetItemText(0,2,strTmp); //单精度浮点数
strTmp.Format(TEXT("%e"),*(const double *)lpAdd); this->SetItemText(0,3,strTmp); //双精度浮点数
long lLen = MultiByteToWideChar(CP_ACP,0,(LPCSTR)lpAdd,strlen((LPCSTR)lpAdd), szWideProgID,sizeof(szWideProgID)); szWideProgID[lLen] = '\0';
//strTmp.Format(TEXT("%s"),); this->SetItemText(0,4,szWideProgID); //字符串 strTmp.Format(TEXT("%s"),(const WCHAR *)lpAdd); this->SetItemText(0,5,strTmp); //U_字符串 } __except( EXCEPTION_EXECUTE_HANDLER ) { this->SetItemText(0,1,TEXT("??")); //整数型 this->SetItemText(0,2,TEXT("??")); //单精度浮点数 this->SetItemText(0,3,TEXT("??")); //双精度浮点数 this->SetItemText(0,4,TEXT("??")); //字符串 this->SetItemText(0,5,TEXT("??")); //U_字符串 }
/**//* */ return 0; }
|
|
随笔:2
文章:5
评论:0
引用:0
| 日 | 一 | 二 | 三 | 四 | 五 | 六 |
---|
22 | 23 | 24 | 25 | 26 | 27 | 28 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 1 | 2 | 3 | 4 |
|
常用链接
留言簿(2)
随笔档案
文章分类
文章档案
开源库
搜索
最新评论
阅读排行榜
评论排行榜
|
|