home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / os / os2 / programm / 4509 < prev    next >
Encoding:
Text File  |  1992-08-29  |  2.8 KB  |  80 lines

  1. Xref: sparky comp.os.os2.programmer:4509 comp.os.os2.apps:5619
  2. Path: sparky!uunet!vnet.ibm.com
  3. From: dmm@vnet.ibm.com (dave)
  4. Message-ID: <19920828.102941.559@almaden.ibm.com>
  5. Date: Fri, 28 Aug 92 13:18:25 EDT
  6. Newsgroups: comp.os.os2.programmer,comp.os.os2.apps
  7. Subject: Re: Linking 16-bit Code with 32-bit code
  8. Organization: IBM Canada Lab
  9. News-Software: UReply 3.0
  10. X-X-From: dmm@vnet.ibm.com (Dave Mooney)
  11. References: <1992Aug27.215047.28937@natinst.com>
  12. Lines: 66
  13.  
  14. In <1992Aug27.215047.28937@natinst.com> Malathi Ramdas writes:
  15. > I am trying to call function in a 16-bit code from a 32-bit
  16. > application.  The 16-bit object code is compiled using the MSC 6.0
  17. > compiler while the 32-bit application is compiled using CSET/2. I
  18. > wish to statically link these two object files. Would link386 be
  19. > suitable to link this 16- and 32-bit code?  Are there any link
  20. > options that I need to specify in order to get things to work. My
  21. > 16-bit code also makes 16-bit DOS API calls. Also, while compiling the
  22. > 16-bit code do I need to give any options so that it would be
  23. > callable by 32-bit code?
  24.  
  25. First of all, if you are going to statically link 32-bit and 16-bit
  26. modules into a single .EXE there are a few rules you have to follow.
  27. Number one, no pooftas [1].  Number two, the 16-bit code cannot make any
  28. calls to the runtime library.  Number three, you have to compile the
  29. 16-bit code using the  /NTCODE16 /NDDATA16 /Zl /Gs  options.  And in any
  30. 32-bit-to-16-bit call, the 16-bit stuff has to be large model (or at the
  31. very least, the entry points visible to the 32-bit code have to be 16:16
  32. pointers).  So for your code to work, you have to delete the call to
  33. printf() (or move it to the 32-bit code and do a call back to it) and you
  34. have to add a few more compiler options.  This code should work:
  35.  
  36.   /* --- main32.c --- */
  37.  
  38.   #include <stdio.h>
  39.  
  40.   void _Far16 _Cdecl func(char *s);
  41.  
  42.   int main(void) {
  43.     func("Hello\n");
  44.     return 0;
  45.   }
  46.  
  47.   void _Far16 _Cdecl puts32( char * _Seg16 text ) {
  48.     puts(text);
  49.     return;
  50.   }
  51.  
  52.   /* --- func16.c --- */
  53.  
  54.   void func( char *s ) {
  55.     puts32(s);
  56.     return;
  57.   }
  58.  
  59. Compile with
  60.  
  61.   cl -c -AL -NDDATA16 -NTCODE16 -Gs -Zl func16.c
  62.   icc -Gt main32.c func16.obj
  63.  
  64. and ignore the L4008 warning message which the linker gives you.
  65.  
  66. A much simpler way to do this is to build the 16-bit code as a DLL,
  67. export all the entry points in the 16-bit code, and call it dynamically.
  68. Take a look at SAMPLE04, which came with C Set/2, for an example of how
  69. to do this.
  70.  
  71. dave
  72.  
  73. [1] Number 2, I don't want to catch anyone not drinking.  Mind if we call
  74.     you Bruce?
  75.  
  76. -------------------------------------------------------------------------
  77. Dave Mooney                                              dmm@vnet.ibm.com
  78.  C Set/2 Development, IBM Canada Lab, 844 Don Mills Rd, Toronto, Ontario
  79.             "If you've got a blacklist, I want to be on it"
  80.