文件名称:CsharpCallCppByCLI
介绍说明--下载内容均来自于网络,请自行研究使用
一 方法
C#的project调用C++的DLL,一般也有3中方法:
1)最简单的方法,通过PInvoke,但是只能调用全局function,不能调用Class。
2)通过COM封装调用。
3)通过CLI作为中介,也即本文章所讲的。
二 实例
1)假如我们有的Math的dll,
class CPPDLL_API Math
{
public:
static double Add(double x, double y)
static double Multiply(double x, double y)
}
class CPPDLL_API AdvancedMath
{
public:
static int Factorial(int x)
}
double Math::Add(double x, double y)
{
-failed to translate
C#的project调用C++的DLL,一般也有3中方法:
1)最简单的方法,通过PInvoke,但是只能调用全局function,不能调用Class。
2)通过COM封装调用。
3)通过CLI作为中介,也即本文章所讲的。
二 实例
1)假如我们有的Math的dll,
class CPPDLL_API Math
{
public:
static double Add(double x, double y)
static double Multiply(double x, double y)
}
class CPPDLL_API AdvancedMath
{
public:
static int Factorial(int x)
}
double Math::Add(double x, double y)
{
-failed to translate
(系统自动生成,下载前可以参看下载内容)
下载文件列表
CsharpCallCppByCLI
..................\CLIWrapper
..................\..........\app.ico
..................\..........\app.rc
..................\..........\AssemblyInfo.cpp
..................\..........\CLIWrapper.cpp
..................\..........\CLIWrapper.h
..................\..........\CLIWrapper.vcproj
..................\..........\CLIWrapper.vcproj.HSLCN.xhzhu.user
..................\..........\CLIWrapper.vcproj.ZHUXIAOH.xhzhu.user
..................\..........\Debug
..................\..........\.....\BuildLog.htm
..................\..........\MathWrapper.cpp
..................\..........\MathWrapper.h
..................\..........\ReadMe.txt
..................\..........\resource.h
..................\..........\Stdafx.cpp
..................\..........\Stdafx.h
..................\CppDLL
..................\......\CppDLL.cpp
..................\......\CppDLL.h
..................\......\CppDLL.vcproj
..................\......\CppDLL.vcproj.HSLCN.xhzhu.user
..................\......\CppDLL.vcproj.ZHUXIAOH.xhzhu.user
..................\......\Debug
..................\......\.....\BuildLog.htm
..................\......\ReadMe.txt
..................\......\stdafx.cpp
..................\......\stdafx.h
..................\CppTest
..................\.......\CppTest.aps
..................\.......\CppTest.cpp
..................\.......\CppTest.h
..................\.......\CppTest.rc
..................\.......\CppTest.vcproj
..................\.......\CppTest.vcproj.HSLCN.xhzhu.user
..................\.......\CppTest.vcproj.ZHUXIAOH.xhzhu.user
..................\.......\CppTestDlg.cpp
..................\.......\CppTestDlg.h
..................\.......\Debug
..................\.......\.....\BuildLog.htm
..................\.......\ReadMe.txt
..................\.......\res
..................\.......\...\CppTest.ico
..................\.......\...\CppTest.rc2
..................\.......\resource.h
..................\.......\stdafx.cpp
..................\.......\stdafx.h
..................\CsharpCallCppByCLI.sln
..................\CsharpTest
..................\..........\CsharpTest.csproj
..................\..........\Form1.cs
..................\..........\Form1.Designer.cs
..................\..........\Form1.resx
..................\..........\obj
..................\..........\...\Debug
..................\..........\...\.....\TempPE
..................\..........\Program.cs
..................\..........\Properties
..................\..........\..........\AssemblyInfo.cs
..................\..........\..........\Resources.Designer.cs
..................\..........\..........\Resources.resx
..................\..........\..........\Settings.Designer.cs
..................\..........\..........\Settings.settings
..................\CLIWrapper
..................\..........\app.ico
..................\..........\app.rc
..................\..........\AssemblyInfo.cpp
..................\..........\CLIWrapper.cpp
..................\..........\CLIWrapper.h
..................\..........\CLIWrapper.vcproj
..................\..........\CLIWrapper.vcproj.HSLCN.xhzhu.user
..................\..........\CLIWrapper.vcproj.ZHUXIAOH.xhzhu.user
..................\..........\Debug
..................\..........\.....\BuildLog.htm
..................\..........\MathWrapper.cpp
..................\..........\MathWrapper.h
..................\..........\ReadMe.txt
..................\..........\resource.h
..................\..........\Stdafx.cpp
..................\..........\Stdafx.h
..................\CppDLL
..................\......\CppDLL.cpp
..................\......\CppDLL.h
..................\......\CppDLL.vcproj
..................\......\CppDLL.vcproj.HSLCN.xhzhu.user
..................\......\CppDLL.vcproj.ZHUXIAOH.xhzhu.user
..................\......\Debug
..................\......\.....\BuildLog.htm
..................\......\ReadMe.txt
..................\......\stdafx.cpp
..................\......\stdafx.h
..................\CppTest
..................\.......\CppTest.aps
..................\.......\CppTest.cpp
..................\.......\CppTest.h
..................\.......\CppTest.rc
..................\.......\CppTest.vcproj
..................\.......\CppTest.vcproj.HSLCN.xhzhu.user
..................\.......\CppTest.vcproj.ZHUXIAOH.xhzhu.user
..................\.......\CppTestDlg.cpp
..................\.......\CppTestDlg.h
..................\.......\Debug
..................\.......\.....\BuildLog.htm
..................\.......\ReadMe.txt
..................\.......\res
..................\.......\...\CppTest.ico
..................\.......\...\CppTest.rc2
..................\.......\resource.h
..................\.......\stdafx.cpp
..................\.......\stdafx.h
..................\CsharpCallCppByCLI.sln
..................\CsharpTest
..................\..........\CsharpTest.csproj
..................\..........\Form1.cs
..................\..........\Form1.Designer.cs
..................\..........\Form1.resx
..................\..........\obj
..................\..........\...\Debug
..................\..........\...\.....\TempPE
..................\..........\Program.cs
..................\..........\Properties
..................\..........\..........\AssemblyInfo.cs
..................\..........\..........\Resources.Designer.cs
..................\..........\..........\Resources.resx
..................\..........\..........\Settings.Designer.cs
..................\..........\..........\Settings.settings