Convertion

Discussion in 'C++' started by oytunyilmaz@gmail.com, Jul 14, 2006.

  1. Guest

    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;
    }
     
    , Jul 14, 2006
    #1
    1. Advertising

  2. wrote:
    > 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
    >
    > [...]


    What's _TCHAR? What's "System" function? They are not part of the
    _standard_ C++. You should probably ask in the newsgroup dedicated
    to your platform or compiler.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Jul 14, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    8
    Views:
    1,956
    Mike Treseler
    Feb 10, 2005
  2. isore
    Replies:
    0
    Views:
    554
    isore
    Jul 1, 2004
  3. Hiranya Samarasekera

    BMP to GIF convertion

    Hiranya Samarasekera, Aug 26, 2003, in forum: Java
    Replies:
    3
    Views:
    2,576
    Marco Schmidt
    Aug 27, 2003
  4. cccc
    Replies:
    8
    Views:
    10,058
    Andrew Thompson
    Sep 21, 2004
  5. Steven
    Replies:
    1
    Views:
    618
Loading...

Share This Page