Question : Windows CE 5.0 - ReadFile just giving me first Character

Hello Experts,
I have a huge problem concerning ReadFile - Method (maybe its a WriteFile problem ?).
It just gives me the first character of a file and breaks after that - bet it is an encoding issue, but I am out of ideas.

I am writing an ActiveX that runs on Windows CE 5.0 (!, not PocketPC or Mobile). It is called via a website on the mobile device. That works fine so far (implemented IObjectSafety). My ActiveX got instanciated and the methods it offers get called.
The ActiveX should be used to store data on the mobile device and recieved it again if needed.

1. Method (WriteData) takes as parameters a filename and it's content (both BSTR).
The file got created and its content is written.

2. Method (ReadData) has regular parameter - the filename - and an out BSTR parameter that should return the content of the file given by parameter 1.

Interaction between ActiveX and Website works fine. Just the read stuff from the file drives me insane. I googled for nearly 1 1/2 days. Once I got it all running, but messed it up.
I am not in need to stick to the way shown by the two methods. If someone has a better way / idea I am open minded to that :).

Some facts about the setting:
- embedded visual c++ 4.0
- ATL component
- Windows CE 5.0
- Internet Explorer 6 mobile

Using .net would not be an option, because there is no way an clr-component can be run within a mobile ie :-(.

I tried to use MFC (to use CFile and stuff), but I was not able to implement IObjectSafety *blushes*. If someone has a working skeleton that I can try I would be gratefull. Hpoe this would make things easier.

Thank you in advance.
RZA
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:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
STDMETHODIMP FileStore::WriteData(BSTR fileName, BSTR data)
{
	CComBSTR filePath = store_path;
	filePath.Append(fileName);
HANDLE	hFile = ::CreateFile(filePath, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_WRITE , NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
	DWORD   dwBytesWritten = 0;
	DWORD	dwFileSize;
	TCHAR*  pszUnicodeBuff;
	dwFileSize = wcslen(data);
	pszUnicodeBuff = (TCHAR*)LocalAlloc(LPTR, (dwFileSize +1) * sizeof(TCHAR));	
	_tcsncpy(pszUnicodeBuff, data, dwFileSize);

        ::WriteFile( hFile, (LPCVOID)pszUnicodeBuff, ( dwFileSize +1) * sizeof(TCHAR), &dwBytesWritten, NULL);
	::CloseHandle(hFile);
	return S_OK;
}


//-------------------------------------------------

STDMETHODIMP FileStore::ReadData(BSTR fileName, BSTR* data)
{

	DWORD   dwBytesWritten = 0;
	DWORD	dwFileSize;    
        CHAR*   pszFileBuff = 0;
	TCHAR*  pszUnicodeBuff;
	
	CComBSTR filePath = store_path;
	filePath.Append(fileName);

        HANDLE hFile = CreateFile(filePath, GENERIC_READ | GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

        dwFileSize = GetFileSize( hFile, NULL);
	pszFileBuff = (char*)LocalAlloc( LPTR, dwFileSize );	

        ReadFile(hFile,(LPVOID)pszFileBuff, dwFileSize, &dwBytesWritten, NULL);
        pszUnicodeBuff = (TCHAR*)LocalAlloc( LPTR, sizeof(TCHAR)*( dwFileSize + 1 ));
        mbstowcs(pszUnicodeBuff, (const char *)pszFileBuff, (size_t)strlen(pszFileBuff) );
        CloseHandle(hFile);
        return SysReAllocString(data,  pszUnicodeBuff);	
}

Answer : Windows CE 5.0 - ReadFile just giving me first Character

well, my blind guess is that: why do you call mbstowcs() ???? it treats UNICODE buffer as multibyte and tries to convert it to UNICODE, so it's no surprise you see 1 single charachter
Random Solutions  
 
programming4us programming4us