#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2017
    Posts
    85
    Rep Power
    1

    [Python + DLL] Failed to import DLL (or CDLL), help needed!


    Hey Python Programmers...

    I get writted an dll (or clib) for python, to test if it works...
    So here is my clib, writted in Dev C++ yet:
    Code:
    #include <iostream>
    #include "stdafx.h"
    #include "Windows.h"
    
    #define LIBDLL extern "C" __declspec(dllexport)
    
    LIBDLL int ml_pixel(int x, int y) {
    	return x * y;
    }
    
    LIBDLL int ml_voxel(int x, int y, int z) {
    	return x * y * z;
    }
    
    LIBDLL int ml_px(int x) {
    	return x;
    }
    
    LIBDLL int ml_py(int y) {
    	return y;
    }
    
    LIBDLL int ml_pz(int z) {
    	return z;
    }

    And here is my python code, writted in python 3.x yet (looks like this):
    Code:
    from ctypes import *
    myDLL = cdll.LoadLibrary("c:\\Menar.dll")
    w = myDLL.ml_pixel(5, 5)
    
    print(w);

    If i run my script, this is the error i get:
    Traceback (most recent call last):
    File "C:\Users\Gebruiker\Desktop\dllTest\Library\pyDLLTest.py", line 2, in <module>
    myDLL = cdll.LoadLibrary("c:\\Menar.dll")
    File "C:\Program Files (x86)\Python36-32\lib\ctypes\__init__.py", line 426, in LoadLibrary
    return self._dlltype(name)
    File "C:\Program Files (x86)\Python36-32\lib\ctypes\__init__.py", line 348, in __init__
    self._handle = _dlopen(self._name, mode)
    OSError: [WinError 126] Kan opgegeven module niet vinden
    >>>

    I am just learn C++ so i can create DLLs for programmers so they can extand as example
    python if it doesn't get the just support they are wish... i want learn C++ to extend the python
    support if it works fast for big 3D Applications yet...

    So can anyone tell me whats wrong with my simple DLL or with my Python Code,
    just i can learn about this how i can program it better for real time use...

    So this is an simple test to starts with learn writting DLLs yet... Later i want learn
    write complex and fast 3D Library(s) in called Ray Traced and Sciensifical Applications
    as called VR and 3D-Printing yet..

    So can anyone fix my problem with importing my DLL, i get written in Dev C++ ?...,
    Thanks for help, Jamie.
  2. #2
  3. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Posts
    5,971
    Rep Power
    509
    Find a dll on your computer, see if you can load it and run one of the functions using ctypes module. Try the examples in
    https://docs.python.org/3/library/ctypes.html
    You seem to want to build a moon rocket before learning how to use your hand tools.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2017
    Posts
    85
    Rep Power
    1
    OK, i get tryed your tip, but it don't works yet...

    I've try to import "OpenGL.dll in python, use this code:
    Code:
    from ctypes import *
    cdll.LoadLibrary("C:\\OpenGL.dll")
    w = CDLL("C:\\OpenGL.dll")
    
    print(w)
    The reasion i will be want work with DLLs is thad the thirth party python packages for 3D sush like pyOpenGL are not very fast in 3D Preformences...
    But now, if i try import my dll with the LoadLibrary Code, i get the following error yet:
    Traceback (most recent call last):
    File "C:\Users\Gebruiker\Desktop\DLLs\GLLibTest.py", line 2, in <module>
    cdll.LoadLibrary("C:\\OpenGL.dll")
    File "C:\Program Files (x86)\Python36-32\lib\ctypes\__init__.py", line 426, in LoadLibrary
    return self._dlltype(name)
    File "C:\Program Files (x86)\Python36-32\lib\ctypes\__init__.py", line 348, in __init__
    self._handle = _dlopen(self._name, mode)
    OSError: [WinError 126] Kan opgegeven module niet vinden

    Even i try to load the dll from an windll code, like this:
    Code:
    from ctypes import *
    w = windll.LoadLibrary("C:\\OpenGL.dll")
    
    print(w)

    But then i get the same sourt error, like this:
    Traceback (most recent call last):
    File "C:\Users\Gebruiker\Desktop\DLLs\GLLibTest.py", line 2, in <module>
    w = windll.LoadLibrary("C:\\OpenGL.dll")
    File "C:\Program Files (x86)\Python36-32\lib\ctypes\__init__.py", line 426, in LoadLibrary
    return self._dlltype(name)
    File "C:\Program Files (x86)\Python36-32\lib\ctypes\__init__.py", line 348, in __init__
    self._handle = _dlopen(self._name, mode)
    OSError: [WinError 126] Kan opgegeven module niet vinden

    Now whats wrong with my codes, i tryed all ways to import the "OpenGL.dll" with the reasion thad the third party packages
    for 3D in Python such like pyOpenGL and other 3D Packages from pip is too slow for what i wish with python yet...
    Just with dll's i hope its an big much faster...

    Can anyone help me to fix this problem at the use of dll's downloading from internet yet... i get tryed what you said just
    this tip your gived my:
    Code:
    Find a dll on your computer, see if you can load it and run one of the functions using ctypes module. Try the examples in
    https://docs.python.org/3/library/ctypes.html
    You seem to want to build a moon rocket before learning how to use your hand tools.
    But it will don't lucks on any way, just pleace can anyone help me to fix the problem i get with loading dll's on my computer,
    so thad i don't have any complex C/C++ knowledge needed for what i want ?...

    I want to write big and complex 3d-applications for as example 3d-printing and building 3d-worlds yet.... but the thirth party python packages for
    3d graphics are too slow for my wishes, if you can help me to fix this problem i get with import dll's, i hope thad i can further with python yet....

    Thanks for help, Jamie.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2017
    Posts
    85
    Rep Power
    1
    OSError: [WinError 126] Kan opgegeven module niet vinden
    Oh yeh.... to translate the last part of my two errors it said this above,
    to translate this to english is said such like this:
    Code:
    OSError: [WinError 126] Don't can find the called module

    So i hope you do understand whats wrong with my codes to import dll's from my computer..

    Thanks for help, Jamie.
  8. #5
  9. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Posts
    5,971
    Rep Power
    509
    You did not try my suggestion. OpenGL is not found on the ctypes page: https://docs.python.org/3/library/ctypes.html .
    You tried the location r"C:\OpenGL.dll" . Is OpenGL.dll really installed in c:\ ??? Not likely sir.

    Today I am using a computer having windows 7 operating system as well as some python3 version.

    Code:
    Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (In
    tel)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from ctypes import *
    >>> print(windll.kernel32)
    <WinDLL 'kernel32', handle 76970000 at 322b50>
    >>> print(cdll.msvcrt)
    <CDLL 'msvcrt', handle 762f0000 at 311e90>
    >>> libc=cdll.msvcrt
    >>> libc.printf
    <_FuncPtr object at 0x003193F0>
    >>> print(libc.time(None))
    1526343794
    This exercise gives me hope that the documentation is correct and I can solve this problem. I am unaware of a c compiler on this computer and I don't really feel like installing one.

    I found a 32 bit dll within my file system. It loads.
    Code:
    a:>dir "c:\Program Files (x86)\Common Files\Adobe\Acrobat"
    dir "c:\Program Files (x86)\Common Files\Adobe\Acrobat"
     Volume in drive C is Windows7_OS
     Volume Serial Number is CA56-69DB
    
     Directory of c:\Program Files (x86)\Common Files\Adobe\Acrobat
    
    03/01/2018  11:07 AM    <DIR>          .
    03/01/2018  11:07 AM    <DIR>          ..
    05/14/2018  10:31 AM    <DIR>          ActiveX
                   0 File(s)              0 bytes
                   3 Dir(s)  130,605,289,472 bytes free
    
    a:> 
    a:> python3
    >>> from ctypes import *
    >>> j=cdll.LoadLibrary(r'c:\Program Files (x86)\Common Files\Adobe\Acrobat\Activ
    eX\AcroPDF.dll')
    >>> j
    <CDLL 'c:\Program Files (x86)\Common Files\Adobe\Acrobat\ActiveX\AcroPDF.dll', h
    andle 5a0a0000 at 311ed0>
    >>>
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo