views:

48

answers:

1
// Convert to a wchar_t*

size_t origsize = strlen(toChar) + 1;

const size_t newsize = 100;

size_t convertedChars = 0;

wchar_t wcstring[newsize];

mbstowcs_s(&convertedChars, wcstring, origsize, toChar, _TRUNCATE);

wcscat_s(wcstring, L"\\*.*\0");

wcout << wcstring << endl; // C:\Documents and Settings\softnotions\Desktop\Release\*.*



SHFILEOPSTRUCT sf;

memset(&sf,0,sizeof(sf));

sf.hwnd = 0;

sf.wFunc = FO_COPY;

//sf.pFrom =wcstring;  /* when giving wcstring i am not getting answer */

 sf.pFrom = L"C:\\Documents and Settings\\softnotions\\Desktop\\Release\\*.*\0";

   wcout << sf.pFrom  <<endl;   // C:\Documents and Settings\softnotions\Desktop\Release\*.*

Both wcstring and sf.pFrom are same then why not gettng answer when assigning sf.pFrom =wcstring;

+1  A: 

SHFILEOPSTRUCT requires pFrom and pTo to be double-null-terminated strings.

The string literal you assign to pFrom has an embedded \0, so the string is double-null-terminated.

When you call wcscat_s, the embedded \0 is interpreted as the end of the string to append, so the resulting string is not double-null-terminated.

As you say in your comment, you can do this (although the function you need is wcslen):

wcscat_s(wcstring, L"\\*.*");
wcstring[wcslen(wcstring) + 1] = 0;
ChrisN