Q:

Getting an odd value, so odd

Here 's the related code: 
            char* url;
            url = "http://xxxx/index.txt";

            TCHAR t_url[256];
            charToTchar(url, t_url);
            downloadFile(t_url);

Two functions:
            charToTchar(const char *_char, TCHAR *tchar)
            {
                int iLength ;  
                iLength = MultiByteToWideChar (CP_ACP, 0, _char, strlen (_char) + 1, NULL, 0) ;  
                MultiByteToWideChar (CP_ACP, 0, _char, strlen (_char) + 1, tchar, iLength) ;  
            }

            downloadFile(TCHAR *url_value)
            {
                TCHAR path[256];
                SHGetSpecialFolderPath(NULL, path, 28 , false);
                wcscat_s(path,  _T("\\check.txt"));

                char* c_url_value;
                c_url_value = "";

                int iLength ;  
                iLength = WideCharToMultiByte(CP_ACP, 0, url_value, -1, NULL, 0, NULL, NULL);  
                WideCharToMultiByte(CP_ACP, 0, url_value, -1, c_url_value, iLength, NULL, NULL);   

                DeleteUrlCacheEntry(c_url_value);  
                HRESULT hr = URLDownloadToFile(0, url_value, path, 0, 0);
            }

The right TCHAR path should look like this:
C.:\......\L.o.c.a.l.\.c.h.e.c.k...t.x.t.
But when I run second time of "downloadFile" function, the TCHAR path became so odd:
C.:\.......\L.o.c.a.l.index.txt.k.t.x.t.
ps I'm using VC++ and I don't think it supports "wcscat_s". Any solutions?

A:

If the character set type is Unicode, then using char* right from the start is incorrect.
        TCHAR url[] = _T("http://xxxx/index.txt");
        DeleteUrlCacheEntry(url);  
        downloadFile(url);

The function DeleteUrlCacheEntry takes an LPCTSTR.  
http://msdn.microsoft.com/en-us/library/windows/desktop/aa383983%28v=vs.85%29.aspx
The definition of this type depends on the build settings for Visual C++.  If the build is UNICODE, then the string type is 16-bit, not 8 bit.  
Therefore to be "build neutral", the type to use is TCHAR and usage of the _T macro to create string constants can be used.  
The following program compiles successfully when the character set type chosen is Unicode (Visual Studio 2010):
#include <tchar.h>
#include <windows.h>
#include <WinInet.h>

int main()
{
    TCHAR url[] = _T("http://xxxx/index.txt");
    DeleteUrlCacheEntry(url);  
}

The following program does not compile successfully if a UNICODE build is chosen:
#include <tchar.h>
#include <windows.h>
#include <WinInet.h>

int main()
{
    char* url = "http://xxxx/index.txt";
    DeleteUrlCacheEntry(url);  
}

The error is as follows:
error C2664: 'DeleteUrlCacheEntryW' : cannot convert parameter 1 from 'char *' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

If you know for sure that it's UNICODE and won't ever be any other character set build, you can eschew all of this and just use std::wstring, instead of TCHAR and _T.  Or better yet, you can use a std::basic_string<TCHAR> and take advantage of the functions that are available.

