Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / March 2005

Tip: Looking for answers? Try searching our database.

how convert a buffer into a C# class

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jason Zhang - 02 Mar 2005 08:31 GMT
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.
Antti Keskinen - 03 Mar 2005 13:04 GMT
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

> Hi all,
>   If I have a program wroten in C,and defined a struct like this:
[quoted text clipped - 26 lines]
>   Is there any other way to solve this problem?I do not want to use
> XML,although XML does work.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.