Board index » delphi » D1 Calling a 16-bit DLL Help Needed

D1 Calling a 16-bit DLL Help Needed

Hello,

I have a very pressing (the boss says it needs to be done in two weeks)
problem of calling a 16 bit DLL from a D1 app.

The DLL was not developed in house.  I don't have access to the source.
I have examples of how to call the DLL with  VB3/4 or MSVC++, but alas
not Delphi.  And I have stretched my rather limited Delphi skills to the
edge with limited success.

The test app that I have created works (I don't get a GPF), but I don't
get any data back, even when I get a valid return code.

So the question is: With what I have available, can I call this DLL from
D1?

If so how?

The VB example looks like this:

Declare Function vbCalc Lib "R16.DLL"(stringA, stringB, intA, singleA,
                                      stringC, singleB, intB, intC,
                                      stringD, stringE)

and the call:

intRet = vbCalc(stringA, stringB, intA, singleA, stringC, singleB,
                intB, intC, stringD, stringE)

with singleA as:

Dim singleA() As Single
ReDim singleA(49)

The (abbreviated) C++ example looks like this:

    char sMsg[80], stringA[2000], stringB[7], stringC[7], stringD[5],
         stringE[5];
    float singleA[50], singleB;
    int intA, intB, intC, iRet;

<snip>

    hinst = LoadLibrary("R16.DLL");
    SetErrorMode(PreviousErrorMode);

    if ((UINT) hinst < 33) {
        strcpy(sMsg, "Did not find R16.DLL");
        MessageBox((UINT)NULL, sMsg, "Testing R16.dll", MB_ICONSTOP);
        return(1);
        }

    lpfnR16 = (CPROC*) ::GetProcAddress(hinst,"_CCALC");

    if (lpfnR16 == NULL) {
        FreeLibrary(hinst);
        strcpy(sMsg, "Did not find procedure CCALC");
        MessageBox((UINT)NULL, sMsg, "Testing R16.dll", MB_ICONSTOP);
        return(1);
    }

<snip>

    iRet = (*lpfnR16)(stringA,
                      stringB,
                      &intA,
                      singleA,
                      stringC,
                      &singleB,
                      &intB,
                      &intC,
                      stringD,
                      stringE);

Hopefully I didn't leave anything out :)

Any and all help is appreciated.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    

 

Re:D1 Calling a 16-bit DLL Help Needed


Quote
kdow...@my-dejanews.com wrote:

> Hello,

> I have a very pressing (the boss says it needs to be done in two weeks)
> problem of calling a 16 bit DLL from a D1 app.

> The DLL was not developed in house.  I don't have access to the source.
> I have examples of how to call the DLL with  VB3/4 or MSVC++, but alas
> not Delphi.  And I have stretched my rather limited Delphi skills to the
> edge with limited success.

> The test app that I have created works (I don't get a GPF), but I don't
> get any data back, even when I get a valid return code.

> So the question is: With what I have available, can I call this DLL from
> D1?

(1) Make sure that you specify "stdcall" when declaring the DLL routine.

(2) If you can, skip all the LoadLibrary stuff and declare the
library-name in the
routine declaration, e.g. "External 'R16.DLL'"  This puts the burden of
locating the DLL, finding the routines, etc. upon Windows.

(3) Look closely at the Delphi samples on writing and using DLLs.  They
have working examples and in cases like this I think looking at actual
source-code is best.

Re:D1 Calling a 16-bit DLL Help Needed


On Mon, 14 Dec 1998 14:50:50 -0700, Sundial Services <i...@sundialservices.com>
wrote:

Quote
>kdow...@my-dejanews.com wrote:

>> Hello,

>> I have a very pressing (the boss says it needs to be done in two weeks)
>> problem of calling a 16 bit DLL from a D1 app.

>> The DLL was not developed in house.  I don't have access to the source.
>> I have examples of how to call the DLL with  VB3/4 or MSVC++, but alas
>> not Delphi.  And I have stretched my rather limited Delphi skills to the
>> edge with limited success.

>> The test app that I have created works (I don't get a GPF), but I don't
>> get any data back, even when I get a valid return code.

>> So the question is: With what I have available, can I call this DLL from
>> D1?

>(1) Make sure that you specify "stdcall" when declaring the DLL routine.

Just as I read your answer:
No. Sorry, stdcall is not a valid keyword in Delphi 1.
Usually "Pascal" is the standard calling convention in 16-bit
and used in most APIs. In this case *nothing* has to be
done in Delphi 1, since "Pascal" is the default calling
convention there...
The only other possibility would be "cdecl", which must be
used, if the DLL was written with "C" calling convention
(a look in the hopefully supplied header file should
give the answer).

Quote
>(2) If you can, skip all the LoadLibrary stuff and declare the
>library-name in the
>routine declaration, e.g. "External 'R16.DLL'"  This puts the burden of
>locating the DLL, finding the routines, etc. upon Windows.

Did you ever try this under native 16-bit Windows?
Note: if you write "External 'R16.DLL'" in Delphi 1, your app
will run under Win9x, but *not* under native Win3xx!
One can write "External 'R16.DLL'#0" or just leave out the '.DLL'.

Helge Pretzlaff

Other Threads