1
나는 그와 함께 작동하기 위해 C++에서 DLL, 인터페이스를 가지고있다. bcb, msvc에서 잘 작동합니다. 파이썬 스크립트를 사용하여이 라이브러리의 함수에 액세스하려고합니다. Swig를 사용하여 python-package를 생성하십시오.DLL에서 실행 기능에 대한 액세스 위반
파일 setup.py
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'])
파일 dcm.i
%module dcm
%include <windows.i>
%{
#include <windows.h>
#include "../interface/DcmInterface.h"
#include "../interface/DcmFactory.h"
#include "../interface/DcmEnumerations.h"
%}
%include "../interface/DcmEnumerations.h"
%include "../interface/DcmInterface.h"
%include "../interface/DcmFactory.h"
실행이 명령 (파이썬이 확장 평와 관련된)
setup build
setup install
사용 이 DLL
import dcm
f = dcm.Factory() #ok
r = f.getRegistrationMessage() #ok
print "r.GetLength() ", r.GetLength() #ok
r.SetLength(0) #access violation
마지막 문자열에서 액세스 위반이 발생합니다. 그리고 입력 매개 변수를 사용하여 모든 함수에 대한 액세스 위반이 있습니다.
DcmInterface.h (인터페이스)
class IRegistrationMessage
{
public:
...
virtual int GetLength() const = 0;
virtual void SetLength(int value) = 0;
...
};
uRegistrationMessage.cpp (DLL에서 구현)
class TRegistrationMessage : public IRegistrationMessage
{
public:
...
virtual int GetLength() const
{
return FLength;
}
virtual void SetLength(int Value)
{
FLength = Value;
FLengthExists = true;
}
...
};
공장
DcmFactory.h (에 DLL을 사용 클라이언트 코드)
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();
};
};
생성 된 코드에서'Factory :: SetLength()'를 호출하고'DcmFactory.h'에서 원래 선언을 추가 할 수 있습니까? –
... arg1 = reinterpret_cast (argp1); ecode2 = SWIG_AsVal_int (OBJ1, &val2); 경우 (! SWIG_IsOK ' "인자", "(2)"타입 "" ""INT ""IRegistrationMessage_SetLength ""방법 "'(ecode2)) { SWIG_exception_fail (SWIG_ArgError (ecode2) ")"; "); } arg2 = static_cast < int > (val2); (arg1) -> SetLength (arg2); ... –
Xeningem