Eshani

Hi All,

I am new in pocket PC coding.

I am working on PDA and reading data serially on PDAwhich I hv to store in Pocketword.

I am using SDK PocketPc2003 and using Win32 functions and not MFC to create dialog box, create and write file etc.


I am reading serial data which is hex (unsigned char)string I am converting it in w_char using wsprintf()and displaying on text box and msg box. Till this point everything is ok but when I am trying to save this in a txt file on PDA the data is saved in the file but if we open the file in pocket word can see only first character. If I download this file on PC then I can see the data which is saved. I read somewhre that pocket word requires data in char I tried casting btu no success so far
Please help me to diaplay on pocket word without use of MFC/CString.

Also I am appending the next data rad in the same file. I want to append this nex read data in the next line on the file but don't know how to procede. Please help.

Thanks,
Eshani



Re: Smart Devices Native C++ Development cannot display on pocket word

Saravanan V V

Hi Eshani,

Yes Pocket PC Word supports char only.

I think you are using Widechar Version of APIs (like _wfopen) to open and write the files.

Use the character version of API like fopen,fwrite to save the file.

Hope this helps you.





Re: Smart Devices Native C++ Development cannot display on pocket word

Eshani

Hi Saravanan,

Thanks for the quick reply. Yes you are right I am using a wide char string.

I am using CreateFile(), SetFilePointer() and WriteFile() of win32API.

My data is in string LPWSTR. I am casting this into LPSTR and then converting into char using the code below.

static unsigned short Buffer[1000] = {0}; // unicode buffer
unsigned short *pwc = &Buffer[1000];

LPSTR BytePtr;
char c,tagWrc[512] = {0};

BytePtr = (LPSTR)pwc;

leng = wcslen(pwc);
for(int z=0;z<=leng;z++)
{
tagWrc[Z] = *BytePtr++;
}
int len = sizeof(tagWrc);
TagWrite(tagWrc);

My received data is in Buffer and this data is to be saved in a file.

where Tag write is the function used to write the data in a file on PDA and is using WriteFile() as below.

WriteFile(FileHandle, tagWrc, len * 2, &BytesWritten, NULL);

Still I get the first char only on pocketwordSad

Please guide as I am not getting where I am going wrong. This will be great help.

Thanks,

Eshani





Re: Smart Devices Native C++ Development cannot display on pocket word

Saravanan V V

Hi

You can save the file in this format. So no need to convert the wide char to char using the fwprintf just write the widchar buffer itself.

FILE *lfp;

lfp = fopen("TEST.txt","w+");

if(lfp)

{

fwprintf(lfp,L"Test 1234");

fclose(lfp);

}

Hope this helps




Re: Smart Devices Native C++ Development cannot display on pocket word

Eshani

Hi Saravanan,

It working now Smile. I can display on pocket word properly.

I literally spent 3-4 days on reading stuff on unicode conversion still didnt get sucess. Now I am happy.

Thank you so much for such a gr8 help. I will remember this always Smile

Regards,

Eshani





Re: Smart Devices Native C++ Development cannot display on pocket word

Eshani

Hi Saravanan,

Need another help.

After your help I am saving the read string in a file using fwprintf.

Now I have to save only unique strings, means I have to read the string and copmare it with the strings in the file and if the read string is not present in the file I have to save it.

I tried using a buffer where I am copying the strings which I am saving in a file and making the string comaprison with this buffer but its not working. As my buffer data is not saved till my next loop.

I am using below code for main loop


int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{MSG msg;
// application initialization
if(!InitInstance (hInstance, nCmdShow)) return FALSE;
// main message loop
while(GetMessage(&msg, NULL, 0, 0))
{TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam; // GetMessage(&msg, NULL, 0, 0))
}

Also I hv defined the buffer as static variable..also tried using extern keyword but no use.

Then I tried one more method that is readin the file and comparing the string before saving in the file.

but I guess there is problem with unicode conversion again as it always gives difference in the strings even if same string is written in the file and read again after changing the file pointer to earlier state.

Please help.

Thanks,

Eshani





Re: Smart Devices Native C++ Development cannot display on pocket word

Saravanan V V

Hi

Check the below snippet. Hope this helps you

FILE *lfp;

lfp = fopen("TEST.txt","w+");

if(lfp)

{

fwprintf(lfp,L"Test 1234");

fclose(lfp);

}

lfp = fopen("TEST.txt","r+");

if(lfp)

{

fseek(lfp,0,SEEK_END);

long lFileSize = ftell(lfp);

fseek(lfp,0,SEEK_SET);

char *lFileBuffer = (char *)malloc(sizeof(char)*(lFileSize));

memset(lFileBuffer,0,lFileSize);

fread(lFileBuffer,sizeof(char),lFileSize,lfp);

//compare the strings

if(strstr(lFileBuffer,"1234"))

MessageBox(NULL,L"Stingfound",L"Result",MB_OK);

free(lFileBuffer);

lFileBuffer = (char*)NULL;

fclose(lfp);

}

Note: Please mark the post as useful if you find it useful.





Re: Smart Devices Native C++ Development cannot display on pocket word

Eshani

Hi Saravanan,

Thank you once again for quick reply.

Your code works totally well.

Anyways let me tell you my problem though its silly.

I am receiving hex data in a buffer StrgrecBuff then I am converting it to unicode using wsprintf to display on PDA text box. and to save it in a file I am using fwprintf as suggested by you.

Now problem is my data is hex and I can't receive it in char buff which is requirement of strstr.

My code is given below. please help.

FILE *lfp;

lfp = fopen("Test.txt","a+");

static unsigned char StrgrecBuff[100] = {0};

int a =0,b=0,Code; // code gives the no. of bytes received

for (int e=0; e<=Code; e++)
{
a+= wsprintf((LPWSTR)Temp1 + a,L"%x",StrgrecBuffEmail);

b+= wsprintf((lfp,L"%x",StrgrecBuffEmail);
}
MsgBox((LPWSTR)&Temp1)

How should I use this %x string.

Thanks,

Eshani





Re: Smart Devices Native C++ Development cannot display on pocket word

Eshani

Hi Saravanan,

I got the solution. I am using sprintf to convert my recived hex("%x") string into char string and then passing this to strstr.

Its working now.

Thank you very much.

Regards,

Eshani