我想这样的事情,如何将DWORD转换为char *?
PROCESS_INFORMATION processInfo = .....
strcat(args, processInfo.dwProcessId);
其中args
是char *
,我需要作为参数传递到其他可执行文件。
我想这样的事情,如何将DWORD转换为char *?
PROCESS_INFORMATION processInfo = .....
strcat(args, processInfo.dwProcessId);
其中args
是char *
,我需要作为参数传递到其他可执行文件。
您可以用sprintf
char procID[10];
sprintf(procID, "%d", processInfo.dwProcessId);
这将processInfo.dwProcessId转换成然后可以通过你所使用的字符。
虽然没有直接 “转换为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();
要转换DWORD为char *您可以使用_ultoa/_ultoa_s
看到这里可能会帮助你。 link1
MSDN有很不错的文档,请查看Data Conversion page。
还有sprintf()。
DWORD是一个整数类型。将它转换为char *'没有任何意义。 – 2012-02-14 06:01:17
但我需要这个'DWORD'作为参数传递给使用CreateProcess()调用的另一个exe文件。有什么建议么? – psp 2012-02-14 06:04:15
[C++ long to string](http://stackoverflow.com/questions/947621/c-long-to-string)或[如何将int转换为C中的字符串](http:// stackoverflow。 COM /问题/ 8257714 /如何对转换-AN-INT-到字符串中-C)。 – user7116 2012-02-14 06:04:22