Thunking 16Bits dll's to 32Bits Project

Posted on 1998-05-21
Last Modified: 2012-06-27
How can I use a 16 Bits dll in my 32 Bits App using Borland C++ 5.02?
Question by:nosredna
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
  • 2
LVL 11

Expert Comment

ID: 1164448
You'll have to use the "Flat thunks" mechanism.  Use the thunk compiler (thunk.exe).
The process is explained in KB articles Q125715 and Q142564.  Also see the Borland help about "flat thunks" and "thunk compiler"


Author Comment

ID: 1164449
alexo's, thanks for your answer, but
I would like a response step by step how to proceed. I've tried some times to use
Thunk.exe with a script file .thk but there was some error messages.

LVL 11

Expert Comment

ID: 1164450
Never used it myself.  If you reopen the question somebody else may give you a better answer.
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Accepted Solution

abesoft earned 200 total points
ID: 1164451
Well, this is a complex problem.

There are no truly portable thunking mechanisms available under Win32.  There are "Universal thunks", "Flat thunks", and one other one that I can't remember at the moment, but none of them are available under 95, NT, and Win32s.  (I am assuming that you only care about Intel chips for NT, right?  Otherwise, I think you're completely out of luck, since Alpha etc doesn't run 16 bit apps...)  Also, under NT, there are no MS-provided thunks that will let a 32-bit process call a 16-bit DLL.

When I had to solve this problem, I used DDE in a C++ class provide thunks across all win32 platforms.  It wasn't exactly pretty, but here's the general gist:
1) The main entry point of the app was a 16-bit executable, and it would first detect that you had Win32s or a real 32 bit platform to run on.  (This was a nice side-effect of the solution...)  It would then exec the real 32-bit app, and open a connection to it.
2) Whenever a 32-bit routine wanted to call a thunked routine, it would call it via a class that I had written.
3) The class would take the function parameters, convert them into a portable format (in this case, text... watch out for pointers...) and pass them via DDE to the 16-bit executable.
4) The 16-bit executable would decode the parameters, dynamically load the DLL, and call the function.  It would then encode the result and pass it back....

Obviously, adding a new routine involved writing a fair amount of code, but it is mostly cookie-cutter stuff if you design your class nicely.

Other options avaialble are wrapping the whole thing in OLE (which was not an option for us since we wanted to support early Win32s which didn't do OLE), use WM_COPYDATA instead of DDE (not available on all platforms) or, well, there are a LOT of options here... but they all come down to the same kind of approach.

Expert Comment

ID: 1164452
Just remembered it: The other thunk mechanism is "Generic Thunk".  (And all none of the MS-thunks are generic or universal, regardless of the neames... ;)
LVL 11

Expert Comment

ID: 1164453
There are "flat", "generic" and "universal" thunks.  Some are Win95 specific, some are for NT and some work with Win32s.  Check the KB articles I mentioned in my rejected answer.

Author Comment

ID: 1164454
It seems very easy and I will try.
Thanks for your answer.

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

737 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