Solved

Win16 app calling win32 dll

Posted on 1999-01-09
13
357 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 500 total points
ID: 1418370
0
 
LVL 11

Expert Comment

by:alexo
ID: 1418371
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

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…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…

729 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