tags:

views:

190

answers:

3

I have a structure say for an example

typedef struct { DWORD time; BYTE* message; DWORD size; } ACCP_MESSAGE_COMMAND_PARAM_T;

Now this is common to both master and client end and through master we r requesting to client with the following data 20,"MessageRequest",30.

Now at client side i want to display the message which is requested by master using %s. But i am able to display only through %c not by %s.. Moreover if iam converting BYte* to LPCWSTR how should i achieve? Bcz whenever i am doing so it throws an exception..

Please Reply Thanks Abhineet Agarwal

A: 

Are you sending the string in unicode? There is no TEXT() macro surrounding the string so I guess not. Try to print it with %S.

Shaihi
Abhi
Does the message contain the termination? What is the size used for?Why don't you pass LPWSTR in the first place?
Shaihi
Is the message sent as widechar in the first place? Look in the debugger how each character is represented. A wide char should occupy 2 bytes.
Shaihi
Did you try and look at this: http://msdn.microsoft.com/en-us/library/bb202786.aspx
Shaihi
At first i took LPCWSTR msg = L"MessageRequest";then I stored the above value at MessageRequest.message=(BYTE*)msg;
Abhi
The above i have done at master side
Abhi
After that at client side i recieve this message in BYTE* form.
Abhi
Now my task is to print this message.. But the problem which i m getting is that i am not able to print in %s form Secondly i am not able to typecast in LPCWSTR type. if i do so i get an exception..
Abhi
Yes it occupy 2bytes
Abhi
I am not too familiar with WinMo and it's WinCE 5 core. Are you sure the client can access the whole buffer without access violation? The seems that there are no problems if you can print it char by char. I'm just laying my thoughts here.
Shaihi
No actually we have to dump that message on a particular place say for an example MessageStatus window so in that case %c concept will not work out.Plz replyThanks
Abhi
Maybe it is me being thick headed, but can you updated the question stating exactly what it is you are doing (MFC, the code at the server, the code at the client + anything else that may be helpful). That way even if I can't see the problem someone else will find it easier to find it.
Shaihi
See there is master end and client endAt mAster endthere is a function which makes request to clientbool MessagePackageReq(BYTE scrap){ LPCWSTR msg = L"MessageRequest"; ACCP_MESSAGE_COMMAND_PARAM_T MessageRequest; MessageRequest.size = 30; MessageRequest.message = (BYTE*)msg; MessageRequest.time = 40; DWORD cmdid; INT value,target,kind; LPVOID param = target = ACCP_APP_1SEG; kind = ACCP_CMD_CON_MESSAGE; if(req) { value=req( if(value == 0) return true; } return false;}
Abhi
And at client side there is a call back function
Abhi
INT accp_callback(INT message, DWORD id, INT app_kind, LPVOID param){ switch(message) {
Abhi
case ACCP_MSG_CON_MESSAGE: { ACCP_MESSAGE_COMMAND_PARAM_T * par = (ACCP_MESSAGE_COMMAND_PARAM_T*)param; for(UINT i=0;i<((par->size)/2);i++){ RETAILMSG(1,(TEXT("%c"),*par->message)); m1[i] =*par->message; par->message = par->message + 2; } RETAILMSG(1,(TEXT("Message =%s, Size = %u, Time = %u\n"),m1,par->size,par->time)); res(id, app_kind, message - ACCP_CMD_NUM, NULL);}
Abhi
Here m1 is a global variable of type BYTE m1[100];
Abhi
I'll read this soon, but it better to update the question itself and not add this data as comments
Shaihi
Try to make the msg variable global or allocate it using malloc. I think you have a problem with leaving the scope of the allocated msg.
Shaihi
Why don't you use a msgqueue? http://msdn.microsoft.com/en-us/library/ms885180.aspx
Shaihi
I can't help more than this. Update the question describing what you are trying to achieve and what you have done so far. Then post the code you use now with the line that causes the exception.
Shaihi
ok thanksAbhineet Agarwal
Abhi
+1  A: 

You need to read up on Unicode. Your data in your question ("MessageRequest") is not the same as in you comments (L"MessageRequest"). They are way different, and you need to understand that. Look at the memory view to see how they are layed out.

You've not said how you want to "display" the message, but if it's still Unicode, and the client is CE-based, then there's nothing to do. CE only uses Unicode for all of it's APIs. If its the desktop, use a Wide ("W" suffixed) API, or #define UNICODE in your app. Or convert it using wcstombs or WideCharToMultiByte.

ctacke
A: 

Well i got the solution for it.

If you want to convert BYTE* to LPCWSTR other than using WideCharToMultiByte then we can use in the following way:

BYTE * message; 
message="MessageRequest";
WCHAR msg[100]; 
msg = (WCHAR)message; //Copy "message" content into "msg" .
LPCWSTR msg1;  //Taken variable of LPCWSTR type 
msg1=(LPCWSTR)msg;

And then display it using DrawText(...); on the window And u will be able to see proper message.

Abhi
This assumes that the BYTE* points to data that is already wide character, not multibyte, so this is *not* the same thing. In fact you could have just cast the BYTE* to a TCHAR*, or done a simple memcpy to your new location.
ctacke
No there was some problem in dll because of which i was getting problem so on doing in above method my problem was solved. the byte* value was imported from the dll which was displayed in %s way only through the above method. Anyway the comment which u send is absolutely right when i checked for the other examples other than my dll which was creating problem for all the method.
Abhi