Solved

Generic Thunking to Win32 functions from Win16

Posted on 1997-06-29
5
503 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Have you tried kernel.LoadLibraryEx32W as Microsoft documentation says? I think "kernel" is the module name.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now