473,587 Members | 2,412 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

variable Bytes question

hi, to get the bytes sent by a socket, in VB a simple local variable like
below was used

Dim recv as Byte()

how can i do that in C++...this is what i am trying now

Byte * rec[] = new Bytes;

but i get these errors:

x:\User\FinalPr oject\Battleshi p\NewGame.h(180 ): error C2691: 'unsigned char
__gc *' : invalid type for __gc array element
x:\User\FinalPr oject\Battleshi p\NewGame.h(180 ): error C2061: syntax error :
identifier 'Bytes'

how can i get the bytes variable so i can receive the text sent by the other
connected socket? thanks

--
-iwdu15
Jan 9 '06 #1
5 1151
this will give you a simple array of bytes.

Byte test[] = new Byte[1];
Byte test2 = 'A';

test[0] = test2;
kind regards,
Bruno.
"iwdu15" <jmmgoalsteraty ahoodotcom> wrote in message
news:E7******** *************** ***********@mic rosoft.com...
hi, to get the bytes sent by a socket, in VB a simple local variable like
below was used

Dim recv as Byte()

how can i do that in C++...this is what i am trying now

Byte * rec[] = new Bytes;

but i get these errors:

x:\User\FinalPr oject\Battleshi p\NewGame.h(180 ): error C2691: 'unsigned
char
__gc *' : invalid type for __gc array element
x:\User\FinalPr oject\Battleshi p\NewGame.h(180 ): error C2061: syntax error
:
identifier 'Bytes'

how can i get the bytes variable so i can receive the text sent by the
other
connected socket? thanks

--
-iwdu15

Jan 9 '06 #2
but then wat if wats received is ghreater than 100 bytes? the vb declaration
didnt have a constraint....i s there anywasy to do that or do i have to limit
how much i send?
--
-iwdu15
Jan 10 '06 #3
iwdu15 wrote:
but then wat if wats received is ghreater than 100 bytes? the vb declaration
didnt have a constraint....i s there anywasy to do that or do i have to limit
how much i send?


100 bytes? Bruno's example was a one byte array. But anyway, the trick
to not overflowing an array is to not read more bytes than can fit in it.

doug
Jan 10 '06 #4
if possible, always work with a fixed buffer size.
this will be more performant than always allocating and de-allocating buffers.

i don't know what you intend to send, but if it is not too much, just
allocate an array that will always be big enough. use a 1 MB buffer if that
solves you problem.
IMO that is a much better solution than having to manage variable length
buffers.

having to add xxx lines of memory management code to save a few bytes of
data is not worth it in most cases.
but in all cases, check the array size before you write data to it.

kind regards,
Bruno.

"iwdu15" wrote:
but then wat if wats received is ghreater than 100 bytes? the vb declaration
didnt have a constraint....i s there anywasy to do that or do i have to limit
how much i send?
--
-iwdu15

Jan 10 '06 #5
ok, thanks alot
--
-iwdu15
Jan 11 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3174
by: Anoop | last post by:
Hi guys i have a piece of code main() { switch(...) { case 1: {
6
1342
by: Prawit Chaivong | last post by:
Hi All I don't know whether I should post this thing to compiler group or this group. Anyway, I decided to post to this group. (I'm sorry if you think I post in wrong group) My question is... I wrote the program like this. void func()
8
5016
by: Groups User | last post by:
C allows type casting in which a variable is converted from one type to another. Does C (whatever standard) allow the type of a variable to change, within a statement, avoiding the conversion? And if so, provide an example of how its done. Example: int a=23; int b=34;
14
5821
by: Luiz Antonio Gomes Pican?o | last post by:
How i can store a variable length data in file ? I want to do it using pure C, without existing databases. I'm thinking to use pages to store data. Anyone has idea for the file format ? I want to store data like a database: ---------------------------------- Custumer:
1
3264
by: Shawn | last post by:
As if it won't be clear enough from my code, I'm pretty new to C programming. This code is being compiled with an ANSI-C compatible compiler for a microcontroller. That part, I believe, will be irrelavent. My syntax is surely where I am going wrong. I'd like to be able to call this routine to read different values from another device. ...
20
225005
by: Manuel | last post by:
hi, I have a problem, a stupid problem. I can't declare a variable of type byte. The g++ said that i have syntactic error in this line. The code is this: byte * variable; well, i think that the mistake is a stupidity but i don't find it. where is it?
29
4221
by: Martin | last post by:
For reasons I won't go into, I need to transfer from 1 to 3 bytes to a variable that I know is 4 bytes long. Bytes not written to in the 4-byte target variable must be zero. Is the following use of memcpy() a well-defined way of so doing? The code is written knowing that sizeof(unsigned long) == 4 in this instance. The code is somewhat...
3
4048
by: chandra.krothapalli | last post by:
Hi, I am writing a program to read database logs using db2Readlog/ db2ReadLogNoConn API. I am able to parse the data of "FIXED format data" and link them to appropriate columns for a given UPDATE/INSERT/DELETE. I am having difficulty in parsing the "Variable format data". In the log record I am not able find information about data...
11
21633
by: EricGoogle | last post by:
Hello All, I am trying to figure out a how to get a variable's name from code. Ex: var MYVAR = 3; alert( ????? ); OUTPUT: "MYVAR"
0
7843
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8206
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7967
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5713
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5392
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3840
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.