ok first..C# has support for unmanaged code (which your case will be) since you're writing it in C++ (but if you'll be using VC++, It will be managed then).
Now after creating the DLL file (and pls remember to save it as a .DLL), you'll use the
System.Runtime.InteropServices
(which handles managed-unmanaged code interoperability) namespace of .NET to do your import
so first..add the
System.Runtime.InteropServices
namespace to your code..
and then follow the code sample below..which imports a DLL named :
msvcrt
and access the
int
typed method in it named :
puts(string _c)
--remember that you do the DLL imports for each method called--
using System;
using System.Runtime.InteropServices;
class PlatformInvokeTest
{
[DllImport("msvcrt.dll")]
public static extern int puts(string c);
[DllImport("msvcrt.dll")]
internal static extern int _flushall();
public static void Main()
{
puts("Test");
_flushall();
}
}
but I must add that depending on what you want to do with the DLL, there are quite a number of things you can do (optional), such as
Marshalling
, assigning
Entry Point
, etc..So I would suggest you read some articles on it..There are loads of them online
If you like the above, Accept Answer and give a Vote.. :)