473,404 Members | 2,137 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,404 software developers and data experts.

how convert a buffer into a C# class

Hi all,
If I have a program wroten in C,and defined a struct like this:
typedef struct data
{
int m_i;
int m_j;
}data;

data myData;

I send Mydata to another program via Ethernet.Just like below:

SocketObj.Send(&myData,sizeof(myData));//assume SocketObj is a Object that
can send msg via Ethernet

and the receiver is wroten in C# or VC++ 7.0 . I define a struct in it
too:
__gc class data : public Object
{
int m_i;
int m_j;
}

But ,how can I fill this class from the stream I got from Ethernet?
I tried BinaryFormatter,but I found that BinaryFormatter's format is not
pure ,
It contains may additive information.So ,BinaryFormatter does not work.

Is there any other way to solve this problem?I do not want to use
XML,although XML does work.
Nov 17 '05 #1
1 1111
Hi !

The sender and the receiver must use the same protocol and handshaking
methods. For this purpose, I suggest that you find some Ethernet component
that works in both unmanaged programs and managed programs. This allows you
to build a consistent interface between the two worlds. After the component
has received the data, it can format it anyway you please to fit into the
managed structure.

From MC++, this is an easy step. In those code lines where you use the
component, wrap them into "#pragma unmanaged" sections. This creates an
unmanaged stub to ensure perfect compatibility with unmanaged components
inside a managed application. The C# process requires a COM proxy (P/Invoke)
unless the Ethernet component supports .NET.

-Antti Keskinen
"Jason Zhang" <jz****@sunrisetelecom.com.cn> wrote in message
news:uE**************@TK2MSFTNGP12.phx.gbl...
Hi all,
If I have a program wroten in C,and defined a struct like this:
typedef struct data
{
int m_i;
int m_j;
}data;

data myData;

I send Mydata to another program via Ethernet.Just like below:

SocketObj.Send(&myData,sizeof(myData));//assume SocketObj is a Object that
can send msg via Ethernet

and the receiver is wroten in C# or VC++ 7.0 . I define a struct in it
too:
__gc class data : public Object
{
int m_i;
int m_j;
}

But ,how can I fill this class from the stream I got from Ethernet?
I tried BinaryFormatter,but I found that BinaryFormatter's format is not
pure ,
It contains may additive information.So ,BinaryFormatter does not work.

Is there any other way to solve this problem?I do not want to use
XML,although XML does work.

Nov 17 '05 #2

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

Similar topics

1
by: Sam Smith | last post by:
Hi, I wan't a function to take a const char*, a start bit position and number of bits and convert that bit-stream into a primitive of desired type. I.e. something like: char convert(const...
3
by: MJB | last post by:
I'm getting an IStream back from function xmlHttp.responsestream. I would like to convert this to a System.IO.Stream in order to work with it in my application. Has anyone encountered this and...
6
by: Mimi | last post by:
Is there a way to convert int to byte easily? I want to write my int indexTbl to a MemoryStream but the MemoryStream class only accepts byte buffer. I have more than one int indexTbl to write...
9
by: Charles Law | last post by:
Suppose I have a structure Private Structure MyStruct Dim el1 As Byte Dim el2 As Int16 Dim el3 As Byte End Structure I want to convert this into a byte array where
12
by: Brian Henry | last post by:
first question... I have a flat file which unfortinuatly has columns seperated by nulls instead of spaces (a higher up company created it this way for us) is there anyway to do a readline with this...
3
by: David | last post by:
Hi, how to convert a char array(byte) to a string variable? byte buffer; string strTest; /*the blow codes all get type of 'buffer': System.Byte! strTest = buffer.ToString() strTest =...
5
by: bbb | last post by:
Hi, I need to convert XML files from Japanese encoding to UTF-8. I was using the following code: using ( FileStream fs = File.OpenRead(fromFile) ) { int fileSize = (int)fs.Length; int buffer...
3
by: GM | last post by:
Dear all, Could you all give me some guide on how to convert my big5 string to unicode using python? I already knew that I might use cjkcodecs or python 2.4 but I still don't have idea on what...
4
by: Neal Becker | last post by:
In an earlier post, I was interested in passing a pointer to a structure to fcntl.ioctl. This works: c = create_string_buffer (...) args = struct.pack("iP", len(c), cast (pointer (c),...
2
by: =?Utf-8?B?QmFydE1hbg==?= | last post by:
Greetings, I am working on a project where the interface from the UI application (done in C#) requires that an image buffer be passed back as a byte array as defined by an interface. The...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.