Article View: comp.os.os2.programmer
Article #1223Re: Linking 16-bit Code with 32-bit code
From: dave
Date: Fri, 28 Aug 1992 17:18
Date: Fri, 28 Aug 1992 17:18
66 lines
2891 bytes
2891 bytes
In <1992Aug27.215047.28937@natinst.com> Malathi Ramdas writes:
> I am trying to call function in a 16-bit code from a 32-bit
> application. The 16-bit object code is compiled using the MSC 6.0
> compiler while the 32-bit application is compiled using CSET/2. I
> wish to statically link these two object files. Would link386 be
> suitable to link this 16- and 32-bit code? Are there any link
> options that I need to specify in order to get things to work. My
> 16-bit code also makes 16-bit DOS API calls. Also, while compiling the
> 16-bit code do I need to give any options so that it would be
> callable by 32-bit code?
First of all, if you are going to statically link 32-bit and 16-bit
modules into a single .EXE there are a few rules you have to follow.
Number one, no pooftas [1]. Number two, the 16-bit code cannot make any
calls to the runtime library. Number three, you have to compile the
16-bit code using the /NTCODE16 /NDDATA16 /Zl /Gs options. And in any
32-bit-to-16-bit call, the 16-bit stuff has to be large model (or at the
very least, the entry points visible to the 32-bit code have to be 16:16
pointers). So for your code to work, you have to delete the call to
printf() (or move it to the 32-bit code and do a call back to it) and you
have to add a few more compiler options. This code should work:
/* --- main32.c --- */
#include <stdio.h>
void _Far16 _Cdecl func(char *s);
int main(void) {
func("Hello\n");
return 0;
}
void _Far16 _Cdecl puts32( char * _Seg16 text ) {
puts(text);
return;
}
/* --- func16.c --- */
void func( char *s ) {
puts32(s);
return;
}
Compile with
cl -c -AL -NDDATA16 -NTCODE16 -Gs -Zl func16.c
icc -Gt main32.c func16.obj
and ignore the L4008 warning message which the linker gives you.
A much simpler way to do this is to build the 16-bit code as a DLL,
export all the entry points in the 16-bit code, and call it dynamically.
Take a look at SAMPLE04, which came with C Set/2, for an example of how
to do this.
dave
[1] Number 2, I don't want to catch anyone not drinking. Mind if we call
you Bruce?
-------------------------------------------------------------------------
Dave Mooney dmm@vnet.ibm.com
C Set/2 Development, IBM Canada Lab, 844 Don Mills Rd, Toronto, Ontario
"If you've got a blacklist, I want to be on it"
Technical Details
Message-ID:
<19920828.102941.559@almaden.ibm.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!vnet.ibm.comReferences:
<1992Aug27.215047.28937@natinst.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!vnet.ibm.com From: dmm@vnet.ibm.com (dave) Message-ID: <19920828.102941.559@almaden.ibm.com> Date: Fri, 28 Aug 92 13:18:25 EDT Newsgroups: comp.os.os2.programmer,comp.os.os2.apps Subject: Re: Linking 16-bit Code with 32-bit code Organization: IBM Canada Lab News-Software: UReply 3.0 X-X-From: dmm@vnet.ibm.com (Dave Mooney) References: <1992Aug27.215047.28937@natinst.com> Lines: 66