calling functions in a Delphi DLL from VC++ - Programmer

This is a discussion on calling functions in a Delphi DLL from VC++ - Programmer ; Hi, I have some problems calling function from a dll created in Delphi. This DLL is a commercial (free) product so I don't know its contents. However, in the documentation it says that the calling convention is stdcall. And the ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: calling functions in a Delphi DLL from VC++

  1. calling functions in a Delphi DLL from VC++

    Hi,
    I have some problems calling function from a dll created in Delphi.
    This DLL is a commercial (free) product so I don't know its contents.
    However, in the documentation it says that the calling convention is
    stdcall. And the parameters are Delphi integers which should map to C
    int with no problems. Anyway, with all functions I call that have
    parameters, I get an exception error. The functions with no parameters
    works fine. This is my test code:

    typedef int (__stdcall *funcRetInt)();
    typedef int (__stdcall *TEST) (int);

    int main(int argc, char* argv[])
    {
    int ret = 0;

    HINSTANCE hLibrary;
    hLibrary=LoadLibrary("Easylase.dll");

    if(hLibrary != NULL)
    {

    FARPROC pnProc = GetProcAddress(hLibrary,"EasyLaseGetCardNum");
    funcRetInt EasyLaseGetCardNum;
    if (pnProc)
    {
    EasyLaseGetCardNum = (funcRetInt)pnProc;
    ret = EasyLaseGetCardNum();
    // Works fine.
    }


    pnProc = GetProcAddress(hLibrary,"EasyLaseGetStatus");
    TEST EasyLaseGetStatus;
    if (pnProc)
    {
    EasyLaseGetStatus = (TEST)pnProc;
    ret = EasyLaseGetStatus(0);
    // CRASH!!
    }
    }

    return 0;
    }

    If anyone have some ideas, I would appreciate some help, because Iam
    all out of ideas. I have had some contact with the guy who wrote the
    dll, and he says the dll works fine in delphi and VB. But he as never
    tried it with C/C++. He is abit stuck-up, so before I complain that his
    code dose not work I want to be sure I haven't made any elementary
    error.
    Thanks for your help
    Peter


  2. Re: calling functions in a Delphi DLL from VC++

    I had problems from C++ to C++ with mismatching register calling and
    stack based calling.
    Maybe that helps.

    Lothar


  3. Re: calling functions in a Delphi DLL from VC++

    I had problems from C++ to C++ with mismatching register calling and
    stack based calling.
    Maybe that helps.

    Lothar


  4. Re: calling functions in a Delphi DLL from VC++

    Peter Balck wrote:
    : Hi,
    : I have some problems calling function from a dll created in Delphi.
    : This DLL is a commercial (free) product so I don't know its contents.
    : However, in the documentation it says that the calling convention is
    : stdcall. And the parameters are Delphi integers which should map to C
    : int with no problems. Anyway, with all functions I call that have
    : parameters, I get an exception error. The functions with no parameters
    : works fine. This is my test code:

    Peter:

    1. Just wondering: have you tried calling the functions from Delphi?

    2. Exactly what message do you get on the exception error? Can you
    check `errno' (say, via strerror()) to narrow it down?



+ Reply to Thread