Solved

Win16 app calling win32 dll

Posted on 1999-01-09
13
346 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
  • 7
  • 5
13 Comments
 
LVL 22

Expert Comment

by:nietod
Comment Utility
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
Comment Utility
0
 
LVL 11

Expert Comment

by:alexo
Comment Utility
0
 
LVL 1

Author Comment

by:moshem
Comment Utility
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
Comment Utility
>> 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
Comment Utility
well that mean I need to change the win16 app and I can't do
that , any other thoughts ?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 11

Expert Comment

by:alexo
Comment Utility
>> 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
Comment Utility
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
Comment Utility
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
Comment Utility
can you explain in detail , why whould this work with a multithreaded application ?
0
 
LVL 11

Expert Comment

by:alexo
Comment Utility
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
Comment Utility
>> 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
Comment Utility
Thanks Alex.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
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…
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…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now