Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > CreateFile returns invalid handle value when I use wcscpy in my source... ...need a help.

Reply
Thread Tools

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

 
 
MIUSS
Guest
Posts: n/a
 
      02-27-2007
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

 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      02-27-2007
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.
 
Reply With Quote
 
 
 
 
David Harmon
Guest
Posts: n/a
 
      02-27-2007
On 26 Feb 2007 23:13:36 -0800 in comp.lang.c++, "MIUSS" <(E-Mail Removed)> 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

 
Reply With Quote
 
MIUSS
Guest
Posts: n/a
 
      02-27-2007
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.


 
Reply With Quote
 
Default User
Guest
Posts: n/a
 
      02-27-2007
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
 
Reply With Quote
 
MIUSS
Guest
Posts: n/a
 
      02-28-2007
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.


 
Reply With Quote
 
John Harrison
Guest
Posts: n/a
 
      02-28-2007
David Harmon wrote:
> On 26 Feb 2007 23:13:36 -0800 in comp.lang.c++, "MIUSS" <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CreateFile in unmanaged code fails Udo Hoerhold ASP .Net Security 0 06-14-2006 03:10 PM
VBScript FSO: CreateFile OK, OpenTextFile fails Paul ASP General 6 03-17-2006 01:15 AM
CreateFile - Read/Write client's Stroage Sean Liong via .NET 247 ASP .Net 3 06-09-2005 12:45 PM
wcscpy and memcpy Amon Tse C++ 1 04-26-2005 11:44 AM
How to handle, when SQL command returns a single value vasanth kumar ASP General 2 07-18-2004 10:56 AM



Advertisments