Bonjour,
Je suis en train d'essayer d'importer d'une fonction à partir d'un dll avec ce code
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
 // 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;
}
Par contre, l'exécution montre que le dll est bien importé et la fonction est aussi connue, par contre, à l'utilisation de la fonction j'ai l'erreur suivante

Code : Sélectionner tout - Visualiser dans une fenêtre à part
Exception de première chance à 0x76bdb727 dans testWrapper.exe : Exception Microsoft C++ : QuantLib::Error à l'emplacement mémoire 0x0015f800.. Exception non gérée à 0x76bdb727 dans testWrapper.exe : Exception Microsoft C++ : QuantLib::Error à l'emplacement mémoire 0x0015f800..
Le code s'arrete dans le fichier crtexe.c
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
{
        /*
         * 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();
}
Par contre, le code est bien exécuté sous Visual Studio 2008, tandis que l'erreur avec ma version Visual Studio 2010