?
Solved

Generic Thunking to Win32 functions from Win16

Posted on 1997-06-29
5
Medium Priority
?
519 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 300 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

770 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