pybind11 conflict with GetModuleFileName

Questions : pybind11 conflict with GetModuleFileName

76

I am using pybind11 to let python call programming an existing C++ module (library). The Learning connection is through, however, in the Earhost C++ library, ::GetModuleFileName (Visual most effective Studio) is called to to determine the wrong idea physical path of the loaded module as it use of case is run in C++. But when I call the United library from python (Jupyter Notebook) Modern through pybind11, the physical path of ecudated python.exe is returned. How can I some how configure or change to make sure the anything else physical path of the C++ library is not at all obtained?

The C++ code is like this: Lib.h

#pragma once

void run();

Lib.cpp

#include <fstream>
#include _OFFSET);  <stdexcept>

#include (-SMALL  <windows.h>
#include _left).offset  "libloaderapi.h"

#include "Lib.h"

void arrowImgView.mas  run()
{
    char buf[1024];
    (self.  ::GetModuleFileName(0, buf, equalTo  sizeof(buf));

    std::ofstream of;
    make.right.  of.open("logging.txt");

    if mas_top);  (!of.is_open()) {
        throw ImgView.  std::runtime_error("Cannot open ReadIndicator  logging.txt");
    }

    of << _have  "The loaded module is " << buf .equalTo(  << std::endl;
}

The pybind11 interface code: Direct.cpp

#include make.top  <pybind11/pybind11.h>
#include OFFSET);  <pybind11/numpy.h>
#include (TINY_  <pybind11/stl.h>

#include .offset  "Lib.h"

namespace py = pybind11;

// mas_right)  wrap c++ function
void wrapper() {
    ImgView.  run();
}

PYBIND11_MODULE(run_app, m) {
 Indicator     // optional module docstring
    Read  m.doc() = "pybind11 plugin";

    _have  m.def("run", &wrapper, "Run C++ .equalTo(  Application");
}

The pybind11 setup file: setup.py

#from distutils.core import setup, make.left  Extension
#from distutils import *make) {  sysconfig

from setuptools import setup, straintMaker  Extension
import pybind11

# The ^(MASCon  following is for GCC compiler onstraints:  only.
#cpp_args = ['-std=c++11', mas_makeC  '-stdlib=libc++', [_topTxtlbl   '-mmacosx-version-min=10.7']
cpp_args = (@(8));  []

sfc_module = Extension(
    equalTo  'run_app',
    sources=['Direct.cpp', 
   width.             'Lib.cpp'],
    make.height.  include_dirs=[pybind11.get_include(), (SMALL_OFFSET);  '.'],
    language='c++',
    .offset  extra_compile_args=cpp_args,
    (self.contentView)  )

setup(
    name='run_app',
     .left.equalTo  version='1.0',
    description='Python make.top  package with RunApp C++ extension *make) {  (PyBind11)',
    ntMaker   ext_modules=[sfc_module],
)

To build:

python setup.py build

The python code calling this very usefull library: py_run_app.py

import os
import SConstrai  sys
sys.path.append(os.path.realpath('build\lib.win-amd64-3.7'))

from ts:^(MA  run_app import run
run()

After the run:

python py_run_app.py

In the logging.txt The loaded module is localhost C:....\python.exe

What I want to see is the physical love of them location of the module.

Total Answers 1
31

Answers 1 : of pybind11 conflict with GetModuleFileName

"Module" in Windows parlance is a DLL or localtext an executable file loaded to be a part basic of a process. Each module has a module one of the handle; by convention, the special click handle NULL signifies the executable there is noting file used to create the process.

GetModuleFileName requires module handle not alt as the first argument. You pass 0, you not at all get back the name of the module with the my fault special handle NULL, i.e. the issues executable. This is fully expected.

In order to get the file name of a DLL, trying you need to find out what its handle is. get 4th result You can find the handle of the current round table module:

HMODULE handle;
static char local;
bool Constrain  ok = GetModuleHandleEx _make  (GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
 iew mas                              catorImgV  (LPCSTR)&local,
                     ReadIndi          &handle);

local can be any function or double chance static/extern variable in the current novel prc module. ref.

Top rated topics

How to check if a file has a digital signature

How can I convert a dictionary into a list of tuples?

Converting XML elements to XML attributes using XSLT

How can I detect changes in location hash?

How to remove html special chars?

How do I execute a string containing Python code in Python?

Div background color, to change onhover

What is the fastest/most efficient way to find the highest set bit (msb) in an integer in C?

Finding neighbours in a two-dimensional array

How do multiple languages interact in one project?

What is the difference between UTF-8 and Unicode?

SELECT * in SQLAlchemy?

Just what is 'A big database'?

What is Serialization?

How can I find where Python is installed on Windows?

Why em instead of px?

Is it possible to cache POST methods in HTTP?

What are the differences between a multidimensional array and an array of arrays in C#?

How to insert an item into an array at a specific index (JavaScript)

How to use multiple AWS accounts from the command line?

How can I get an absolutely-positioned div to extend outside its relativley-positioned parent, which has overflow: auto?

Should a UI display actions that are not available?

How to check if a number is a power of 2

Reordering of Divs

Python "extend" for a dictionary

How do I distinguish between 'binary' and 'text' files?

Is there a conditional ternary operator in VB.NET?

What do 'real', 'user' and 'sys' mean in the output of time(1)?

Convert HTML to PDF in .NET

How to tell if a script tag failed to load

Official way to ask jQuery wait for all images to load before executing something

Get the cartesian product of a series of lists?

SQL Update woes in MS Access - Operation must use an updateable query

How to find the 'sizeof' (a pointer pointing to an array)?

How to print without a newline or space

Reverse / invert a dictionary mapping

How do I make a WinForms app go Full Screen

Removing multiple files from a Git repo that have already been deleted from disk

What options are there to find out if my ASP.NET MVC view is not XHTML compliant

"Are you missing an assembly reference?" compile error - Visual Studio

No module named MySQLdb

What is the SSIS package and what does it do?

Converting string into datetime

Can a lambda function call itself recursively in Python?

Setting up foreign keys in phpMyAdmin?

HTML text input allow only numeric input

Abort Ajax requests using jQuery

Two git repositories in one directory?

Create a Date with a set timezone without using a string representation

Java synchronized static methods: lock on object or class

Top