Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert DWORD to char *?

Tags:

c++

I am trying something like this,

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

where args is a char * which I need to pass as an argument to another executable.

like image 224
psp Avatar asked Feb 14 '12 06:02

psp


4 Answers

You can use sprintf

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

This will convert the processInfo.dwProcessId into a character which can then be used by you.

like image 130
Ajit Vaze Avatar answered Oct 03 '22 00:10

Ajit Vaze


MSDN has pretty good documentation, check out the Data Conversion page.

There's sprintf() too.

like image 23
Alexey Frunze Avatar answered Oct 02 '22 22:10

Alexey Frunze


To convert DWORD to char * you can use _ultoa / _ultoa_s

see here might help you.link1

like image 34
Java Avatar answered Oct 02 '22 23:10

Java


While not directly "converting to a char*", the following should do the trick:

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();
like image 34
André Caron Avatar answered Oct 03 '22 00:10

André Caron