how to change wstring to lpcvoid ?

i need to use writefile

BOOL WriteFile(

HANDLE hFile, // handle to file to write to
LPCVOID lpBuffer, // pointer to data to write to file -->should mean write_stuff
DWORD nNumberOfBytesToWrite, // number of bytes to write
LPDWORD lpNumberOfBytesWritten, // pointer to number of bytes written
LPOVERLAPPED lpOverlapped // pointer to structure needed for overlapped I/O
);

but don't know how to change wstring to lpcvoid ?

1
2
3
4
5
6
7
8
9
10
11
 create = CreateFile(LP_filename, GENERIC_WRITE, FILE_SHARE_WRITE, 
NULL, CREATE_ALWAYS,FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN | 
FILE_FLAG_NO_BUFFERING, NULL); 

wstring write_stuff = L"I am Happy" + write_stuff2 + write_stuff3  ; 

HANDLE write ; 
DWORD Bytes_that_need_To_Write;
LPDWORD bytes_which_have_written_already;

WriteFile(                            ); 


i don't know how to use WriteFile also..
i have read MSDN, but still don't understand..
Do i need to have a cycle operator--> while , when write a string to a file?

thanks very much
Last edited on
Pass this as the second parameter: (LPCVOID)&write_stuff[0]
And this as the third parameter: sizeof(wchar_t)*write_stuff.size()

The resulting file will very likely be a little endian UCS-2 encoded file.
http://msdn.microsoft.com/en-us/library/bb540534(VS.85).aspx

do each writeFile function only write 1 byte eachtimes?

if it's true, that means i need to use while to excute writeFile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
while (bytes_which_have_written_already< Bytes_that_need_To_Write )
{

create = CreateFile(LP_filename, GENERIC_WRITE, FILE_SHARE_WRITE, 
NULL, CREATE_ALWAYS,FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN | 
FILE_FLAG_NO_BUFFERING, NULL); 

wstring write_stuff = L"I am Happy" + write_stuff2 + write_stuff3  ; 

HANDLE write ; 

wchar_t need_to write_Bytes = write_stuff.size() ;
DWORD Bytes_that_need_To_Write = sizeof (need_to write_Bytes ) ;

LPDWORD bytes_which_have_written_already;

WriteFile
 (
   write, 
   (LPCVOID)&write_stuff[0],   
   Bytes_that_need_To_Write  - bytes_which_have_written_already,
   bytes_which_have_written_already,
   NULL
 )
}

Last edited on
do each writeFile function only write 1 byte eachtimes?
'Course not! That's what the third parameter is for. The fourth parameter is there in case some kind of error has occurred while writing (say, the system ran out of storage).
thanks very much

by the way , API is like low-level language, which difficult to learn and use^^
Last edited on
it is of course... or it would not be easy to remember^^...

(did u realize that they made most programming languages like the english language, by the way?:P) *jokey:D*
Last edited on
Topic archived. No new replies allowed.