如何将DWORD转换为char*

How to convert DWORD to char *?

本文关键字:char 转换 DWORD      更新时间:2023-10-16

我正在尝试这样的东西,

PROCESS_INFORMATION processInfo = .....
strcat( args, processInfo.dwProcessId);

其中CCD_ 1是CCD_ 2,我需要将其作为参数传递给另一个可执行文件。

您可以使用sprintf

char procID[10];
sprintf(procID, "%d", processInfo.dwProcessId);

这将把processInfo.dwProcessId转换成一个可以供您使用的字符。

要将DWORD转换为char*,可以使用_ultoa/ultoa_s

请参阅此处可能会对您有所帮助。link1

MSDN有非常好的文档,请查看数据转换页面。

还有sprintf()。

虽然不直接"转换为char*",但以下操作应该可以实现:

std::ostringstream stream;
stream << processInfo.dwProcessId;
std::string args = stream.str();
// Then, if you need a 'const char*' to pass to another Win32
// API call, you can access the data using:
const char * foo = args.c_str();