How can I create a DLL that can be called from Python 2.6 under win32?

2 ビュー (過去 30 日間)
Puppet Master Ivaschenko
Puppet Master Ivaschenko 2014 年 8 月 29 日
コメント済み: Rafael Fietzek 2018 年 8 月 3 日
Hi there!
I have a function:
function [y] = add2(x)
y = x+2;
end;
I want to call it as a DLL from Python 2.6 under win32. I used the Matlab Compiler to build the .NET Assembly 'add2.dll'. Then I tried the following Python code:
from ctypes import*
mydll = windll.LoadLibrary("C:\\...\\add2.dll")
mydll.add2(5)
It answered: AttributeError: function 'add2' not found
What would be a problem? Did I use a wrong Compiler?
On the other hand, I can call standard Matlab functions using COM interface:
import win32com.client
h = win32com.client.Dispatch('matlab.application')
h.Execute("mpower(2,3)")
It works well and results in 8. Is there a similar way to call my 'add2' function?
TIA

回答 (2 件)

Claire
Claire 2014 年 10 月 29 日
Hi there,
Did you get any further with this? I'm hoping to try a similar implementation myself and it would be great to know if its even possible before I start.
Claire

Cavalera
Cavalera 2015 年 2 月 23 日
Hi there,
The DLL is dependant of the Matlab Compiler Runtime (MCR). The MCR has to be launched before you call your function add2 function. More over, it is not possible to call your Matlab code directly inside Python. You should write a C or C++ wrapper in order to pass your function add2 to Python.
I can help if you have questions
Hugo Cavalera R&D engineer at Inria
  2 件のコメント
Michele Manfredda
Michele Manfredda 2018 年 7 月 5 日
Can you better comment your answer? I could not find anything more in the web and this was the first clue.
1) how do you launch the mcr? 2) Why do you need a wrapper? What is the reason? 3) Can you post an example? :-)
Rafael Fietzek
Rafael Fietzek 2018 年 8 月 3 日
We are doing the same basically, Any luck getting it works?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangePython Package Integration についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by