CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2010

    Unhappy Calling from VC++ a Dll made in Fortran

    Hi, I've one dll that was made in Fortran. This dll contains the diynamic model of a Sailboat (in fact is a VPP -Velocity Prediction Program-)

    In general, the inputs of the dll are 2 integers and 20 floats, as follows: (the name of the dll's function is "DLL_SIMULATEUR")

    DLL_SIMULATEUR(int int, float, float ..., float)

    the expected answer of the simulator is the same 22 variables in time + delta time.

    I can use easily the dll in VB6 as follows:

    --- function declaration ---

    Private Declare Sub DLL_SIMULATEUR Lib "C:\vpp53.dll" (CodeError As Integer, n As Integer, t As Double, dt As Double, TWS As Double, TWA As Double, ec As Double, Ang As Double, _
    X As Double, Y As Double, z As Double, psi As Double, teta As Double, phi As Double, _
    Vx As Double, Vy As Double, vz As Double, omx As Double, omy As Double, omz As Double, Course As Double, Cap_Compass As Double, Leeway As Double, MomentSafran As Double)

    --- call to dll ---
    Call DLL_SIMULATEUR(CodeErreur, n, t, dt, TWS, TWA, ec, Ang, X, Y, z, psi, teta, phi, Vx, Vy, vz, omx, omy, omz, Course, Cap_Compass, Leeway, MomentSafran)

    and the updated values are saved in the same variables,
    for example, t <<time>>, if I send t=1, then after call the dll, t is going to be 2.

    Another case. If I use it in matlab, the .h file is as follows:

    #ifndef simul_h
    #define simul_h
    EXPORTED_FUNCTION double __stdcall simul(int*, int*, double*, double*,..., double*);

    and the dll's call is like this: (this is in the .m file)



    where a0 is a ptr from matlab (i dont use it, but anyway, I must to put a variable to recive it), Input1, Input2, Val1 and Val2 are integers, and the rest, are doubles (in matlab, floats in C++)...

    All that thing works fine, but, when I try to use the dll from VC++ (VS 2008), I can link the dll and send the data.. but I can't get the returned data.

    The code in C++ that I'm using is:

    // Test3.cpp*: définit le point d'entrée pour l'application console.
    #include "stdafx.h"
    #include "iostream"
    #include <time.h>
    #include <windows.h>
    #include <winbase.h>

    typedef void (__stdcall *SimulateurFunc)( int*, int*, float*,float*,float*,float*,float*,float*,float*,float*,float*,float*,float*,float*,float*,

    int CodeErrDll, n;
    float t,Dt,Tws,Twa,AngleBoom,AngleSafran,X,Y,Z,Psi,Teta,Phi,Vx,Vy,Vz,Omx,Omy,Omz,Course,CapCompas,Leeway,MomentMecheSafran;

    int main()
    n=1; //Numero de iteraciones de la funcion
    Dt=0.1; // Diferencial de tiempo
    // t = tiempo total de simulacion : t = n * Dt

    SimulateurFunc _SIMULATEUR;

    HINSTANCE hInstLibrary;
    hInstLibrary= LoadLibrary(_T("vpp53.dll"));
    if (hInstLibrary)
    _SIMULATEUR = (SimulateurFunc)GetProcAddress(hInstLibrary, "DLL_SIMULATEUR");

    if (_SIMULATEUR)



    std::cout << "DLL Failed To Load!" << std::endl;

    printf("Press any Key to Continue\n");

    return 0;

    It compiles fine (I know that it compiles doesn't means that it is going to work as i need xD)
    but i can't get the updated values that are given by the dll.

    What I'm doing wrong???
    I'll be very happy if someone can help me.... I'm not good in c++ :S

    Thanks a lot!

    one final remark: I dont have the .h either the .def of the function (as they are not used in VB and Matlab...)

  2. #2
    Join Date
    Nov 2003

    Re: Calling from VC++ a Dll made in Fortran

    Try changing "float" to "double".


  3. #3
    Join Date
    Jan 2010

    Question Re: Calling from VC++ a Dll made in Fortran

    in fact, that was one of the first things that I tried....

    The problem (I think) is the way that I'm using to call the dll....

    Thank you anyway!

  4. #4
    Join Date
    Nov 2003

    Re: Calling from VC++ a Dll made in Fortran

    In VB6, "Integer" is a "short" in C++.


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.