Solved

Generic Thunking to Win32 functions from Win16

Posted on 1997-06-29
5
504 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
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…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

895 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

12 Experts available now in Live!

Get 1:1 Help Now