Using a C++ library in C#
-
I need access to the parallel port, but as far as I can tell it isn't possible. But, in c/c++ it's really easy... Now, I want my application to be in C#... so would I be able to make c or c++ library and be able to use it in my C# app? I already tried the NTPort library. But it costs money and it has alot of features I don't even use in it... I have no clue how they get it to work... So, is a C/C++ library (DLL) possible? Or, is it just possible to do it straight though C# in some werid way I haven't found??? /\ |_ E X E GG
-
I need access to the parallel port, but as far as I can tell it isn't possible. But, in c/c++ it's really easy... Now, I want my application to be in C#... so would I be able to make c or c++ library and be able to use it in my C# app? I already tried the NTPort library. But it costs money and it has alot of features I don't even use in it... I have no clue how they get it to work... So, is a C/C++ library (DLL) possible? Or, is it just possible to do it straight though C# in some werid way I haven't found??? /\ |_ E X E GG
Yes you can use C++ functions from C# as long as they are exported from your C++ DLL. The function prototype in C# will look like this:
[DllImport("my.dll")]
public static extern int MyFunction(string param1, int param2);You can check this MSDN arcticle for details: Consuming Unmanaged DLL Functions[^] Alexandre Kojevnikov MCAD charter member Leuven, Belgium
-
I need access to the parallel port, but as far as I can tell it isn't possible. But, in c/c++ it's really easy... Now, I want my application to be in C#... so would I be able to make c or c++ library and be able to use it in my C# app? I already tried the NTPort library. But it costs money and it has alot of features I don't even use in it... I have no clue how they get it to work... So, is a C/C++ library (DLL) possible? Or, is it just possible to do it straight though C# in some werid way I haven't found??? /\ |_ E X E GG
Complie the C/C++ project with the /clr switch and place the main methods you intend using in a psuedo MC++ class. That class will be accessible in .NET. leppie::AllocCPArticle(Generic DFA State Machine for .NET);
-
Yes you can use C++ functions from C# as long as they are exported from your C++ DLL. The function prototype in C# will look like this:
[DllImport("my.dll")]
public static extern int MyFunction(string param1, int param2);You can check this MSDN arcticle for details: Consuming Unmanaged DLL Functions[^] Alexandre Kojevnikov MCAD charter member Leuven, Belgium