Solved

Generic Thunking to Win32 functions from Win16

Posted on 1997-06-29
5
512 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
error email attachment VB2010 5 54
VBA Error Since Excel 2016 x64 5 143
Clean Uninstall of VS Professional 2015 5 60
Licensing Sharepoint 2016 for developers 11 77
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…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

733 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