Note that there are some explanatory texts on larger screens.

plurals
  1. POAccess violation on run function from dll
    text
    copied!<p>I have DLL, interface on C++ for work with he. In bcb, msvc it works fine. I want to use Python-scripts to access function in this library. Generate python-package using Swig.</p> <p>File <em>setup.py</em></p> <pre><code> import distutils from distutils.core import setup, Extension setup(name = "DCM", version = "1.3.2", ext_modules = [Extension("_dcm", ["dcm.i"], swig_opts=["-c++","-D__stdcall"])], y_modules = ['dcm']) </code></pre> <p>file <em>dcm.i</em></p> <pre><code>%module dcm %include &lt;windows.i&gt; %{ #include &lt;windows.h&gt; #include "../interface/DcmInterface.h" #include "../interface/DcmFactory.h" #include "../interface/DcmEnumerations.h" %} %include "../interface/DcmEnumerations.h" %include "../interface/DcmInterface.h" %include "../interface/DcmFactory.h" </code></pre> <p>run these command (python is associated with extension .py)</p> <pre><code>setup build setup install </code></pre> <p>using this DLL</p> <pre><code>import dcm f = dcm.Factory() #ok r = f.getRegistrationMessage() #ok print "r.GetLength() ", r.GetLength() #ok r.SetLength(0) #access violation </code></pre> <p>On last string I get access violation. And I have access violation on every function using input parameters.</p> <p><em>DcmInterface.h</em> (interface)</p> <pre><code>class IRegistrationMessage { public: ... virtual int GetLength() const = 0; virtual void SetLength(int value) = 0; ... }; </code></pre> <p><em>uRegistrationMessage.cpp</em> (implementation in DLL)</p> <pre><code>class TRegistrationMessage : public IRegistrationMessage { public: ... virtual int GetLength() const { return FLength; } virtual void SetLength(int Value) { FLength = Value; FLengthExists = true; } ... }; </code></pre> <p>Factory</p> <p><em>DcmFactory.h</em> (using DLL in client code)</p> <pre><code>class Factory { private: GetRegistrationMessageFnc GetRegistration; bool loadLibrary(const char *dllFileName = "dcmDLL.dll" ) { ... hDLL = LoadLibrary(dllFileName); if (!hDLL) return false; ... GetRegistration = (GetRegistrationMessageFnc) GetProcAddress( hDLL, "getRegistration" ); ... } public: Factory(const char* dllFileName = "dcmDLL.dll") { loadLibrary(dllFileName); } IRegistrationMessage* getRegistrationMessage() { if(!GetRegistration) return 0; return GetRegistration(); }; }; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload