VS2010 C#调用C++ DLL文件.NET教程网——简单专业的.NET技术网站.pdf
文本预览下载声明
TAG
RSS
ASP.NET IT C# SQL VB.NET AJAX silverlight .NET
Google DLL EXE C# VB DLL C C++ Java
: C#
VS2010 C#C++ DLL
: 2011-04-06 10:19 : : admin : 4224 ASP.NET1.0/2.0/3.5/4.0/MVC
C#DLLC#DllImport
1. CSharpInvokeCPP
2. C++
3. “DLL”
dllmain.cppDLLexemainWinMain
DLLLoadLibraryFreeLibrary
/benkaoya/archive/2008/06/02/2504781.aspx
4. CSharpInvokeCPP.CPPDemo.cpp
1 // CSharpInvokeCPP.CPPDemo.cpp : DLL
2 //
3
4 #include stdafx.h
5
6 extern C __declspec(dllexport) int Add(int x, int y)
7 {
8 return x + y;
9 }
10 extern C __declspec(dllexport) int Sub(int x, int y)
11 {
12 return x - y;
13 }
14 extern C __declspec(dllexport) int Multiply(int x, int y)
15 {
16 return x * y;
17 }
18 extern C __declspec(dllexport) int Divide(int x, int y)
19 {
20 return x / y;
21 }
extern C “extern” “C” extern C
C
__declspec(dllexport) DLL
extern C __declspec(dllexport)DllImportC++DLLDllImportC
DLL
5. Debug CSharpInvokeCPP.CPPDemo.dllCSharpInvokeCPP.CPPDemo.lib
PE ExplorerDLL
“”
6. C#C++DLLC#
7. CSharpInvokeCSharp.CSharpDemoCPPDLL
1 public class CPPDLL
2 {
3 [DllImport(CSharpInvokeCPP.CPPDemo.dll)]
4 public static extern int Add(int x, int y);
5
6 [DllImport(CSharpInvokeCPP.CPPDemo.dll)]
7 public static extern int Sub(int x, int y);
8
9 [DllImport(CSharpInvokeCPP.CPPDemo.dll)]
10 public static extern int Multiply(int x, int y);
11
12 [DllImport(CSharpInvokeCPP.CP
显示全部