PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Reading a file in evc++ 3

Hi all, what's a good method for reading from a text file into a string, or set of strings?

I'd like to be able to run this using GapiDraw from a stationary machine (compiled under VC6.0) for build testing, and also on pocket pc's as the final target machine.

I'm getting terribly confused trying to use fopen, and failing due to lack of unicode between compilers, etc.
I'm using something like this:
Code:

TCHAR fpath[256];
TCHAR filename[]=_T("file.ext");
PocketPC::GetFullPathName(filename, fpath);

HANDLE myHandle = ::CreateFile(fpath, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if (myHandle == INVALID_HANDLE_VALUE)
{
myHandle = 0;
return;
}

DWORD Length = GetFileSize (myHandle, 0);

char* buf=new char[Length];
char* bufcur=buf;

DWORD r;
::SetFilePointer (myHandle, 0, 0, FILE_BEGIN);
::ReadFile(myHandle, buf, Length, &r;, 0);
CloseHandle(myHandle);

PS: PocketPC::GetFullPathName is a pocketfrog function that returns full path name. You sould use your own...
Here's a version of GetFullPathName I created a while back. Works great.
Code:
LPCTSTR GetPath(TCHAR *filename)
{
int nStrLen;

TCHAR *lpFilename;
TCHAR *pDest;
int result;
int ch = '\\';

lpFilename = new TCHAR[1024];
nStrLen = GetModuleFileName(NULL, lpFilename, 1024);
pDest = _tcsrchr(lpFilename, ch);
if (pDest != NULL)
{
result = pDest - lpFilename + 1;
lpFilename[result] = '\0';
if (filename != NULL)
_tcscat(lpFilename, filename);
return lpFilename;
}
else
return NULL;
}
iceboxman · 05 Nov 2002, 22:57 UTC — Reading a file in evc++ 3
serenity wrote:
I'm getting terribly confused trying to use fopen, and failing due to lack of unicode between compilers, etc.

By the way, use TCHARs and all TCHAR related functions(functions beginning with _tcs). You don't need to change your code and it will automatically work between different compilers. Sometimes it get's a little fustrating when it seems you've tried everything. Another useful string function is wsprintf. Look at the MSDN help that comes with EVC for help on using functions.
serenity · 06 Nov 2002, 08:39 UTC — thanks for all the help
Thanks all, most appreciated!