Board index » delphi » Using THUNK to call a 32-bit DLL from a 16-bit application
Brent Darley
![]() Delphi Developer |
Tue, 30 Nov 2004 06:37:01 GMT
|
Brent Darley
![]() Delphi Developer |
Tue, 30 Nov 2004 06:37:01 GMT
Using THUNK to call a 32-bit DLL from a 16-bit application
Hello,
I need to call functions in a 32-bit DLL I am building with Borland C++ 5.01, but they need to be called from a 16-bit application in Windows XP. The DLL has to be 32-bit because it includes a 32-bit library that I can't change. I've heard that it is possible to call a 32-bit DLL from a 16-bit application by using something called a "thunk". So far I found a program called thunk.exe in my \BC5\SDKTOOLS directory and two "universal thunking" libraries called "w32sut32.lib" and "w32sut16.lib" in my \BC5\LIB directory. Does anyone know a good source that describes how to use this thunk Thank you, (I've already learned a great deal from this newsgroup) Brent Darley |
Wayne A. Ki
![]() Delphi Developer |
Tue, 30 Nov 2004 17:07:20 GMT
Re:Using THUNK to call a 32-bit DLL from a 16-bit applicationOn Thu, 13 Jun 2002 17:37:01 -0500, Brent Darley <notbdar...@notcharter.net> wrote: Quote>I've heard that it is possible to call a load and call a 16-bit DLL. To load and call a Win32 DLL from a Win16 application requires the use of Generic thunks. Quote>Does anyone know a good source that describes how to use this thunk information. Since Win16 was abandoned by MS years ago, it may be more difficult to come by this info now. I have some old (1993) code from Walter Oney which was in MSJ. Try these links: http://msdn.microsoft.com/library/en-us/winprog/winprog/about_generic... Also go to http://www.microsoft.com/msj/ and search for "thunks". Quote>is it just a simple process to describe. it might be quite a challenge to get it right. -- |
Günter Wirt
![]() Delphi Developer |
Mon, 06 Dec 2004 15:20:35 GMT
Re:Using THUNK to call a 32-bit DLL from a 16-bit applicationHi, I had the same problem in the past. Here my solution. Regards, <<<<<<<<<Header>>>>>>>>>> //$HB$--------------------------------------------------------------------- #if !defined(__EXMAIDLL_H) // To use in a DLL, define EXGT32DLL #if !defined(__WIN32__) // Generelle Einstellungen und Compileroptionen um Klassen zu definieren DECLARE_HANDLE32 (HPROC32); // Klasse ExGenericThunk ~ExGenericThunk (); bool IsOK () const { return mInst32 != 0; } protected: ExGenericThunk(const char * fileName); ExGenericThunk(const ExGenericThunk& thunk); DWORD __cdecl CallProc32 (HPROC32, DWORD fAddrCvt, DWORD nArgs, ...); private: HINSTANCE32 mInst32; static HINSTANCE32 (WINAPI *LoadLibraryEx32W) (LPCSTR, DWORD, DWORD); void Init(const char* fileName); #endif // __WIN32__ #endif // __EXGT32_H /* EOF */ <<<<<<<<<<< Code >>>>>>>>>>>> /* #include <exmaidll.h> #ifndef __WIN32__ // only for 16-bit platform #include <stdarg.h> HINSTANCE32 (WINAPI *ExGenericThunk::LoadLibraryEx32W) (LPCSTR, DWORD, void ExGenericThunk::Init(const char* fileName) // Initialize our static members if they're not already: (FARPROC) LoadLibraryEx32W = GetProcAddress (hKernel, // All or nothing: mInst32 = 0; if (LoadLibraryEx32W) delete [] lpszFile; return *this; if (! CallProc32W || ! hProc) va_start (args, nArgs); // Copy the arguments from our stack frame to the stack frame that __asm push word ptr [dwTemp+2]; va_end (args); // Call CallProc32W. The pushed variable list precedes the parameters, if (uSelector) { return MAKELP (uSelector, 0); /* EOF */ <<<<< How to use >>>>>> class TFileThunk : public ExGenericThunk { private: |
1. call 16 Bit DLL from 32 Bit Delphi Application
2. Calling 16 bit DLL from 32 bit application
3. Using a 32 bit DLL in a 16 bit BPW application
4. Using 32 bit DLL in 16 bit BPW application
5. Porting 16 bit DOS Application to 32 bit DOS Application using BC++ 5.0
6. Calling 16 bit Dll from 32 bit program
7. thunking (calling 16 bit dll's from 32 bit app)
8. Calling 16-bit DLLs from 32-bit Apps
9. Q: 16 bit code calling 32-bit DLL on Win 3.1
10. Accessing a 16 bit dll from a 32 bit application (written in VB 6.0)