Author Topic: Static linking of 16-bit and 32-bit code  (Read 5073 times)

jj2007

  • Member
  • *****
  • Posts: 9743
  • Assembler is fun ;-)
    • MasmBasic
Static linking of 16-bit and 32-bit code
« on: December 12, 2013, 10:08:24 PM »
I wonder if it is possible to link 16-bit lib or obj files with 32-bit lib or obj files.

Related: How can you use the 16-bit LoadLibrary call in assembler?

Any ideas?

dedndave

  • Member
  • *****
  • Posts: 8823
  • Still using Abacus 2.0
    • DednDave
Re: Static linking of 16-bit and 32-bit code
« Reply #1 on: December 12, 2013, 10:23:12 PM »
google the term "thunk"
although, i can't imagine why   :P

jj2007

  • Member
  • *****
  • Posts: 9743
  • Assembler is fun ;-)
    • MasmBasic
Re: Static linking of 16-bit and 32-bit code
« Reply #2 on: December 12, 2013, 10:56:10 PM »
google the term "thunk"
although, i can't imagine why   :P
Thunking from 16-bit Windows 3.1 code to a 32-bit DLL is easy, but that's not the problem. I'd like to link statically.

japheth

  • Guest
Re: Static linking of 16-bit and 32-bit code
« Reply #3 on: December 12, 2013, 11:08:25 PM »
I'd like to link statically.

That's no problem - so long as you don't try to call the 16-bit code. There's no relocation type for a 16-bit far call in the PE format.

jj2007

  • Member
  • *****
  • Posts: 9743
  • Assembler is fun ;-)
    • MasmBasic
Re: Static linking of 16-bit and 32-bit code
« Reply #4 on: December 12, 2013, 11:41:43 PM »
I'd like to call the 32-bit code from the 16-bit code. One option I see is to load relocatable 32-bit code into 16-bit memory, and call it from there with CallProc32W.

But how can I get the address of CallProc32W from a 16-bit DOS program?

sinsi

  • Member
  • *****
  • Posts: 1184
Re: Static linking of 16-bit and 32-bit code
« Reply #5 on: December 13, 2013, 12:00:59 AM »
You might have to put the 32-bit code in a dll.

Quote
Windows NT, Windows 95, Windows 98, and Windows 2000 do not allow direct mixing of 16-bit code and 32-bit code in the same process.
Quote
Generic thunks allow a 16-bit Windows-based application to load and call a Win32-based DLL.
http://support.microsoft.com/kb/125710
I can walk on water but stagger on beer bourbon.

japheth

  • Guest
Re: Static linking of 16-bit and 32-bit code
« Reply #6 on: December 13, 2013, 12:04:12 AM »
But how can I get the address of CallProc32W from a 16-bit DOS program?

I'd say that's not possible.

A 16-bit DOS real-mode program in XP that wants to execute 32-bit may do

- call exports of a Win32 dll ( using so-called BOPs )    OR
- switch to protected-mode via DPMI and then call 32-bit code directly ( after having done some low-level selector stuff ).

sinsi

  • Member
  • *****
  • Posts: 1184
Re: Static linking of 16-bit and 32-bit code
« Reply #7 on: December 13, 2013, 12:07:48 AM »
Oops, didn't see the DOS bit. Maybe your DOS program could talk to a 16-bit Windows .vxd which could then talk to a 32-bit .dll
I can walk on water but stagger on beer bourbon.

jj2007

  • Member
  • *****
  • Posts: 9743
  • Assembler is fun ;-)
    • MasmBasic
Re: Static linking of 16-bit and 32-bit code
« Reply #8 on: December 13, 2013, 12:29:37 AM »
You might have to put the 32-bit code in a dll.

That's what I always did, but I'd like to go the static linking route. BOPs sounds interesting, though. Actually, it's a 16-bit Win app that calls the code, but for testing, 16-bit console would be nice...

sinsi

  • Member
  • *****
  • Posts: 1184
I can walk on water but stagger on beer bourbon.

jj2007

  • Member
  • *****
  • Posts: 9743
  • Assembler is fun ;-)
    • MasmBasic
Re: Static linking of 16-bit and 32-bit code
« Reply #10 on: December 13, 2013, 03:14:54 AM »
Thanks, John & Dave & Japheth - I knew I had seen that BOP stuff before ;-)