'Why ctypes cant load my dll file in the same dir?

I am very beginer at this kind of programming but i wanna try to use dll written on C++ in Python via ctypes module

Maybe i made stupid mistake but i am trying to load my dll file using ctypes and stuck with this error

Also i was trying to load it not with absolute path but with ctypes.windll.LoadLibrary("vnlib_link.dll)" or ctypes.windll.LoadLibrary("./vnlib_link.dll")

C:\Users\ilyam\AppData\Local\Programs\Python\Python310\python.exe C:/Users/ilyam/PycharmProjects/visengine/main.py
Traceback (most recent call last):
  File "C:\Users\ilyam\PycharmProjects\visengine\main.py", line 7, in <module>
    lib = ctypes.windll.LoadLibrary(dirname+"\\vnlib_link.dll")
  File "C:\Users\ilyam\AppData\Local\Programs\Python\Python310\lib\ctypes\__init__.py", line 452, in LoadLibrary
    return self._dlltype(name)
  File "C:\Users\ilyam\AppData\Local\Programs\Python\Python310\lib\ctypes\__init__.py", line 374, in __init__
    self._handle = _dlopen(self._name, mode)
FileNotFoundError: Could not find module 'C:\Users\ilyam\PycharmProjects\visengine\vnlib_link.dll' (or one of its dependencies). Try using the full path with constructor syntax.

Process finished with exit code 1

enter image description here

vnlib_link.h

#ifndef VNLIB_LINK_H
#define VNLIB_LINK_H

#include <stdio.h>
#include <iostream>
#include <string>


using namespace std;

#ifdef __cplusplus
    extern "C" {
#endif

#ifdef BUILD_DLL
    #define VNLIB_LINK __declspec(dllexport)
#else
    #define VNLIB_LINK __declspec(dllexport)
#endif

void VNLIB_LINK wrtCon(string msg);

#ifdef __cplusplus
    }
#endif

int VNLIB_LINK rtPlus(int a, int b);

#endif //end of dll

vnlib_link.cpp

#include "vnlib_link.h"

void wrtCon(string msg){
    cout << "Msg == : " << msg << endl;
}

int rtPlus(int a, int b){
    return a+b;
}

main.py

import ctypes
import os
import sys

dirname = os.path.dirname(sys.argv[0])
lib = ctypes.windll.LoadLibrary(dirname+"\\vnlib_link.dll")

lib.wrtCon("something")

Commands i am using to compile my dll

g++ -c -DBUILD_DLL vnlib_link.cpp -m64
g++ -shared -o vnlib_link.dll vnlib_link.o -Wl,--out-implib,libvnlib_link.a -m64


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source