3

I use pythonnet not ironpython.

There is a function like this:

test(ref string p1,out string p2)

How can I call test in python 3.6?

import clr
import sys
import System
sys.path.append(r'd:\dll')  
clr.FindAssembly('communication.dll')  
from  communication import *  
dll=IEC62056()
dll.test(----------)
denfromufa
  • 5,610
  • 13
  • 81
  • 138
layty
  • 31
  • 6
  • you can check similar discussion [here](https://stackoverflow.com/questions/26998687/calling-a-net-function-in-python-which-has-a-reference-parameter) – rahulaga-msft Mar 07 '18 at 07:38
  • hmm not a best solution but why not make a console program to wrap your dll and then call console program from python ? – Agent_Orange Mar 07 '18 at 07:39
  • @Rahul Agarwal this page is iropython not pythonnet https://pythonnet.github.io/ – layty Mar 07 '18 at 08:32
  • @ Agent_Orange I am sorry, i can't understand, can you show me examples? – layty Mar 07 '18 at 08:35

2 Answers2

1

I can't test the code without communication.dll, so please check if the following code is working for you:

import clr
import sys
sys.path.append("D:\\dll") # path to dll
clr.AddReference("communication") # add reference to communication.dll
from  communication import test

ref_string_p1 = "----------"
out_string_p2 = test(ref_string_p1)
print(out_string_p2)
mdk
  • 398
  • 2
  • 8
0

you can feed ref as a regular argument, and feed out arbitrarily. pythonnet will return them positionally as tuple.

assume void test(ref string p1,out string p2) in c#, you get p1, p2 = test(p1, None) in python

willhyper
  • 96
  • 2
  • 5