C++ 在dll中使用导入的函数时_security_init_cookie出错
我正在尝试使用VS2010和以下代码从dll导入一个函数C++ 在dll中使用导入的函数时_security_init_cookie出错,c++,dll,dllexport,C++,Dll,Dllexport,我正在尝试使用VS2010和以下代码从dll导入一个函数 // test.cpp : définit le point d'entrée pour l'application console. // #include "stdafx.h" #include<iostream> #include<windows.h> #include<map> #include<string> using namespace std; namespace m
// test.cpp : définit le point d'entrée pour l'application console.
//
#include "stdafx.h"
#include<iostream>
#include<windows.h>
#include<map>
#include<string>
using namespace std;
namespace mido{
class ABC_YieldCurve;
}
typedef int (*buildDepoSwapCurve)(mido::ABC_YieldCurve *& depoSwapTermStructure, long asOfDate,
std::map<std::string, double>& depoInstruments, std::map<std::string, double>& swapInstruments, std::string& error );
int _tmain(int argc, _TCHAR* argv[])
{
buildDepoSwapCurve mybuildDepoSwapCurve;
HINSTANCE hinstLib = LoadLibrary(TEXT("YieldCurve.dll"));
if (hinstLib == NULL) {
printf("ERROR: unable to load DLL\n");
cin.get();
return 1;
}
mybuildDepoSwapCurve = (buildDepoSwapCurve)GetProcAddress(hinstLib, "buildDepoSwapCurve");
if (mybuildDepoSwapCurve == NULL) {
printf("ERROR: unable to find DLL function\n");
cin.get();
FreeLibrary(hinstLib);
return 1;
}
//Construction d'un depoInstruments
std::map<std::string,double> mydepoInstruments;
mydepoInstruments["1W"]=0.0382;
mydepoInstruments["1M"]=0.0372;
mydepoInstruments["3M"]=0.0363;
mydepoInstruments["6M"]=0.0353;
mydepoInstruments["9M"]=0.0348;
//Construction d'un swap instrument
std::map<std::string,double> mySwapInstruments;
mySwapInstruments["1Y"]=0.0345;
mySwapInstruments["2Y"]=0.037125;
mySwapInstruments["3Y"]=0.0398;
mySwapInstruments["5Y"]=0.0443;
mySwapInstruments["10Y"]=0.05165;
mySwapInstruments["15Y"]=0.055175;
mySwapInstruments["25Y"]=0.05165;
//l'objet myYieldCurve nul
mido::ABC_YieldCurve * myYieldCurve;
string t="";
cout<< mybuildDepoSwapCurve(myYieldCurve,40000,mydepoInstruments,mySwapInstruments,t)<<endl;;
cout<<"test";
cin.get();
FreeLibrary(hinstLib);
return 0;
}
在文件crtexe.c中
谢谢
我已经删除了Remove/GS(缓冲区安全检查),但现在问题出在代码dbgheap.c中
extern "C" _CRTIMP void __cdecl _free_dbg(
void * pUserData,
int nBlockUse
)
{
/* lock the heap
*/
_mlock(_HEAP_LOCK);
__try {
/* allocate the block
*/
_free_dbg_nolock(pUserData, nBlockUse);
}
__finally {
/* unlock the heap
*/
_munlock(_HEAP_LOCK);
}
}
删除项目设置中的/GS(缓冲区安全检查):)这是EXE的CRT启动代码,请注意文件名“crtexe.c”。你是如何将代码链接到DLL的,这是一个谜。不喜欢这个消息,杀了messenger?当导入VS[2010]DLL项目时,设置了/GS,不应该设置它。项目->属性->C/C++->代码生成->缓冲区安全检查->不,我刚才完全按照你说的做了,但结果是一样的:-(现在问题是外部的“C”CRTIMP void cdecl free dbg(void*pUserData,int nBlockUse){/*锁定堆/\uMLOCK(\uHEAP\uLOCK);\uuuuuu尝试{/分配块/\uFREE\uDBG\uNOLOCK(pUserData,nBlockUse);}{/unlock heap*/_munlock(_heap_LOCK);}
extern "C" _CRTIMP void __cdecl _free_dbg(
void * pUserData,
int nBlockUse
)
{
/* lock the heap
*/
_mlock(_HEAP_LOCK);
__try {
/* allocate the block
*/
_free_dbg_nolock(pUserData, nBlockUse);
}
__finally {
/* unlock the heap
*/
_munlock(_HEAP_LOCK);
}
}