|
-
September 2nd, 2009, 05:18 AM
#1
C# and C++ Data Type
Now I am writing C sharp programs which will interact the events from application gateway in network socket programming.
The interface in the application gateway is in C++.
Is it possible that I use C Sharp?
Moreover, as to the data types in C++, how to match these in C Sharp?
especially in uint.... in C++, but how about in c sharp??
-
September 2nd, 2009, 10:28 AM
#2
Re: C# and C++ Data Type
You will need to use PInvoke in order to invoke C/C++ libraries from C#. The datatypes will be marshaled as needed by the P/Invoke layer but you will still need to have a good idea of what they are in C#.
MSDN on PInvoke
http://msdn.microsoft.com/en-us/library/aa719104%28VS.71%29.aspx
You may also be able to find more information on it elsewhere. Its pretty easy to do if your not passing complex data structures around. The easiest way Ive found to find a particular size for a datatype in C# is to find its size in C++ using sizeof(), see how many bytes it is, and then use an equivalent in size data type in C#. Just make sure you use the proper signed or unsigned type. Also, bit fields get tricky but you can usually substitute a single System.UInt32 value for them and just set the bits of the UInt32 manually to get what you want. Its sort of tough to explain but if you need help with it just post again
Last edited by RaleTheBlade; September 2nd, 2009 at 10:31 AM.
R.I.P. 3.5" Floppy Drives
"I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones." - Albert Einstein
-
September 2nd, 2009, 11:18 AM
#3
Re: C# and C++ Data Type
If you're P/Invoking native libraries then bear in mind that the size of those native types can change depending on the platform. So it's not enough to check the sizes on your local machine, you need to know what the machine you'll be operating on is using.
www.monotorrent.com For all your .NET bittorrent needs
NOTE: My code snippets are just snippets. They demonstrate an idea which can be adapted by you to solve your problem. They are not 100% complete and fully functional solutions equipped with error handling.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|