473,320 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Problem converting from char* into BYTE

hello,
i'm trying to recieve some binary data on a socket and then decode it,
to decode my data i'm using a dll library, my problem is that the function i need in my library to decode my message takes as input and output arguments BYTE messageDecode( BYTE inmessage, BYTE outmessage),
But to read my data through the socket i have to use a char * because i'm using; nBytes = recv(soc, tempBuffer + offset, 1000, 0); where tempBuffer is char *.
Here is a sample of the code i'm trying to use but still when i print the recieved buffer i get something but when i print it after passing to constr unsigned char* i get nothing:
Expand|Select|Wrap|Line Numbers
  1. bool Sockets::ReadData( SOCKET soc , char *tempBuffer )
  2. {    
  3.     bool ret = true;
  4.     int offset = 0;
  5.     int nBytes = 0;
  6.     unsigned char *const outBuffer="";
  7.     while( 1 ) 
  8.     {
  9.         nBytes = recv(soc, tempBuffer + offset, 1000, 0);
  10.         nret = WSAGetLastError();
  11.         if( nret == WSAECONNRESET ) 
  12.         {
  13.                 ret = false;
  14.                 break;
  15.         }
  16.         else if (nBytes == 0) 
  17.         {
  18.                 ret = false;
  19.                 break;
  20.         } 
  21.         else if (nBytes == -1) 
  22.         {
  23.                 break;
  24.         }
  25.         else 
  26.         {
  27.                 offset += nBytes;
  28.         }
  29.     }
  30.  
  31.  
  32.     if( offset > 0 )
  33.     {
  34.         unsigned char *const utempBuffer = (unsigned char *const)tempBuffer;// i guess this cast is wrong
  35.  
  36.  
  37.  
  38. DecodeMessage_byte(utempBuffer, offset,outBuffer);/* Here is my function from the library*/
  39.  
  40.     return ret;
  41. }
  42.  
Dec 12 '07 #1
2 2981
weaknessforcats
9,208 Expert Mod 8TB
You are certain that BYTE and unsigned char* are the same thing???

I mean usually a BYTE is a char.
Dec 12 '07 #2
Do not try to convert this into byte .Read char one by one from the offset variable when you recieve .And then print each charcter.

This is because if you use encoder/decoder then it will change the binary form of character which will not be usefull to you.

I have done this to transfer the image data from client to Server and successfully working.

Rakesh Setia
Dec 23 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: matt melton | last post by:
Hi there, I am trying to write a method that accepts an array of any primitive type and will return the same array without copying memory as an array of bytes. ie. I'd like to be able to do...
5
by: c duden | last post by:
I am attempting to encrypt some text and be able to decrypt it at a later time. I have two methods to do this: public static Byte EncryptText(string textToEncrypt, string encryptionHash) {...
4
by: vertigo | last post by:
Hello I have: struct packet{ byte type; /*my byte is unsigned char*/ int len; } struct packet *p = new struct packet; p->type=10; p->len=0;
7
by: john | last post by:
On my form i have a message box called txtItemDesc that displays the french phrase qualité Père Noël. Now then when i run this code on that text box: Dim chrArr() As Char chrArr =...
1
by: SloppyCoder | last post by:
I am having a problem preparing a UTF8 string for IPP (internet printing protocol) transmission. Converting integers until 639 goes well, but beyond this, in case of 640, results in an extra...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
39
by: Martin Jørgensen | last post by:
Hi, I'm relatively new with C-programming and even though I've read about pointers and arrays many times, it's a topic that is a little confusing to me - at least at this moment: ---- 1)...
4
by: HackerisNewKnight | last post by:
Hello, 1) First problem. In my project i need to convert from char* to BYTE*( BYTE is unsigned char), is there any way to make the convertion? BYTE* bite; char* ch="help me, please"; bite =...
12
by: cmdolcet69 | last post by:
Can anyone give me some ideas on how to convert the following program to vb 2003? I would like to jsut take this code and implement it in vb. def.h /* Global Type Definitions */ typedef ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.