Please help: how to load a 32bit DLL within a 16bit application under Win95

Please help: how to load a 32bit DLL within a 16bit application under Win95

Post by P.B.T.Weustin » Fri, 08 Nov 1996 04:00:00



Hello,

I am using Borland C++ 4.52 under Win95.
I'd like to call a 32bit DLL from a 16bit application.
I can create the DLL and the application. When I try to load
the 32bits DLL in the 16bit program with LoadLibrary(), the
function returns an error of code:

21      Application requires Microsoft Windows 32-bit extensions.

Why do I get this message? I am running Win95, do I need Win32s ???

Thanks for any help, Paul

       |\      _,,,---,,_         Paul Weustink
 ZZZzz /,`.-'`'    -.  ;-;;,_     phone: +31 53 4892806
      |,4-  ) )-,_. ,\ (  `'-'    fax  : +31 53 4892223

                                  Control Laboratory, Dept. EE,
                                  University of Twente, Netherlands

---------------------- THE 32BIT DLL -------------------------------
#define  STRICT
#include <windows.h>

/* 32bit DLL entry point */
BOOL WINAPI DllEntryPoint (HINSTANCE hinstDll, DWORD fdwRreason, LPVOID
plvReserved)
{
         return 1;

Quote:}

/* exit procedure */
int FAR PASCAL WEP (int bSystemExit)
{
         return 1;

Quote:}

/* The function I would like to call */
void _export MyFunction (double *y)
{
        int x = 1;
        *y = *y + x;

Quote:}

------------------------------ THE 16BIT APPLICATION ------------------

#include <windows.h>
#include <stdio.h>

/* the 16bit main program */
int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance, LPSTR
lpCmdLine, int nCmdShow)
{
    double y;
    char msg[256];
    HINSTANCE testDLL;
    void (FAR *lpMyFunction)(double *);

    /* try to load the 32bit DLL */
    HINSTANCE testDLL = LoadLibrary ((LPCSTR) "test.dll");

    if ((UINT) testDLL > HINSTANCE_ERROR)
    {
        /* try to load the function */
        (FARPROC) lpMyFunction = GetProcAddress (testDLL, "MyFunction");
        if (lpMyFunction)
        {
            y = 1.0;

            /* call the 32bit function */
            (*lpMyFunction)(&y);

            sprintf (msg, "y = %g", y);
            MessageBox (0, msg, "result", MB_OK);
        }
        else
            MessageBox (0, "MyFunction not found", "error", MB_OK);

        /* unload the library */
        FreeLibrary (testDLL);
    }
    else
    {
        sprintf (msg, "test.dll not found, error = %d", (UINT) testDLL);
        MessageBox (0, msg, "error", MB_OK);
    }

    return 0;

Quote:}

 
 
 

Please help: how to load a 32bit DLL within a 16bit application under Win95

Post by Bret Pehrso » Fri, 08 Nov 1996 04:00:00



> Hello,

> I am using Borland C++ 4.52 under Win95.
> I'd like to call a 32bit DLL from a 16bit application.
> I can create the DLL and the application. When I try to load
> the 32bits DLL in the 16bit program with LoadLibrary(), the
> function returns an error of code:

> 21      Application requires Microsoft Windows 32-bit extensions.

> Why do I get this message? I am running Win95, do I need Win32s ???

The simple fact of the matter is that Win16 code cannot call Win32 code,
and vice versa.  So, Windows will not let your 16 bit app load a 32 bit
dll.

To get around this restriction, you must use thunks.  This can be a
difficult is is generally non-portable between Win95 and WinNT.

You may elect to aquire a copy of Matt Pietrek's "Windows 95 System
Programming Secrets," an excellent book that covers, among other
important things, the issue of 16-32 bit thunks.  Other sources include
the Microsoft Developer Network CD and portions of the Win32 SDK.

There are other techniques to loading 32 bit code into 16 bit apps by
modifying the code page at runtime.  This technique was used a lot
before Win32 was a reality.  I spent a little time with this technique
back in the old Win3.1 days, but was never able to get it to work with
Borland compilers.  I forget exactly where I saw the technique, probably
in one of the trade journals (probably Win/DOS Developer's Journal).

Good luck!

--

*Please carbon-copy all responses to newsgroup
--

 
 
 

1. Loading 16bit DLL in 32bit application

Hi,

Please reply by email because I usually don't read this newsgroup.
Thnx in advance.

Problem: I'm writing a 32bit application and have my problems
even loading a 16bit DLL. I have an ISDN card which I'd like
to access through the CAPI20.DLL. The pity is that the manufacturer
didn't build/ship any CAPI2032.DLL...

Question: Is it possible to load a 16bit DLL in a 32bit application
(LoadLibrary() always returns NULL) ? And if yes: how?
I use a VC++ 4.2 compiler. The program doesn't hve to work under
Win3.xx, only under Win95/NT 4.0.

Thanx in advance for your answer.

Cheers
        -boby

--

--Finagle's First Law: If an experiment works, something has gone wrong--

2. local admin rights ?

3. Help : Calling a 16Bit Dll from 32Bit Application

4. Mac IIci Soft Power quirk

5. Loading 32bit DLL from 16bit programs

6. TVPaint 3.6 Wanted

7. Loading 16bit dll's in a 32bit app

8. TPF Socks?

9. PIPES between 16bit DLL and 32bit Application.

10. sharing memory between 16bit kernel application and 32bit ring 3 application

11. Call 32bit DLL from 16bit app? HELP!

12. How to call 32bit DLL from 16bit DLL?

13. 16Bit dll called from Win95 Application