Sign in to follow this  
  • entries
  • comments
  • views

On C# and C++

Sign in to follow this  


So, last night I got the urge to start fiddling with some networking code... sadly, I didn't get very far, in fact, I never got into the networking stuff. My first idea was, I'll make the networking library a DLL, then I'll make a small test bed application in C# and I'll get something going in no time. Boy was I wrong. All the hype around C# made me think that using C# with C++ (unmanaged) libraries was straightforward. Perhaps it's just that the information I found is not accurate. But it's something like this:

// Import the creation function with standard calling convention [ DllImport( @"MyDLL.dll", EntryPoint = "??CreateMyClass@@PFWR@Q", CallingConvention = CallingConvention.StdCall ) ]
public static extern IntPtr CreateMyClass();

Which is not too bad, although I do find it very annoying that I need to specify the decorated function name myself, this is something that the compiler should figure out, I guess it'll get better in next versions of the language (there's some talk about it being real easy in 2005), regardless, that part was annoying, but more annoying is that I apparently need to create a static function in my DLL called "CreateMyClass" that all it does is call new on MyClass and return it.

So, I found all this to be an insane amount of work for such a simple standalone test bed program, so I ended up going for a really simple Win32 app.

So I'm looking forward to going home tonight and just getting the Win32 stuff out of the way so that I can start playing with some net code.

And now, it's time for lunch.
Sign in to follow this  

1 Comment

Recommended Comments

If your function was declared with extern "C", its name wouldn't be decorated, i.e.:
extern "C" MyFunction()

Share this comment

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now