0

hi,
i have a big exe program that i wrote in c# (big means that i have a lot of class in it), i want to write a script in python that will check the program.

what is the right way to check the program, convert the c# program to dll and to create an instants of my classes, or to load the Exe program to the python ?

thanks,

Oron

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by jcao219
0

hi,
i have a big exe program that i wrote in c# (big means that i have a lot of class in it), i want to write a script in python that will check the program.

what is the right way to check the program, convert the c# program to dll and to create an instants of my classes, or to load the Exe program to the python ?

thanks,

Oron

Ah, use IronPython.

With IronPython, you can load .NET .dll's using the clr module.
http://ironpython.net/

If you have a C# program with this code:

using System;

namespace SimpleDLL
{
    public class Simple
    {
        public string data;

        public Simple(string data)
        {
            this.data = data;
        }
    }
}

and you compile it as simpledll.dll

you can do this in IronPython (put the dll in the same folder as the .py file)

import clr

clr.AddReference("simpledll")

from SimpleDLL import Simple

s = Simple("Hello World")

If you want to just run an EXE in IronPython, you can do this:

import clr

from System.Diagnostics import Process
Process.Start("name_of_exe.exe")

If you want to work with a C# exe, I think that would be much harder, since you'll have to work with System.Reflection and stuff like that.

Edited by jcao219: n/a

0

you can also use ctypes.

from ctypes import *
myDLL = cdll.LoadLibrary('nameOfDll.dll')
0

you can also use ctypes.

from ctypes import *
myDLL = cdll.LoadLibrary('nameOfDll.dll')

He wrote the .dll in C#.
cdll can only load dlls written in C or C++.

C# dlls are .NET assemblies, built with MSBUILD, which are extremely different.
I'm afraid IronPython is the only way for this situation.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.