小编Cla*_*reM的帖子

Python ctypes:如何将NULL作为参数传递,格式为const char**

我正在尝试使用ctypes从python初始化Matlab编译器运行时(MCR).我的最终目标是能够在python中使用由Matlab编译器创建的C DLL,但我需要克服的第一个障碍就是启动并运行MCR.

我正在使用Python 2.7.8,Matlab 2013a,MCR8.1.

从mclbase.h剪切以显示参数等

LIBMWMCLBASE_API_EXTERN_C bool mclInitializeApplication(const char** options, size_t count);
Run Code Online (Sandbox Code Playgroud)

C相当于我正在尝试做的事情

mclInitializeApplication(NULL,0)
Run Code Online (Sandbox Code Playgroud)

这是我在python中调用函数的各种尝试.它们不可避免地导致TypeErrors或Windows错误0xE06D7363.我无法破解它!我是一个蟒蛇新手所以可能有一些简单的我缺少.欢迎任何评论!

# Initialize the MATLAB Compiler Runtime global state
from ctypes import *

libmcr=cdll.mclmcrrt8_1

# Load mclbase library
mcr_dll = cdll.LoadLibrary('C:\\Program Files\\MATLAB\\MATLAB Compiler Runtime\\v81\\bin\\win64\\mclbase.dll')

# Pick function we want to use
mclInit=mcr_dll.mclInitializeApplication

# Set up argument and results types
mclInit.argtypes = [POINTER(POINTER(c_char)),c_size_t]
# mclInit.argtypes = [POINTER(c_char_p),c_size_t] #different formatting attempt
mclInit.restype = c_bool

a=None
acast=cast(a,POINTER(c_char_p))
acast1=cast(a,POINTER(c_char))
acast2=cast(a,POINTER(POINTER(c_char)))

print 'a='
print a
print 'acast='
print acast
print …
Run Code Online (Sandbox Code Playgroud)

null ctypes pointers python-2.7

7
推荐指数
1
解决办法
4630
查看次数

标签 统计

ctypes ×1

null ×1

pointers ×1

python-2.7 ×1