Giter Site home page Giter Site logo

jimixkartin / import-dll-into-python-project Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sarangsmk/import-dll-into-python-project

0.0 0.0 0.0 29 KB

Import a custom dll built with C# into a Python Project and access the functions from the dll.

License: GNU General Public License v3.0

C# 72.74% Python 27.26%

import-dll-into-python-project's Introduction

import-dll-into-python-project

Importing a custom dll built with C# into a Python Project and access the functions inside the dll with the help of pythonnet.

Project Structure

  • dll Project - Contains the C# Solution for the custom dll
  • Python Project - The Python project folder

Dll Code

namespace CalcProject
{
    public class calculate
    {
        /// <summary>
        /// Simple Helper to add 2 Numbers and return the result
        /// </summary>
        /// <param name="a">Number 1</param>
        /// <param name="b">Number 2</param>
        /// <returns>Sum of 2 Numbers</returns>
        public int Add(int a, int b)
        {
            return a + b;
        }
    }
}

Python Code

import clr

# Add Reference to the library/dll
# Option -1 :Add the dll into project folder
clr.AddReference("dlls/CalcProject")

# Option -2: Add the dll path into the system path
# dll_path = r"C:\SMK\Desktop\test\CalcTest\CalcTest\bin\Debug"
# import sys
# sys.path.append(assembly_path)

# From NameSpace_Name import class_Name
from CalcProject import calculate

# Create object of the Class
obj = calculate()

# Call the function with class object (The function from dll that you want to access)
print(obj.Add(1, 2))

import-dll-into-python-project's People

Contributors

sarangsmk avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.