pointer指向并读取记忆体位址问题

bob76012 2013-12-07 06:30:18
我在一个工程简单写了变数
a = 10
并输出记忆体位址
并编译执行
然后我再开另一个工程
把显示的记忆体位址填入
b
cout << b << endl;//显示记忆体位址正确
cout << *b << endl;//error读取失败了
为什么呢
应该是显示10才对不是吗?
...全文
114 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
晓敬 2013-12-08
  • 打赏
  • 举报
回复

#include <iostream>
int main(int argc,char** argv){
int a=1;
int *b=&a;
std::cout << "a:" << a << std::endl;
std::cout << "*b:" << *b << std::endl;
std::cout << "&a:" << &a << std::endl;
std::cout << "b:" << b << std::endl;
}
赵4老师 2013-12-07
  • 打赏
  • 举报
回复
hProcess=OpenProcess(PROCESS_ALL_ACCESS,FALSE,dwProcessId); ReadProcessMemory The ReadProcessMemory function reads memory in a specified process. The entire area to be read must be accessible, or the operation fails. BOOL ReadProcessMemory( HANDLE hProcess, // handle to the process whose memory is read LPCVOID lpBaseAddress, // address to start reading LPVOID lpBuffer, // address of buffer to place read data DWORD nSize, // number of bytes to read LPDWORD lpNumberOfBytesRead // address of number of bytes read ); Parameters hProcess Handle to the process whose memory is being read. The handle must have PROCESS_VM_READ access to the process. lpBaseAddress Pointer to the base address in the specified process to be read. Before any data transfer occurs, the system verifies that all data in the base address and memory of the specified size is accessible for read access. If this is the case, the function proceeds; otherwise, the function fails. lpBuffer Pointer to a buffer that receives the contents from the address space of the specified process. nSize Specifies the requested number of bytes to read from the specified process. lpNumberOfBytesRead Pointer to the actual number of bytes transferred into the specified buffer. If lpNumberOfBytesRead is NULL, the parameter is ignored. Return Values If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call GetLastError. The function fails if the requested read operation crosses into an area of the process that is inaccessible. Remarks ReadProcessMemory copies the data in the specified address range from the address space of the specified process into the specified buffer of the current process. Any process that has a handle with PROCESS_VM_READ access can call the function. The process whose address space is read is typically, but not necessarily, being debugged. The entire area to be read must be accessible. If it is not, the function fails as noted previously. QuickInfo Windows NT: Requires version 3.1 or later. Windows: Requires Windows 95 or later. Windows CE: Unsupported. Header: Declared in winbase.h. Import Library: Use kernel32.lib. See Also Debugging Overview, Debugging Functions, WriteProcessMemory, ReadProcessMemoryVlm
碼上道 2013-12-07
  • 打赏
  • 举报
回复
两个工程,是两个不同的进程

64,642

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧