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

M

MIUSS

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:)
 
I

Ian Collins

MIUSS said:
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.
 
D

David Harmon

On 26 Feb 2007 23:13:36 -0800 in comp.lang.c++ said:
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
 
M

MIUSS

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 said:
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.
 
D

Default User

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
 
M

MIUSS

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 said:
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.
 
J

John Harrison

David said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top