Solved

Generic Thunking to Win32 functions from Win16

Posted on 1997-06-29
5
508 Views
Last Modified: 2013-12-03
I need my 16-bit app to take advantage of a couple of simple Win32 functions if it is running under Windows 95/NT.  Apparently it is reasonably feasible to do this with the thunking functions LoadLibraryEx32W, GetProcAddress32W,  CallProc32W and FreeLibraryEx32W.

I've built a little routine to test this and it fails every time with a nasty system error, and I'm not surprised, since they are not part of the Win16 interface and I never specifically linked their library in.

What DLL do these functions live in and how do you safely link to them at compile time (and at run-time, where they may not exist for Win16 ?).

Suggestions gratefully received.
0
Comment
Question by:scce
  • 3
  • 2
5 Comments
 
LVL 23

Accepted Solution

by:
chensu earned 100 total points
ID: 1399591
They live in the system kernel. As the documentation says,

Using Microsoft Visual C++, you would create an import library like this one:
IMPORTS
    kernel.LoadLibraryEx32W
    kernel.FreeLibrary32W
    kernel.GetProcAddress32W
    kernel.GetVDMPointer32W
    kernel.CallProc32W

At run time, I think you need to detect the Windows version, if it is running in 16-bit version, you should bypass the generic thunk functions.
0
 

Author Comment

by:scce
ID: 1399592
Thanks, chensu.  I'll try that and see if I have more success. A couple of points still trouble me about that though.

 1.  Isn't the 32-bit kernel named kernel32.dll ?  If this is the name that should be used in the imports section, then doesn't that create a dependency in the application which will cause it to fail to start up under Win16, even if those functions calls are avoided?
0
 
LVL 23

Expert Comment

by:chensu
ID: 1399593
I think 32-bit version Windows has two kernels actually. One is 16-bit, another is 32-bit so that it can run 16-bit applications. Since your application is 16-bit, you have to link to the 16-bit kernel DLL which does thunk for you. 16-bit applications cannot link to 32-bit DLLs directly (Otherwise, you do not need Generic Thunk.).
0
 

Author Comment

by:scce
ID: 1399594
Hi chensu,

I've just tried your suggestion, and I think I'm nearly there, but there is still a problem there.

The 16-bit kernel is called KRNL386.EXE, but I can't put this in the IMPORTS section of the DEF file because it's an EXE file not a DLL.  The program fails to load because it is looking for KRNL386.DLL (which it assumes is the default import module extension) not KRNL386.EXE (which it should be).

Import lines of the format
IMPORTS
      KRNL386.EXE.LoadLibraryEx32W
do not work.

How you do import functions from EXE files?  The documentation seems to suggest it should be possible by saying things like "importing from DLL or Application Program", but never actually gives an example.

Any ideas?

Thanks.

scce
0
 
LVL 23

Expert Comment

by:chensu
ID: 1399595
Have you tried kernel.LoadLibraryEx32W as Microsoft documentation says? I think "kernel" is the module name.
0

Featured Post

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question