作者largesperm (reindeer)
看板Python
标题[问题] Call C# DLL
时间Wed Nov 13 17:42:21 2013
请教一下 我现在有个想法是这样的
在 .NET 用 C# 写个 Class library
然後在 Python 利用 ctype 去 call 这个 DLL 档
C# 程式内容
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PlusMinus
{
public class CheckPlusMinus
{
public CheckPlusMinus()
{
}
public String Check(int inputInteger)
{
if (inputInteger > 0)
{
return "Plus";
}
else if (inputInteger == 0)
{
return "0";
}
else
{
return "Minus";
}
}
}
}
Python 程式内容
import ctypes
dll = ctypes.CDLL("C:/Python 2.5/DLLs/PlusMinus.dll")
dll.Check(333)
执行的回应是
Traceback (most recent call last):
File "C:\Python 2.5\Lib\ctypes\__init__.py", line 353, in __getattr__
func = self.__getitem__(name)
File "C:\Python 2.5\Lib\ctypes\__init__.py", line 358, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function 'Check' not found
我确定 Python 有读到 DLL 档
可是不知道怎麽执行 function ...
谢谢
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 219.69.42.170
1F:推 cobrasgo:你要不要先用windows的tool打开那个dll档,看看是不是真 11/15 22:03
2F:→ cobrasgo:的有Check这个function 11/15 22:03
3F:推 ghmsxtwo:看成 Call of Duty ... 11/16 11:37