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,