T H U N K I N G ------------------------------------------------------------------------- mails collected Jul-02-1998 from http://www.developers.href.com using search item "thunking" Franz Glaser ------------------------------------------------------------------------- Calling 32-bit-DLL from Delphi 1 ------------------------------------------------------------------------- To: Karsten Strobel From: dblock@vdn.com (David Block) Re: Calling 32-Bit DLL from Delphi-1 Sat, 18 Apr 1998 00:07:08 GMT borland.public.delphi.winapi Karsten- Here's an example of calling a 32 bit DLL (Kernel32.DLL) from 16 bit Delphi. This particular example is for converting long filenames to short. I hope it helps. unit Demo; interface type { These four functions are used for thunking to 32 bits} function LoadLibraryEx32W(LibFileName: PChar; hFile, dwFlags: DWORD): THandle32; function FreeLibrary32W(LibModule: THandle32): BOOL; function GetProcAddress32W(Module: THandle32; ProcName: PChar): TFarProc; function CallProcEx32W(nParam, fXlat, pFn, lpInfile, lpOutfile, dwSize : DWORD) : BOOL; cdecl; function EnumFunc(Wnd:HWND; TargetWindow:PHWND): boolean; export; Function LongToShort(LongName, ShortName : PCHAR; dwSize : LongInt) : Boolean; implementation function LoadLibraryEx32W; external 'KERNEL' index 513; function FreeLibrary32W; external 'KERNEL' index 514; function GetProcAddress32W; external 'KERNEL' index 515; function CallProcEx32W; external 'KERNEL' index 518; Function LongToShort(LongName, ShortName : PCHAR; dwSize : LongInt) : Boolean; var lpGetShortPathName32: pointer; hKernel32 : LongInt; Begin Result := FALSE; { assume we won't do anything or thunk failure } if (CheckOS = 0) then exit; { do nothing under Win31} hKernel32 := LoadLibraryEx32W('KERNEL32.DLL', 0, 0); if (hKernel32 <> 0) then Begin lpGetShortPathName32 := GetProcAddress32W(hKernel32, 'GetShortPathNameA'); if (lpGetShortPathName32 <> nil) then Begin if (CallProcEx32W(3,3, DWORD(lpGetShortPathName32),DWORD(LongName), DWORD(ShortName), dwSize)) then Result := TRUE; { on success, return result } End; FreeLibrary32W(hKernel32); End; End; end. David Block dblock@vdn.com -------------------------------------- Karsten Strobel Steve Turner Re: Calling 32-Bit DLL from Delphi-1 Mon, 20 Apr 1998 09:22:49 +0100 borland.public.delphi.winapi In article <3537B28F.EB254CE9@t-online.de>, Karsten Strobel writes >Hi! > >Can anybody tell me how I can make calls from Delphi-1 (16-Bit) to a >32-Bit DLL (written with Delphi-3)? > Go to the Delphi Super Page (http://www.sunsite.icm.edu.pl/delphi) and take a look at CALL32NT.ZIP, written by Christian Ghisler. I have used it to successfully call 32-bit DLL functions from my D1 apps under Win 95. Hope the above helps. -- Steve Turner Leeds, England ---------------------- =========================================================== 16-bit DLL from Delphi 2 Juergen Peter Below <100113.1101@compuserve.com> Re: 16 Bit DLL + Delphi 2 Wed, 08 Apr 1998 21:09:38 +0200 borland.public.delphi.vcl.components.writing In article <352b68ee.1838873@forums.borland.com>, wrote: > is there anybody who knows how to call a function from a 16 Bit DLL in > Delphi 2 ? > JCrgen, the best solution is without doubt to get a 32-bit version of the DLL. There is a process called thunking that can be used on Win95 (but not NT!) but it requires MS tools (thunk compiler) if done the official way and is version dependent if done the inofficial way (via an undocumented Win95 function named QT_Thunk). The only portable method is to write a small 16-bit program that calls the DLL for the 32-bit side and communicates with that via Windows messages, DDE or acts as an OLE automation server. Peter Below (TeamB) 100113.1101@compuserve.com) ----------- Juergen Jim Gabriel Re: 16 Bit DLL + Delphi 2 Fri, 10 Apr 1998 08:37:52 -0700 borland.public.delphi.vcl.components.writing "Thunking" is what you need to do, however it is platform dependant (Win95 RevA). If you try to do it on a machine with "RevB", the current release you'll bomb. I've done this ALL in Delph and it worked great under REVA, but ended up rewritting the 16bit dll (with lots of inline assembler) to support 32 bit. The DLL no longer exists and it works on all version of 95 and NT. If after thinking about this, you still want to THUNK, there is an article (somewhere on the net,.. I think at the Delphi Informat) that details it perfectly and I couldn't have done it with out it. Good luck jim gabriel Juergen wrote: > Hallo, > is there anybody who knows how to call a function from a 16 Bit DLL in > Delphi 2 ? > > Kind Regards > J.Sonnemann ---------- To: "Greg Carter" From: "Bryce Doster" Subject: Re: 32 to 16 bit thunking examples Date: Mon, 23 Mar 1998 15:12:57 -0800 Newsgroup: microsoft.public.win32.programmer.kernel Did a quick surf of the Jan 98 Devnet CD. Here are some hits to check out: "The Communicating Windows PC", "Calling a 16-bit Process in a 32-bit World?", it has examples. "Win32 Thunking Mechanism", old NT info dealing with OS/2, but shows api examples. "Can't Run Macro That Calls 16-bit DLL in 32-bit MS Excel", seems to have VBA examples. "HOWTO: Debug Flat Thunks", not really examples but looks like good info. "HOWTO: Create an OLE Server to Implement "Thunking"",Q141939, actually has a subheading of, "Example: A 32-bit Program Calling a 16-Bit DLL". I don't know why I have taken the time to look these up...I need to get back to work. Good luck and have fun! Thanks, Bryce Doster --------------- http://www.itecuk.com/delmag/thunk95.htm