2
情況很簡單。我在一個DLL(DLL1)中打開文件並在另一個(DLL2)中關閉它。我調用陸續在python腳本兩個DLL文件之一,它的代碼如下:C++&python關閉並打開不同的dll文件
from ctypes import *
DLLFP1=r"C:\Workspaces\CPP\Test\build\files1.dll"
DLLFP2=r"C:\Workspaces\CPP\Test\build\files2.dll"
DLL1=cdll.LoadLibrary(DLLFP1)
DLL2=cdll.LoadLibrary(DLLFP2)
cppobj=c_void_p()
DLL1.open(byref(cppobj))
DLL2.close(cppobj)
DLL1代碼:
#define DLLEXPORT extern "C" __declspec(dllexport)
DLLEXPORT void open(ofstream* &f){
f = new ofstream();
string FP("c:\\teest.log");
f->open(FP);
}
和DLL2代碼:
#define DLLEXPORT extern "C" __declspec(dllexport)
DLLEXPORT void close(ofstream* f){
f->close();
}
在結果我有「訪問違規寫作」。我也可以正常寫入文件從DLL2文件,如果我移動關閉功能DLL1它工作正常。我使用英特爾編譯器。操作系統是Windows7。
問題是什麼錯?在DLL之間共享文件的正確方法是什麼?
非常感謝您提前。
相關:[C++ 11地址是否考慮在動態/共享庫邊界之間傳遞std庫對象?](http://programmers.stackexchange.com/questions/176681/did-c11-address-concerns-通過std-lib-objects-between-dynamic-shared-librar) – robyschek
嘗試將兩個dll與動態C運行時連接,用MS的cl.exe它是'/ MD'開關 – robyschek
我試過了,不幸的是,幫助。 –