O
oytunyilmaz
Hi,
I have a problem with passing a parameter of type _TCHAR* to int
System(const char *) function. How can I convert _TCHAR* to const char
* ? The code is below
STDMETHODIMP CCopyPathContextMenu::InvokeCommand(LPCMINVOKECOMMANDINFO
lpici)
{
_TCHAR* pStrClipboardText = NULL, strTempFileNameBuff[MAX_PATH + 50];
_TCHAR *pCurrent = NULL, *pLast = NULL;
BOOLEAN bMakeCStyleString = ((GetKeyState(VK_CONTROL) & 0x8000) !=
0);
BOOLEAN bMakeShortPath = ((GetKeyState(VK_SHIFT) & 0x8000) != 0);
int nFileCount = 0, i;
switch (LOWORD(lpici->lpVerb)) {
case ID_COPY_PATH:
nFileCount = m_listFileNames.size();
if (nFileCount == 0)
return S_OK;
// The '+ 50' is so that we provide ample room for double
backslashes.
pStrClipboardText = new _TCHAR[nFileCount * (MAX_PATH+50)];
pStrClipboardText[0] = _T('\0');
// Loop through all the files.
for (i = 0; i < nFileCount; i++) {
// Copy the file name into a temporary buffer. If the ALT key is
down,
// convert the long file name to a short one.
_tcscpy(strTempFileNameBuff, m_listFileNames.front().data());
pLast = strTempFileNameBuff;
// If the control key is pressed, change the path so that all the
// backslashes are converted to double backslashes. This is useful
// when pasting a path into C/C++ code, as a single backslash
denotes
// an escape sequence and a double backslash denotes a literal
backslash.
while ((pCurrent = _tcschr(pLast, _T('\\'))) != NULL) {
_tcsncat(pStrClipboardText, pLast, pCurrent - pLast + 1);
pLast = pCurrent + 1;
_tcscat(pStrClipboardText, _T("\\"));
}
_tcscat(pStrClipboardText, pLast);
// If this isn't the last file, add a line break before we add the
next file name.
if (i != (nFileCount - 1))
_tcscat(pStrClipboardText, _T("\r\n"));
m_listFileNames.pop_front();
}
***********
//system(pStrClipboardText);
***********
delete[] pStrClipboardText;
break;
}
return S_OK;
}
I have a problem with passing a parameter of type _TCHAR* to int
System(const char *) function. How can I convert _TCHAR* to const char
* ? The code is below
STDMETHODIMP CCopyPathContextMenu::InvokeCommand(LPCMINVOKECOMMANDINFO
lpici)
{
_TCHAR* pStrClipboardText = NULL, strTempFileNameBuff[MAX_PATH + 50];
_TCHAR *pCurrent = NULL, *pLast = NULL;
BOOLEAN bMakeCStyleString = ((GetKeyState(VK_CONTROL) & 0x8000) !=
0);
BOOLEAN bMakeShortPath = ((GetKeyState(VK_SHIFT) & 0x8000) != 0);
int nFileCount = 0, i;
switch (LOWORD(lpici->lpVerb)) {
case ID_COPY_PATH:
nFileCount = m_listFileNames.size();
if (nFileCount == 0)
return S_OK;
// The '+ 50' is so that we provide ample room for double
backslashes.
pStrClipboardText = new _TCHAR[nFileCount * (MAX_PATH+50)];
pStrClipboardText[0] = _T('\0');
// Loop through all the files.
for (i = 0; i < nFileCount; i++) {
// Copy the file name into a temporary buffer. If the ALT key is
down,
// convert the long file name to a short one.
_tcscpy(strTempFileNameBuff, m_listFileNames.front().data());
pLast = strTempFileNameBuff;
// If the control key is pressed, change the path so that all the
// backslashes are converted to double backslashes. This is useful
// when pasting a path into C/C++ code, as a single backslash
denotes
// an escape sequence and a double backslash denotes a literal
backslash.
while ((pCurrent = _tcschr(pLast, _T('\\'))) != NULL) {
_tcsncat(pStrClipboardText, pLast, pCurrent - pLast + 1);
pLast = pCurrent + 1;
_tcscat(pStrClipboardText, _T("\\"));
}
_tcscat(pStrClipboardText, pLast);
// If this isn't the last file, add a line break before we add the
next file name.
if (i != (nFileCount - 1))
_tcscat(pStrClipboardText, _T("\r\n"));
m_listFileNames.pop_front();
}
***********
//system(pStrClipboardText);
***********
delete[] pStrClipboardText;
break;
}
return S_OK;
}