Reputation: 2043
Let's suppose for a moment i have this variable
LPTSTR cmdArgs = "D:\\path\my.exe -user blah PLATFORM=0 DEVICE=0 -k poclbm VECTORS BFI_INT WORKSIZE=128 AGGRESSION=7";
Notice where it says DEVICE=0 well, in my case it could be DEVICE=1 or DEVICE=2 etc.
That would mean that, that string must be dynamic. I am going to pass to a function the number which would should come after DEVICE= however, i have no idea how to add it to the cmdArgs variable.
I was thinking of using sprintf and do DEVICE=%d, but i've no idea if i can cast a char variable(which will contain the formatted string) to an LPSTR
Upvotes: 0
Views: 2223
Reputation: 109189
An LPSTR
is a typedef for a char *
. You can use sprintf
for inserting the device number into the string.
char cmdArgs[1000];
int deviceNum = 1;
sprintf( cmdArgs, "D:\\path\\my.exe -user blah PLATFORM=0 DEVICE=%d -k poclbm VECTORS BFI_INT WORKSIZE=128 AGGRESSION=7", deviceNum );
EDIT:
Since the code snippet shows an LPTSTR
you may want to use TCHAR routines instead of sprintf
. LPTSTR
is typedef'd as whcar_t *
when _UNICODE
preprocessor symbol is defined, and char *
if that symbol is not defined or _MBCS
is defined.
TCHAR cmdArgs[1000];
int deviceNum = 1;
_stprintf( cmdArgs, _T(""D:\\path\\my.exe -user blah PLATFORM=0 DEVICE=%d -k poclbm VECTORS BFI_INT WORKSIZE=128 AGGRESSION=7"), deviceNum );
Upvotes: 2
Reputation: 394
Your summary says LPSTR, but your code block says LPTSTR. These (might) be different things, depending on if you're building for Unicode or not.
In unicode builds, LPTSTR is a wchar_t*. In non-unicode, LPTSTR is char*. LPSTR is char* in both cases.
winnt.h has these typedefs (these aren't the literal typedef's, I've kinda paraphrased them here):
typedef char CHAR;
typedef CHAR *LPSTR;
typedef wchar_t WCHAR;
typedef WCHAR *LPWSTR;
#ifdef UNICODE
typedef LPWSTR LPTSTR;
#else
typedef LPSTR LPTSTR;
#endif
If you're building non-Unicode, sprintf with %d will do what you want, as specified by others here.
Upvotes: 1