From: B.S on
I think all of you is rite, program is giving error at creating file
it is returning INVALID_HANDLE_VALUE i dont know why. i tried it in
ather programs and there it workd. The file name is corect but it
doesn't work

and TCHAR is returning 256 not 1024 you must be meen WCHAR it is used
for UNICODE not TCHAR
From: B.S on
I think there is resolved the problem i describe hfile in global and
now it works fine, now one thing i wont to know is how to delete some
bytes from file.
From: Friedel Jantzen on
Am Tue, 27 Oct 2009 05:01:53 -0700 (PDT) schrieb B.S:

> I think there is resolved the problem i describe hfile in global and
> now it works fine, now one thing i wont to know is how to delete some
> bytes from file.

Hi,
I think, it is not clear, why it does not work with a local hfile.
You can get an error code, if an invalid handle is returned with
DWORD lastError = GetLastError();
I think this is important.
The API function FormatMessage is used to get a verbose error message from
the system:

char *lpMsgBuf = 0;

FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
lastError,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0,
NULL
);

// ... Display the message e.g. with MessageBox ...
// Note: It can happen, that the system does not supply an error message
string.

// Free the buffer
if(lpMsgBuf) LocalFree( lpMsgBuf );

I had a quick look at your code (missupload.com worked), but I do not have
the time to explain all bugs. You should go with the debugger step by step
and check whats going on.

This bug must be fixed immediately:
ReadFile(hfile,&programa,sizeof(programa),&din,0);
where programa is: TCHAR programa[256]; // Again: why dont you use char?
When programa is an array, the name programa is a _pointer_ .
=> ReadFile(hfile,programa,sizeof(programa),&din,0);
Your bug overwrites memory, and this can be the cause of very odd behavior.

Check the doc for the return value of WM_INITDIALOG.

Regarding your question, how to delete bytes from the file, we must know:
From the end or elsewhere?

HTH,
Friedel
From: B.S on
It returned " The system cannot find the file specified."

thanks for this code.

i use TCHAR all time and i hadn't any problem and whats differens with
TCHAR and char i think they are same.

and about deleting bytes i need to delete from middle of the file
From: Friedel Jantzen on
Am Tue, 27 Oct 2009 12:59:32 -0700 (PDT) schrieb B.S:

> It returned " The system cannot find the file specified."

Do you pass a full path to CreateFile or the filename only?
With a filename only the system assumes that it is in the current
directory. You can call GetCurrentDirectory and debug or call MessageBox to
see what your current directory actually is.
BTW: A common typo is forgetting to double the backslashes in the path, if
it is a string literal.

> thanks for this code.
>
> i use TCHAR all time and i hadn't any problem and whats differens with
> TCHAR and char i think they are same.

No, TCHAR is a 16-bit unicode wchar_t, if UNICODE is defined;
and it is an 8-bit ANSI char, if not (thats why you had no problems).
TCHAR is used to write code which can be compiled with ANSI APIs
and with UNICODE APIs, depending on
#define UNICODE
#define _UNICODE
or a switch in your project settings.
Your code is designed for ANSI only and will not compile with UNICODE
defined, so using TCHAR makes no sense.

> and about deleting bytes i need to delete from middle of the file

Afaik there is no Win32 API for this.
If your file is small, you can read it into a buffer, call MoveMemory to
shift the part behind the remove data to the beginning of the remove data,
then WriteFile with the new filesize. Careful with MoveMemory, study the
doc for the meaning of its parameters!

With a large file, I would use a temporary file copy and copy the data
behind the remove data in parts.

Have a look at the SetEndOfFile function, too.

I use an hex editor to check the resulting file.

Regards,
Friedel
First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4
Prev: Form load event
Next: trying to addicon to program problem