?
Solved

Win16 app calling win32 dll

Posted on 1999-01-09
13
Medium Priority
?
361 Views
Last Modified: 2013-12-03
Hi

We have an app that we developed for a dll
the app itself is 16-bit
we formely developed a 16-bit dll for it's use.

now we have a 32-bit version of that dll and we
need it to work without recompiling the app itself.

so how is done ?

if there is no straitforward way to do that , can I do that:

-create a 16-bit dll with "ghost" functions sutiable for the
 app ( the same as the original 16-bit dll) , this dll
 will in turn call the new 32-bit dll that will also return
 values to the 16-bit dll and from there to the app.

I don't need only a answer , I need a working example in
c/c++.

please post your answers here and send your example file
to moshem@cpm.elex.co.il
0
Comment
Question by:moshem
[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
  • 7
  • 5
13 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1418369
16 bit code can call 32 bit code, but it is a real pain.  The process is called thunking and is documented in the microsoft help.  (Look up Thunk Compiler).  Since this involves changes only on the 32 bit side, I believe you do not have to write a "ghost" dll.  But, you may want to do that anyways as it would allow you to leave the main DLL unchanged when your 16 bit code is no longer needed.
0
 
LVL 11

Accepted Solution

by:
alexo earned 2000 total points
ID: 1418370
0
 
LVL 11

Expert Comment

by:alexo
ID: 1418371
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
LVL 1

Author Comment

by:moshem
ID: 1418372
Sorry guys , I forgot to tell you that my dll need to
be multithreaded and I read somewhere the thunking does
not work with threads.

prove me wrong
0
 
LVL 11

Expert Comment

by:alexo
ID: 1418373
>> prove me wrong
I cannot do that, Moshe, because you are correct.  The documentation says:
"16-bit processes cannot create new threads. Certain Win32 elements, such as the functions supporting the common dialog boxes or those supporting console applications, create threads on behalf of the calling application. These functions cannot be used in a Win32-based DLL loaded by a 16-bit process."

And, in Q133722:
"You cannot create threads inside a thunk from a Win16-based application to a Win32-based DLL."

Bummer...

Let's try an alternative approach.
You can run a hidden Win32 application that will load the 32bit DLL.  Your Win16 application can communicate with the Win32 application by means of WM_COPYDATA messages, named pipes, DDE, OLE or RPC.
0
 
LVL 1

Author Comment

by:moshem
ID: 1418374
well that mean I need to change the win16 app and I can't do
that , any other thoughts ?
0
 
LVL 11

Expert Comment

by:alexo
ID: 1418375
>> well that mean I need to change the win16 app and I can't do that
You don't need to.

Write a replacement Win16 DLL that will communicate with The Win32 application.  For each function in the old Win16 DLL, write a replacement function in the new Win16 DLL that will communicate with the Win32 application using one of the methods I suggested.  The Win32 application will in turn invoke the needed function in the Win32 DLL and pass the results (if any) back to the new Win16 DLL.  The DllMain() of the new Win16 DLL can take care of initialization.

I think that the easiest IPC method is WM_COPYDATA messages.
Read http://support.microsoft.com/support/kb/articles/q114/3/41.asp for some details.
Get sample code from the platform SDK.
0
 
LVL 1

Author Comment

by:moshem
ID: 1418376
that's a very unelegent solution , can you think of something
else , maybe insted of WM_COPYDATA ?

if not , can you email me the sample from the SDK ?
to : moshem@cpm.elex.co.il
0
 
LVL 11

Expert Comment

by:alexo
ID: 1418377
Moshe, there is no elegant solution for what you need, the windows model does not support it so you must "letachmen".  If the Win32 DLL wasn't multithreaded you could use generic thunks.  Since it is, your only option is interprocess communications, and that requires two processes.  If you dont like WM_COPYDATA, you can use another IPC mechanism but you'll still need two processes.

You can get the relevant SDK samples from:
  http://msdn.microsoft.com/developer/sdk/winbase.htm

0
 
LVL 1

Author Comment

by:moshem
ID: 1418378
can you explain in detail , why whould this work with a multithreaded application ?
0
 
LVL 11

Expert Comment

by:alexo
ID: 1418379
Moshe, the URL I gave you is incorrect.  I'll send you the sample by email.  Subject: "INTEROP sample".
0
 
LVL 11

Expert Comment

by:alexo
ID: 1418380
>> can you explain in detail , why whould this work with a multithreaded application?

We seem to have a misunderstanding there, a Win16 application cannot be multithreaded.  Maybe you mean a multithreaded DLL?

A Win16 application cannot be multithreaded.  While it can load a 32bit DLL (using thunks) the code in that DLL is executed in the context of the Win16 application and must abide by the restrictions of the Win16 model.

If you're communicating between a Win16 app and a Win32 app, the Win32 app can be multithreaded.

This is getting cumbersome to explain.  Drop me a call (I'll send you my phone number in email).
0
 
LVL 1

Author Comment

by:moshem
ID: 1418381
Thanks Alex.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
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 this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

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