I want to convert a CHAR file to UNICODE file. I read a file character by character in CHAR file type and then save this character in a CHAR Variable and then I want to copy this CHAR Variable to a WCHAR Variable and then I Write the the WCHAR Variable in to a UNICODE file.

here is the code :

#include<Windows.h>
#include<tchar.h>

int _tmain(int argc, LPCTSTR argv[])
{
    HANDLE hInfile, hOutfile;
    CHAR f1; 
    WCHAR f2;   
    DWORD Rd, Wrt; 
    INT i;
    CreateFile(argv[1], GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL,NULL);
    CreateFile(argv[2], GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,NULL);
    while ((ReadFile(hInfile, &f1, sizeof(CHAR), &Rd, NULL) && Rd>0)) 
    {
        **_tccpy(f2, f1);**
        WriteFile(hOutfile, &f2, Rd, &Wrt, NULL);
    }

    CloseHandle(hInfile);
    CloseHandle(hOutfile);

}

in bold code is the problem, how can I copy CHAR Variable to a WCHAR Variable. the _tccpy function and strcpy function cant do this, because the prototype of both of them is char or wachar.

有帮助吗?

解决方案

I have always found these string basics and conversions very useful when dealing with Unicode in C++.

其他提示

Microsoft Specific Use wmain instead of main if you want to write portable code that adheres to the Unicode programming model.

wmain( int argc, wchar_t *argv[ ], wchar_t *envp[ ] )

wmain at ms http://msdn.microsoft.com/en-us/library/bky3b5dh(VS.80).aspx

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top