Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Calling 16bit DLL from 32 bit Process under NT

Posted on 1998-11-12
1
Medium Priority
?
240 Views
Last Modified: 2010-04-15
I have a 16 bit DLL (written in MS C), but the source code has been lost.  I want to call this DLL from either 32 MSC (Visual Studio 5/6) or 32 bit VB 5/6.  Can you either post an example how to do this, or direct me to documentation that describes how to do this?
0
Comment
Question by:rmichels
[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
1 Comment
 
LVL 2

Accepted Solution

by:
abesoft earned 450 total points
ID: 1254245
Well, this is a complex problem.

There are no truly portable thunking mechanisms available under Win32.  There are "Universal thunks", "Flat thunks", and "Generic Thunks", but none of them are available under all of 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/COM (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.

Finally, you should consider what the 16-bit DLL is doing.  If it is providing GUI interfaces or controls, you might find that even thunking to it won't get you very far, due to the fact that Win32 has re-mapped so many messages that are passed to a window.
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.

704 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