0

for the usage of an external dll in IronPython I have to pass a string to a char array (char var[len]; in C++.NET). It seems to be expected to pass an SByte array.

If I try

myVarFromCLibrary = myPyString

I get

TypeError: expected Array[SByte], got str

There is very little information in the web. Up to now I found that I can apply something like this:

from System import Array
...
myCString = Array[System.SByte](myPyString)

myVarFromCLibrary = myCString

If I do so, I get an error like:

TypeError: expected SByte, got str

What is to do to get the right conversion.

1 Answer 1

0

Meanwhile I found a workaround but no solution:

def strToCharArray(theCharArray,theString):
  asBytes = bytes(theString,'ascii')  
  for i in xrange(len(theString)):
    theCharArray[i] = ord(asBytes[i])
  theCharArray[len(asBytes)] = 0

def charArrayToStr(theCharArray):  
  chars = []
  i     = 0
  while theCharArray[i]>0: 
    chars.append(chr(theCharArray[i]))
    i += 1
  return "".join(chars)

This keeps my program running but is not the real solution

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.