How to convert Byte* to LPCWSTR in wince6.0? - windows-ce

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

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.

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.

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.

Related

converting an address from a char type to a ip6addr in Contiki-NG

I'm sending an IPV6 address in a packet data section, that is beside the sender and receiver addresses.
I did convert it to a char using uiplib_ipaddr_snprint() and added it to the package and sent it.
Everything is working perfectly, I managed to cut the address from the data, however, I'm having trouble converting it using uiplib_ip6addrconv() but when I try to print the address is empty!
I'm not sure where the error is, but in regards to string manipulations I think everything is working correctly, the address is printed in the string form correctly, however, the converting doesn't seem to be working and I'm not sure why, any help is appreciated it.
This is how I get the address from the data of the packet, and p contains the correct address, then try to convert it to an ip6addr where things doesn't work.
Thank you.
int size = 40;
char *p;
p = strstr(str,"fe");
printf("%s\n", p);
const uip_ip6addr_t *addr_2;
uiplib_ip6addrconv(p, addr_2);

Write float value in Node buffer

I am reading sensor data and I need to send these data via bluetooth so I am using noble/bleno library to subscribe data every time the value change. Here I am confusing how to send data as a buffer.
I have data something like value = 24.3756
So I need to write this in buffer:
let buf = new Buffer(2);
buf.writeIntLE(buf);
But when I convert to ArrayBuffer value shows only 24 (not getting after decimal point)
How to send full float value and read as array buffer ?
First of all please read Buffer documentation here.
Then please don't use deprecated functions. If you need to create a new buffer use Buffer.alloc or Buffer.allocUnsafe. When you're creating buffer ensure that it can hold the data you want to write there. Next please use a suitable method for writing data. You're writing floating point number, then you have to use Buffer.writeFloatBE/Buffer.writeFloatLE. If you do everything I mentioned you'll end up with a correct solution:
const buffer = Buffer.allocUnsafe(4);
buffer.writeFloatLE(24.3756);

Arduino read get values after ? in url with ethernet shield

Sorry if it has been asked before but I cannot find anything on the internet. I just want to host a page in arduino ethernet shield and when I visit it from a browser with Get parameters (e.g http://xxx.xxx.xx.xx/led.html?red=255,green=0,blue=255) to change to change the led's color. I cannot find how to send data from browser to arduino.
The answer involves the use of The Ethernet Library (Ethernet.h) - which provides an interface to Client and Server, a degree of conceptualizing low-level I/O and buffering the input, and context.
In the following code snippet ( of the sample code at http://arduino.cc/en/Tutorial/WebServer )
...
char c = client.read();
Serial.write(c);
...
the line char c = client.read() is taking a byte from the request stream and assigning it to a char type, it is then serialing that charbyte to a string where it perform conditional logic on it.
The conditional logic of that sample only cares about reading whether a return character \n on a blank line, but the bytes that are being read (on each iteration) byte to byte, actually compose the RAW Request.
At minimal, a RAW HTTP GET Request looks like this:
GET /?first=John&Last=Doe HTTP/1.1
Host: localhost
So, for you to read the query string, you'll need to buffer the bytes being read from the stream.
Then, you'll likely serialize the whole buffer into a string, and perform string operations on them, as well as your conditional logic....

Is there anything like GetDlgItemInt but for a Window that has been created? Win32 Api

Using C++ Win32 API, I've created a window ( CreateWindow() ) instead of a dialogue box. Are there any commands similar to "GetDlgItemInt" or "SetDlgItemInt" that is used for getting and setting data in an edit window for Win 32 API instead? Otherwise I'll have to make a dialogue box or do a heap of code for converting INTs to a string then back again.
The idea is that the user specifies the window width and height by typing in the two edit dialogue boxes within the window I have created. There are nice easy tutorials that basically tell me how to do that through a dialogue box, but I would like to know if there are similar functions that I can use that are not dependent on a dialogue box?
I'm hoping to have something like this...
xVal = 1280;
yVal = 720;
hwndResoX = CreateWindow("edit",xVal, WS_CHILD|WS_VISIBLE|WS_BORDER|ES_NUMBER,20,20,40,20, _hwnd, NULL, NULL, NULL);
hwndResoY = CreateWindow("edit",yVal, WS_CHILD|WS_VISIBLE|WS_BORDER|ES_NUMBER,80,20,40,20, _hwnd, NULL, NULL, NULL);
But as you can imagine, I can not use the xVal or yVal in the CreateWindow() because I get a compile error stating I can not convert from INT to CHAR*
Simplest way to do this:
// Create the window. Note that for edits, the caption is not the same as its contents,
// so we leave that empty here:
hwndResoX = CreateWindow("edit","", WS_CHILD|WS_VISIBLE|WS_BORDER|ES_NUMBER,20,20,40,20, _hwnd, NULL, NULL, NULL);
// Now create a string to use to set as the content:
char content[32];
sprintf(content, "%d", xVal); // Recommend using StringCchPrintf if there's any chance that the buffer size might be too small
SetWindowText(hwndResoX, content);
See also this MSDN page on Using Edit Controls.
For getting the data back, use GetWindowText to get a string, then parse that using whichever string-to-int parsing function you want (eg. strtol, atoi, sscanf, etc.)
While you do have to convert manually between int and string, it's not all that much code, just a couple of extra lines, so a lot less hassle than converting to use a dialog.
Having said that, if you use a proper dialog here, you get a couple of extra benefits: notably the user can tab from field to field automatically, which you have to do extra work to enable in a non-dialog.
You can use GetDlgItemInt, just specify an int ID for the HMENU parameter in CreateWindow.

Append data to an IStream object

I am making calls to a web service to get data from my dll. I am getting the data in a char* object in parts.
I want to get the whole data into an IStream object. I am running a while loop and getting the data into char* object. Can someone please tell me how I can combine all this data into a single IStream or LPSTREAM object.
Thanks
Never got an answer for this one! Can someone please help!
Ok I thought I'd answer this one just to help out. You're making calls to another computer so I'm assuming that you are reading in streams of data in char*'s. That's what I get from a comment like "I am getting the data in a char* object in parts."
Therefore, as I understand it, you just want to append the char* string to the IStream object so that it holds the new data.
My suggestion would be to do this:
Create a streambuf object (http://msdn.microsoft.com/en-us/library/aa277891(VS.60).aspx)
While you are recieving packets
append the packet to the streambuf object (http://msdn.microsoft.com/en-us/library/aa277883(VS.60).aspx)
Create a IStream object and init it with the streambuf object (http://msdn.microsoft.com/en-us/library/aa277365(VS.60).aspx)
Now that should work I think. That will fill your IStream object with the stream you got from the website.
I hope that helps,
Robert

Resources