Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在C#/Python中从DLL调用函数 我有下一个C++代码,用于创建DLL文件< /P> // MathFuncsDll.h #ifdef MATHFUNCSDLL_EXPORTS #define MATHFUNCSDLL_API __declspec(dllexport) #else #define MATHFUNCSDLL_API __declspec(dllimport) #endif namespace MathFuncs { // This class is exported from the MathFuncsDll.dll class MyMathFuncs { public: // Returns a + b static MATHFUNCSDLL_API double Add(double a, double b); // Returns a - b static MATHFUNCSDLL_API double Subtract(double a, double b); // Returns a * b static MATHFUNCSDLL_API double Multiply(double a, double b); // Returns a / b // Throws const std::invalid_argument& if b is 0 static MATHFUNCSDLL_API double Divide(double a, double b); }; } // MathFuncsDll.cpp : Defines the exported functions for the DLL application. // #include "stdafx.h" #include "MathFuncsDll.h" #include <stdexcept> using namespace std; namespace MathFuncs { double MyMathFuncs::Add(double a, double b) { return a + b; } double MyMathFuncs::Subtract(double a, double b) { return a - b; } double MyMathFuncs::Multiply(double a, double b) { return a * b; } double MyMathFuncs::Divide(double a, double b) { return a / b; } }_C#_Python_C++_Dll - Fatal编程技术网

如何在C#/Python中从DLL调用函数 我有下一个C++代码,用于创建DLL文件< /P> // MathFuncsDll.h #ifdef MATHFUNCSDLL_EXPORTS #define MATHFUNCSDLL_API __declspec(dllexport) #else #define MATHFUNCSDLL_API __declspec(dllimport) #endif namespace MathFuncs { // This class is exported from the MathFuncsDll.dll class MyMathFuncs { public: // Returns a + b static MATHFUNCSDLL_API double Add(double a, double b); // Returns a - b static MATHFUNCSDLL_API double Subtract(double a, double b); // Returns a * b static MATHFUNCSDLL_API double Multiply(double a, double b); // Returns a / b // Throws const std::invalid_argument& if b is 0 static MATHFUNCSDLL_API double Divide(double a, double b); }; } // MathFuncsDll.cpp : Defines the exported functions for the DLL application. // #include "stdafx.h" #include "MathFuncsDll.h" #include <stdexcept> using namespace std; namespace MathFuncs { double MyMathFuncs::Add(double a, double b) { return a + b; } double MyMathFuncs::Subtract(double a, double b) { return a - b; } double MyMathFuncs::Multiply(double a, double b) { return a * b; } double MyMathFuncs::Divide(double a, double b) { return a / b; } }

如何在C#/Python中从DLL调用函数 我有下一个C++代码,用于创建DLL文件< /P> // MathFuncsDll.h #ifdef MATHFUNCSDLL_EXPORTS #define MATHFUNCSDLL_API __declspec(dllexport) #else #define MATHFUNCSDLL_API __declspec(dllimport) #endif namespace MathFuncs { // This class is exported from the MathFuncsDll.dll class MyMathFuncs { public: // Returns a + b static MATHFUNCSDLL_API double Add(double a, double b); // Returns a - b static MATHFUNCSDLL_API double Subtract(double a, double b); // Returns a * b static MATHFUNCSDLL_API double Multiply(double a, double b); // Returns a / b // Throws const std::invalid_argument& if b is 0 static MATHFUNCSDLL_API double Divide(double a, double b); }; } // MathFuncsDll.cpp : Defines the exported functions for the DLL application. // #include "stdafx.h" #include "MathFuncsDll.h" #include <stdexcept> using namespace std; namespace MathFuncs { double MyMathFuncs::Add(double a, double b) { return a + b; } double MyMathFuncs::Subtract(double a, double b) { return a - b; } double MyMathFuncs::Multiply(double a, double b) { return a * b; } double MyMathFuncs::Divide(double a, double b) { return a / b; } },c#,python,c++,dll,C#,Python,C++,Dll,但我收到了这个信息 或者在python代码中 Traceback (most recent call last): File "C:/Users/PycharmProjects/RFC/testDLL.py", line 6, in <module> result1 = mydll.Add(10, 1) File "C:\Python27\lib\ctypes\__init__.py", line 378, in __getattr__ func = sel

但我收到了这个信息

或者在python代码中

Traceback (most recent call last):
  File "C:/Users/PycharmProjects/RFC/testDLL.py", line 6, in <module>
    result1 = mydll.Add(10, 1)
  File "C:\Python27\lib\ctypes\__init__.py", line 378, in __getattr__
    func = self.__getitem__(name)
  File "C:\Python27\lib\ctypes\__init__.py", line 383, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function 'Add' not found
回溯(最近一次呼叫最后一次):
文件“C:/Users/PycharmProjects/RFC/testDLL.py”,第6行,在
result1=mydll.Add(10,1)
文件“C:\Python27\lib\ctypes\\uuuu init\uuuuuu.py”,第378行,在\uuuu getattr中__
func=self.\uuuu getitem\uuuuu(名称)
文件“C:\Python27\lib\ctypes\\ uuuu init\uuuuuu.py”,第383行,在\uuuu getitem中__
func=self.\u FuncPtr((名称或顺序,self))
AttributeError:未找到函数“Add”
请帮忙 如何修复此代码,并调用例如ADD函数


谢谢

< p>因为它是C++编译,导出的符号名将是.< /p> 您可以通过查看DLL的导出列表,使用类似于的工具来确认这一点

当您打算通过网络调用DLL时,最好从DLL提供一个普通的C导出。您可以使用这一点来编写C++方法的包装器。

另见:

Traceback (most recent call last):
  File "C:/Users/PycharmProjects/RFC/testDLL.py", line 6, in <module>
    result1 = mydll.Add(10, 1)
  File "C:\Python27\lib\ctypes\__init__.py", line 378, in __getattr__
    func = self.__getitem__(name)
  File "C:\Python27\lib\ctypes\__init__.py", line 383, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function 'Add' not found