2011-03-19 46 views
0

我试图使用VS2010与此代码误差__security_init_cookie在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 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; 
} 
从DLL导入fonction

结果表明,该DLL的进口和功能是成功的。 但我不明白为什么会有错误(对不起,这是法文版) 0x76bdb727 dans testWrapper.exe例外:Microsoft C++:QuantLib ::错误导致错误0x0015f800 .. 例外情况0x76bdb727丹斯testWrapper.exe:异常的Microsoft C++:QuantLib ::错误A L'进驻备忘录0x0015f800 ..

但是,代码停止时,我的朋友使用VS2008与此代码的工作 的错误是:

{ 
     /* 
     * The /GS security cookie must be initialized before any exception 
     * handling targetting the current image is registered. No function 
     * using exception handling can be called in the current image until 
     * after __security_init_cookie has been called. 
     */ 
     __security_init_cookie(); 

     return __tmainCRTStartup(); 
} 

在文件crtexe.c 谢谢

我已经删除的删除/ 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); 
     } 
} 
+0

这是EXE的CRT启动代码,请注意文件名“crtexe.c”。如何将代码链接到DLL中是一个谜。 – 2011-03-19 22:26:51

回答

1

取出/GS(缓冲区安全检查)设置:)

+5

不喜欢信息,拍摄信使? – 2011-03-19 22:27:20

+0

当导入一个VS [2010之前] dll项目/ GS被设置,不应该。 – 2011-03-19 22:54:21

+0

请问该怎么办? – nam 2011-03-19 23:16:15