Working with CreateFile()

Hi, I'm having trouble with opening and reading text from a file. I'm not getting any errors at this point, but nothing seems to be written to my "hold" vector. Am I setting up my file-opening program correctly?


1
2
3
4
5
6
7
8
9
10
11
12
13
vector<wchar_t*> loadfile(HDC hdc, wchar_t file[])
{
	HANDLE hfile;
	vector<wchar_t*> hold(9000);//will be holding the text in wide-string vector
	DWORD read=0;

	hfile = CreateFile(file,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_ALWAYS,
                            FILE_ATTRIBUTE_NORMAL,NULL);
	ReadFile(hfile,&hold[0],128,&read, NULL);
	CloseHandle(hfile);
	TextOut(hdc, 20,20,hold[0], 200);
	return hold;
}



Right now I've got it set up so I can call the function directly in WM_PAINT to test the output. I only have it this way to test output, later on it will be set up to go in my WM__CREATE.
Last edited on
How about checking return codes and looking up error codes where appropriate?

The buffer should be declared as:
 
std::vector<char> hold(9000);
It all depends on what's in the file as to whether you use ASCII or a Unicode buffer.
I was worried about the char/wchar thing. I am using wchar because from what i have read it is supposed to run faster at compiling time. I am having isues retreiving char input as vectors and then converting that over to wchar, that`s why I was hoping that readfile would convert to wchar for me.
you are right, I did some error checking and it is a problem in readfile so it must be the wchar that is the issue. My internet is down so Im typing on a kindle, i can`t post any followup code for the next few days. does anyone know the fastest way to cast a char vector into a wchar vector? right now I am trying to break the char* vectors down into single char constants, then inputting those constants back into a wchar* vector. Does anyone have a better method than that?
Topic archived. No new replies allowed.