I am trying to figure out how to get the contents of a textbox text property into an unsigned char array. I have been researching this via google for a few days without any success unfortunately.
I was finally successful at converting an unsigned char array to a string that can be written to a label text property but cannot figure out how to do the reverse.
The successful code I wrote that writes the unsigned char array to a label control text property is...
I just cannot figure out how to use reinterpret_cas t to do the reverse, as in reading the text property back into an unsigned char buffer. I realize that the example given is using a label control, and for the reverse I will be using a textbox control.
Thank you for your time!
Gary Rubin
I was finally successful at converting an unsigned char array to a string that can be written to a label text property but cannot figure out how to do the reverse.
The successful code I wrote that writes the unsigned char array to a label control text property is...
Code:
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
ULONG BytesWritten = 0;
ULONG BytesRead = 0;
//Allocate a memory buffer which will contain data to send to the USB device
unsigned char OutputPacketBuffer[64];
//Allocate a memory buffer for the data which we will read from the USB device
unsigned char InputPacketBuffer[64];
unsigned int x;
unsigned char y;
y=0x41;
for(x=1;x<=10;x++){ //write test data into the buffer
OutputPacketBuffer[x]=y;
y++;
}
//0x83 is the "TOGGLE LED 4" command in the firmware
OutputPacketBuffer[0] = 0x83;
//Null terminator
OutputPacketBuffer[11] = 0x00;
// Output first 11 chars of the output buffer to label1 text property
std::string s( reinterpret_cast< char const* >( OutputPacketBuffer ),11) ;
label1->Text = gcnew System::String(s.c_str());
WinUsb_WritePipe(MyWinUSBInterfaceHandle, 0x01, &OutputPacketBuffer[0], 64, &BytesWritten, NULL);
WinUsb_ReadPipe(MyWinUSBInterfaceHandle, 0x81, &InputPacketBuffer[0], 64, &BytesRead, NULL);
// Output first 11 chars of the input buffer to label2 text property
std::string s2( reinterpret_cast< char const* >( InputPacketBuffer ),11) ;
label2->Text = gcnew System::String(s2.c_str());
}
Thank you for your time!
Gary Rubin
Comment