简体   繁体   中英

IronPython Crash NOT for Python 2.7 and 3.3

I have no idea why the Ironpython crash after executing DLL but NOT python 2.7 and 3.3

My code as below

import ctypes
import time
DLLHANDLE=ctypes.cdll.LoadLibrary("C:\\INSTRDLL\\builds\\DCSOURCEDLL\\B2902A.dll")
INPUTSCRIPT="SYSTEM{DCSOURCE1|INIT}"
INPUTVOLTAGE=0.0
SOURCEHANDLE=DLLHANDLE.DCSOURCE(c_INPUTSCRIPT,c_INPUTVOLTAGE)
time.sleep(1)

Basically, The DLL is calling instrument to perform initialization once INPUTSCRIPT is issued.

I have attached the Crash screenshot. Please help...

在此处输入图片说明

ctypes , in general, is a whole pile of whatever the opposite of fun is. With normal Python, it's like coding in C - watch your pointers, data types, etc. - but at least CPython is relatively close to C and it works acceptably (it also the advantage of being much more widely used).

In IronPython, it's that, plus the CLR has to intermediate everything - it uses the .NET marshaling APIs, and also generates P/Invoke declarations at runtime. The code to do this is rather complicated and has known bugs - dealing with raw memory is not what .NET is designed to do!

One area of concern is that IronPython uses Unicode strings, while you don't specify what type the DCSOURCE function takes (wide/Unicode/ wchar_t* or narrow/ANSI/ char* ). Without knowing the signature of the C function it's hard to say. I also don't remember what IronPython ctypes assumes and converts to by default.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM