CreateFile returns invalid handle value when I use wcscpy in my source... ...need a help.

Discussion in 'C++' started by MIUSS, Feb 27, 2007.

  1. MIUSS

    MIUSS Guest

    Hello

    I got an unusual problem and I don't know how to solve it out.

    I need to get success with the handle variable hFile. It's not problem
    'til I use wcscpy(...). I mean, when I take out those two double-
    slashes the source is not working and the func CreateFile returns
    0xFFFFFF to that variable. It seems to me that it has some context
    with using wcscpy? But why?

    void SaveWorkerFile(void)
    {
    TCHAR szSoubor[MAX_PATH];//

    int StrLength;
    LPTSTR lpBuffer;
    WCHAR temppp[200];
    WCHAR UnicodeIdr[10];
    HANDLE hFile;

    UnicodeIdr[0] = 0xFEFF; UnicodeIdr[1] = 0x0000;
    // wcscpy(temppp, UnicodeIdr);
    // wcscat(temppp, TEXT("MK00000000 01/01/07 REZIEROTEC
    PocetHodin Popis \r\n"));

    StrLength = lstrlen(temppp)+10;

    lpBuffer = (LPTSTR)HeapAlloc(GetProcessHeap(), 0, StrLength);
    GetWindowText(hWndDatabaseWindow, lpBuffer, StrLength);
    wcscpy(lpBuffer, temppp);

    DWORD dwZapsano;
    lstrcpy(szSoubor, TEXT("C:\\RCOMMISIONS\\mkatab.txt"));

    hFile = CreateFile(szSoubor, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
    0, NULL);
    if(hFile == INVALID_HANDLE_VALUE) return;
    if(!WriteFile(hFile, lpBuffer, StrLength-1, &dwZapsano, NULL))
    MessageBox(g_hWnd, TEXT("Error in writing file process."),
    TEXT("Error"), MB_ICONERROR);
    CloseHandle(hFile);
    HeapFree(GetProcessHeap(), 0, lpBuffer);

    return;
    }

    Any help will be apprecciated.

    Have a nice day:)
     
    MIUSS, Feb 27, 2007
    #1
    1. Advertising

  2. MIUSS

    Ian Collins Guest

    Re: CreateFile returns invalid handle value when I use wcscpy inmy source... ...need a help.

    MIUSS wrote:
    > Hello
    >
    > I got an unusual problem and I don't know how to solve it out.
    >
    > I need to get success with the handle variable hFile. It's not problem
    > 'til I use wcscpy(...). I mean, when I take out those two double-
    > slashes the source is not working and the func CreateFile returns
    > 0xFFFFFF to that variable. It seems to me that it has some context
    > with using wcscpy? But why?
    >
    > void SaveWorkerFile(void)
    > {
    > TCHAR szSoubor[MAX_PATH];//
    >

    Getting repetitive tonight...

    This looks horribly like widows code, so you'd better post to windows
    development group.

    --
    Ian Collins.
     
    Ian Collins, Feb 27, 2007
    #2
    1. Advertising

  3. MIUSS

    David Harmon Guest

    On 26 Feb 2007 23:13:36 -0800 in comp.lang.c++, "MIUSS" <> wrote,
    >I need to get success with the handle variable hFile. It's not problem
    >'til I use wcscpy(...). I mean, when I take out those two double-
    >slashes the source is not working and the func CreateFile returns


    Thee is no wcscpy() nor CreateFile() in the standard C++ library.

    See the welcome message posted twice per week in comp.lang.c++ under the subject "Welcome to comp.lang.c++! Read this first." or available at
    http://www.slack.net/~shiva/welcome.txt
     
    David Harmon, Feb 27, 2007
    #3
  4. MIUSS

    MIUSS Guest

    Hello everyone,

    I've found the fault and already have solved this problem. I used too
    much long string in func wcscpy in TEXT("...") which resulted in
    invalid handle value then. Thank you for your willigness and have a
    nice day:)

    Ian Collins napsal:
    > MIUSS wrote:
    > > Hello
    > >
    > > I got an unusual problem and I don't know how to solve it out.
    > >
    > > I need to get success with the handle variable hFile. It's not problem
    > > 'til I use wcscpy(...). I mean, when I take out those two double-
    > > slashes the source is not working and the func CreateFile returns
    > > 0xFFFFFF to that variable. It seems to me that it has some context
    > > with using wcscpy? But why?
    > >
    > > void SaveWorkerFile(void)
    > > {
    > > TCHAR szSoubor[MAX_PATH];//
    > >

    > Getting repetitive tonight...
    >
    > This looks horribly like widows code, so you'd better post to windows
    > development group.
    >
    > --
    > Ian Collins.
     
    MIUSS, Feb 27, 2007
    #4
  5. MIUSS

    Default User Guest

    Ian Collins wrote:


    > Getting repetitive tonight...
    >
    > This looks horribly like widows code, so you'd better post to windows
    > development group.


    Those poor widows.




    Brian
     
    Default User, Feb 27, 2007
    #5
  6. MIUSS

    MIUSS Guest

    Later I get to know that it isn't neither because of long string in
    TEXT(...)... So I don't know where the fault come from. There must be
    some stupid bug. I've gave up and I've had to copy my older code where
    I hadn't any problem with invalid handle value... I've copied it to my
    new project and it works fine.. It's almost the same I only use TCHAR
    instead of WCHAR and lstrcpy instead of wcscpy...

    MIUSS napsal:
    > Hello everyone,
    >
    > I've found the fault and already have solved this problem. I used too
    > much long string in func wcscpy in TEXT("...") which resulted in
    > invalid handle value then. Thank you for your willigness and have a
    > nice day:)
    >
    > Ian Collins napsal:
    > > MIUSS wrote:
    > > > Hello
    > > >
    > > > I got an unusual problem and I don't know how to solve it out.
    > > >
    > > > I need to get success with the handle variable hFile. It's not problem
    > > > 'til I use wcscpy(...). I mean, when I take out those two double-
    > > > slashes the source is not working and the func CreateFile returns
    > > > 0xFFFFFF to that variable. It seems to me that it has some context
    > > > with using wcscpy? But why?
    > > >
    > > > void SaveWorkerFile(void)
    > > > {
    > > > TCHAR szSoubor[MAX_PATH];//
    > > >

    > > Getting repetitive tonight...
    > >
    > > This looks horribly like widows code, so you'd better post to windows
    > > development group.
    > >
    > > --
    > > Ian Collins.
     
    MIUSS, Feb 28, 2007
    #6
  7. Re: CreateFile returns invalid handle value when I use wcscpy inmy source... ...need a help.

    David Harmon wrote:
    > On 26 Feb 2007 23:13:36 -0800 in comp.lang.c++, "MIUSS" <> wrote,
    >
    >>I need to get success with the handle variable hFile. It's not problem
    >>'til I use wcscpy(...). I mean, when I take out those two double-
    >>slashes the source is not working and the func CreateFile returns

    >
    >
    > Thee is no wcscpy() nor CreateFile() in the standard C++ library.
    >


    wcscpy is part of the standard C library, and therefore part of the
    standard C++ library too.

    john
     
    John Harrison, Feb 28, 2007
    #7
    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. Sean Liong via .NET 247

    CreateFile - Read/Write client's Stroage

    Sean Liong via .NET 247, Jun 8, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    548
    bradley
    Jun 9, 2005
  2. Amon Tse

    wcscpy and memcpy

    Amon Tse, Apr 26, 2005, in forum: C++
    Replies:
    1
    Views:
    2,651
    Ron Natalie
    Apr 26, 2005
  3. Udo Hoerhold

    CreateFile in unmanaged code fails

    Udo Hoerhold, Jun 14, 2006, in forum: ASP .Net Security
    Replies:
    0
    Views:
    245
    Udo Hoerhold
    Jun 14, 2006
  4. vasanth kumar
    Replies:
    2
    Views:
    184
    vasanth kumar
    Jul 18, 2004
  5. Paul
    Replies:
    6
    Views:
    298
Loading...

Share This Page