tags:

views:

47

answers:

3
char cmd[40];
driver = FuncGetDrive(driver);
sprintf_s(cmd, "%c:\\test.exe", driver);

I cannot use cmd in

sei.lpFile = cmad;

so, how to convert char array to wchar_t array ?

A: 

This link has examples for many types of string conversions, including the one you're interested in (look for mbstowcs_s)

On Freund
A: 

From MSDN:

#include <iostream>
#include <stdlib.h>
#include <string>

using namespace std;
using namespace System;

int main()
{
    char *orig = "Hello, World!";
    cout << orig << " (char *)" << endl;

    // Convert to a wchar_t*
    size_t origsize = strlen(orig) + 1;
    const size_t newsize = 100;
    size_t convertedChars = 0;
    wchar_t wcstring[newsize];
    mbstowcs_s(&convertedChars, wcstring, origsize, orig, _TRUNCATE);
    wcscat_s(wcstring, L" (wchar_t *)");
    wcout << wcstring << endl;
}
Traveling Tech Guy
You should link to your source: http://msdn.microsoft.com/en-us/library/ms235631%28VS.80%29.aspx
On Freund
Thanks. I should probably link to google as well :)
Traveling Tech Guy
This is the perfect answer
rajivpradeep
A: 

From your example using swprintf_s would work

wchar_t wcmd[40];
driver = FuncGetDrive(driver);
swprintf_s(wcmd, "%C:\\test.exe", driver);

Note the C in %C has to be written with uppercase since driver is a normal char and not a wchar_t.
Passing your string to swprintf_s(wcmd,"%S",cmd) should also work

josefx
driver is of type char
rajivpradeep
@rajivpradeep which is what I meant, the uppercase C instead of c is for char
josefx