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 / .NET Framework / Interop / June 2005

Tip: Looking for answers? Try searching our database.

Socket Messages To/From Unmanaged Application

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Protege - 02 Jun 2005 16:27 GMT
Please note:  This is a repost.  It was necessary since my previous email
alias was not being monitored/managed.  Sorry.

Hello,

Once again, I am faced with the challenge of trying to send and receive
messages between a managed application (c#) and an unmanaged embedded
application (c code).

These socket messages are often nested structs.

In the past, I have resorted to byte-by-byte manipulation (i.e. hack).

Please help me find a better way.

Possible options:

1.  Purchase a product/library that can help with this (Can't find any).

2.  Write a Managed C++ wrapper (Have never done, and why learn now since
its being replaced by CLI/C++)

3.  Use some form of lightweight serialization that can be handled by both
platforms.

4.  Use StructLayout, MarshalAs, InPtr etc. (Ouch)

5.  Continue my normal byte-by-byte hack. (Doh)

I know others have run into a similar problem.  However, I've yet to see a
straightforward solution.

I'm really surprised that MS doesn't provide a Class in the .Net Fx to deal
with this.

Thoughts ?

Thanks,  Jeff
"Peter Huang" [MSFT] - 03 Jun 2005 07:41 GMT
Hi

Thanks for your options.
But can you describe your problem more detailed?
e.g.
What is your develop platform?
Did the the C# and C application is all on the embeded system?(You are
using compact framework)
What is your embeded system?(Win CE or pocket PC or else)
What is the concrete problem, which method you use in C# to send what
message to C program, and the C program did not receive and via verse.?
Did the problem occur in two unmanaged applications? You may have a try.

Please describe the problem more detailed, so that we can figure out the
problem?
Thanks.

Best regards,

Peter Huang
Microsoft Online Partner Support

Signature

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Protege - 03 Jun 2005 12:33 GMT
Hi Peter,

Thanks for getting back to me.

Sorry for not explaining my problem clearly.

My "problem" is an implementation issue not a technical one.  I can make it
work fine with byte-by-byte building of messages.  I am just trying to find
a better way.  Please note, this issue is not related to my specific
platform or code.  It's a generic interoperability issue many others have
surely faced.

I am sending and receiving messages between a managed server application
(c#) and an unmanaged embedded client application (c code).

The embedded client application is written in c and running on an RTOS (Non
MS).

The managed server application is written in c# running on WinXP.

The application messages sent over the socket are often nested structs.

Before c#, the server application was written in C/C++.  When the server
received messages from the client, all it had to do was look at a command
byte, and then cast the buffer to a message type.  Done.  Also, the server
and client could share the same header file that defined the message
structs.

Now, with c#, the managed server application cannot share the header file
with the client and cannot cast the received bytes to a message type.
Therefore, I am forced to redefine the messages in c# and build the received
message byte by byte (can't just cast).

Possible options for a better implementation:

1.  Purchase a product/library that can help with this (Can't find any).

2.  Write a Managed C++ wrapper (Have never done, and why learn now since
its being replaced by CLI/C++)

3.  Use some form of lightweight serialization that can be handled by both
platforms.

4.  Use StructLayout, MarshalAs, InPtr etc. (Ouch, this seems so tedious and
unsightly)

5.  Continue my normal byte-by-byte hack. (It works)

I know others have run into a similar problem.  However, I've yet to see a
straightforward solution.

I'm really surprised that MS doesn't provide a Class in the .Net Fx to deal
with this.

Thoughts ?

Thanks,  Jeff
"Peter Huang" [MSFT] - 06 Jun 2005 07:31 GMT
Hi Jeff,

Thanks for your quick reply.
Since C#'s safe and stong type feature, it can not cast the byte array into
a strucutre directly.
We need to use the Marshal, as your stated.
Here is a link.
http://groups-beta.google.com/group/microsoft.public.dotnet.languages.csharp
/msg/aca6bf0fbe973b67

For your concern, I think you may try to submit your wish to mswish
website, so that our specified team will evaluate your suggestion to
improve our product.
http://register.microsoft.com/mswish/suggestion.asp

Thanks for your understanding!

Best regards,

Peter Huang
Microsoft Online Partner Support

Signature

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Christian Ehlscheid - 12 Jun 2005 08:15 GMT
Hello,

i'm currently writing a C struct to C#/VFP class translator ..

if you want to get's hands on a late beta write me an email
(replace "nospam" with my lastname)

Regards
Christian

> Hi Peter,
>
[quoted text clipped - 53 lines]
>
> Thanks,  Jeff

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.