我正在使用C ++代码库,其中包含如下几行:

CreateThread(NULL, 0, MyThreadMethod, NULL, 0, NULL);


我想写MyThreadMethod的值来调试输出。 (我想这是一个十六进制地址)。
MyThreadMethod具有类型LPTHREAD_START_ROUTINE。我已经有一个名为OutputDebugInt的方法,该方法可以编写一个int来调试输出。当我编译行

OutputDebugInt(MyThreadMethod);


然后编译器发出错误


  无法将参数1从unsigned long (__stdcall *)(void *)转换为int


那么,有没有一种方法可以将LPTHREAD_START_ROUTINE转换为int(或其他可以写入调试输出的内容)?

最佳答案

std::basic_ostringstream<TCHAR> ss;
ss << static_cast<void*>(&MyThreadMethod);
::OutputDebugString(ss.str().c_str());


在32位平台上可以转换为int,但在64位平台上则不能,因此我坚持创建一个字符串。

10-07 22:18