none
[Interrop Cpp / C#] Looking for the bible... RRS feed

  • Question

  • Hi,

    I'm a bit fed up to look for some content for hours and end up with nothing which is why I'm posting here...

    I have some C modules with some custom types that I want to be able to use in C#. After some research, I started something using DllImport, but it seems not to be the best choice as I have no clue on how my variables are handled in the Unmanaged C++ Dll...

    I then assumed that the best way to do that was to make a C++ managed Class to do the link between the modules and the C#. My problem is that I can't manage to find some clear explanations on how to do that: No detail in MSDN Library and all other sources I founded were rather confusing.

    My question is simple: Is there any Bible for developping these kind of things (ie using C++ managed in C#)?
    If not: Is there anyone here who knows the subject and can share his knowledge ?

    Thanks in advance!
    Tuesday, September 1, 2009 1:52 PM

Answers

  • I'm not aware of any general interop books, MSDN magazine had a pretty good article on it a a while ago though. interop between C# and C usually using dllimport isn't usually that bad however it does require a good understanding on how things work on both sides of the fence, if a structure is being passed it really helps if you are able to visualize what that should look like in memory and point the debugger at a pointer you're getting to check if what you are getting matchs what you think you should be gettings.  If you're only comfortable on one side you'll mostlikely end up in frustration.

    The managed Extentions for C++ are documented rather well over here and contains a couple of samples on doing interop here 

    If you have any specific questions feel free to ask.
    • Marked as answer by eryang Monday, September 7, 2009 6:22 AM
    Tuesday, September 1, 2009 4:21 PM
  • You can also get information about COM Interop and type importing (using the type import tools: tlbimp.exe) from: http://msdn.microsoft.com/en-us/library/kew41ycz(VS.71).aspx There is also a wiki that has information about pinvoke signatures and a tool that plugs into visual studio and has information about user defined types and calling of other unmanaged APIs from managed code: http://www.pinvoke.net/
    • Marked as answer by eryang Monday, September 7, 2009 6:22 AM
    Tuesday, September 1, 2009 11:43 PM

All replies

  • I'm not aware of any general interop books, MSDN magazine had a pretty good article on it a a while ago though. interop between C# and C usually using dllimport isn't usually that bad however it does require a good understanding on how things work on both sides of the fence, if a structure is being passed it really helps if you are able to visualize what that should look like in memory and point the debugger at a pointer you're getting to check if what you are getting matchs what you think you should be gettings.  If you're only comfortable on one side you'll mostlikely end up in frustration.

    The managed Extentions for C++ are documented rather well over here and contains a couple of samples on doing interop here 

    If you have any specific questions feel free to ask.
    • Marked as answer by eryang Monday, September 7, 2009 6:22 AM
    Tuesday, September 1, 2009 4:21 PM
  • You can also get information about COM Interop and type importing (using the type import tools: tlbimp.exe) from: http://msdn.microsoft.com/en-us/library/kew41ycz(VS.71).aspx There is also a wiki that has information about pinvoke signatures and a tool that plugs into visual studio and has information about user defined types and calling of other unmanaged APIs from managed code: http://www.pinvoke.net/
    • Marked as answer by eryang Monday, September 7, 2009 6:22 AM
    Tuesday, September 1, 2009 11:43 PM