(1) chaos caused by a task -- conversions between struct and byte [] in c #

Source: Internet
Author: User

A job involves the udp communication between c # And c ++ systems. It has not completed the job for a long time, but has encountered many small knowledge points. I have never been familiar with c # And c ++ languages. Everything may be a child, and it will be recorded as a work diary for the time being.

First, solve the topic of this article: The structure and byte [] in c # are converted to each other to help the people who have accessed it solve the problem. During the work task, we learned the conversion between struct and byte [] in c. The Code experiment is as follows:

                                   [] StrutsToBytesArray(                            size =                          [] bytes =                            IntPtr structPtr =                          Marshal.StructureToPtr(structObj, structPtr,                           Marshal.Copy(structPtr, bytes,                                                                BytesToStruts(                            size =                           (size >                                                               IntPtr structPtr =                          Marshal.Copy(bytes,                            obj =                                                                    packindex;               type;               length;              [] data;             Main(              Program p =              udp_data sd =              sd.packindex =              sd.type =              [] btmp = Encoding.UTF8.GetBytes(             sd.data =             sd.length =             [] structToB = StrutsToBytesArray(sd);             udp_data byteToStru = (udp_data)BytesToStruts(structToB, sd.GetType());                     }

[Running result ]:
1

0

9

Hi!

This job is probably A system A written in c # On Windows. A message is sent to system B by system B.

The difficulty is that the API provided by system B is a file written in c ++ in Linux, and the code written in c # in Windows is used in our system. The API only contains header files and library files, and cannot be converted to usable dll files without source code. So this API is voided.

So we want to adopt a roundabout strategy to send messages to a C system, because they also have the mail service to process and then send the messages to system B to send emails. The C system also provides an API. This time it is also a file written in c ++ in Linux,

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.