简体   繁体   English

如何在MessageBox上显示FARPROC内存地址

[英]How to Display FARPROC memory address on MessageBox

So I'm trying to make a MessageBox pop up with the memory address of a FARPROC so I can see the value. 因此,我试图用FARPROC的内存地址弹出一个MessageBox,以便可以看到该值。 I can't seem to do it though. 我似乎无法做到这一点。 I've tried some wacky stuff too. 我也尝试过一些古怪的东西。

This is my unworking example that I last tried. 这是我上次尝试的无效示例。

MessageBox(NULL, (LPCSTR) (WCHAR) myFarproc, "Loader", NULL);

It just crashes the program, and 它只是使程序崩溃,并且

MessageBox(NULL, (LPCSTR) myFarproc, "Loader", NULL);

displays gibberish. 显示乱码。 Also of note is that the program calling this dll's code is in C#. 还要注意的是,调用此dll代码的程序在C#中。

You can't just cast a pointer into a string and expect something legible, especially if you cast a random pointer into aa pointer to a C style string (which is what LPCSTR is). 您不能只将指针转换为字符串并期望某些内容清晰易懂,尤其是如果您将随机指针转换为指向C样式字符串的指针(这就是LPCSTR是)。

What you need to do is to convert the numerical value of the pointer into a string using something like sprintf_s and display the resulting string. 您需要做的是使用sprintf_s类的将指针的数值转换为字符串,并显示结果字符串。

For example (from memory, didn't compile it): 例如(从内存中,未编译):

char buffer[9];   // Adjust size if you're on a 64-bit system
sprintf_s(buffer, "%x", (size_t)myFarProc);

This is assuming that you can use the C++ version of sprintf_s. 假设您可以使用sprintf_s的C ++版本。

I think I did it. 我想我做到了。 Am I doing this correctly? 我这样做正确吗?

size_t pAddy = (size_t) myFarproc;
stringstream ss;
char buff[10];
ss << itoa(pAddy,buff,16);
MessageBox(NULL, (LPCSTR) ss.str().c_str(), "Address", NULL);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM