Microsoft KB Archive/102693

From BetaArchive Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

PSS ID Number: 102693

Article Last Modified on 5/5/2001



The information in this article applies to:

  • Microsoft FORTRAN Compiler for MS-DOS 5.1



This article was previously published under Q102693

SYMPTOMS

An attempt to link a dynamic-link library (DLL) for the Microsoft Windows operating system fails and Microsoft LINK generates the following message:

error L2029: '_exit' : unresolved external

CAUSE

Microsoft FORTRAN does not support using the STOP statement in a DLL developed for Windows.

RESOLUTION

To terminate the DLL and the calling application, use the SendMessage() function in the Windows application programming interface (API) to send the calling application a WM_QUIT message. The code example below demonstrates this technique.

MORE INFORMATION

The code example below terminates the DLL and the calling application after displaying a message box warning the user to save all data.

Sample Code - EXIT.FOR

C Compiler options needed: /c /Od /Zi /AL

      interface to integer*2 function PostAppMessage[pascal]
     + (htask, msg, wparam, lparam)
      integer*2 htask[value]
      integer*2 msg[value]
      integer*2 wparam[value]
      integer*4 lparam[value]
      end

      interface to integer*2 function GetCurrentTask[pascal]
      end

      interface to integer*2 function MessageBox[pascal]
     + (hwnd, boxtext, caption, boxtype)
      integer*2   hwnd[value]
      character*1 boxtext[reference]
      character*1 caption[reference]
      integer*2   boxtype[value]
      end

      subroutine exit
      integer*2 in
      character buffer1*120, buffer2*80
      integer*2 i, WM_QUIT, PostAppMessage, GetCurrentTask, MessageBox
      WM_QUIT = #12

      buffer1 =
     +'************** DLL issued STOP Statement ************'// 
     +'\n  Application will terminate. Save contents of windows NOW'c
      buffer2 = 'DLL STOP'c

      i = MessageBox(0, buffer1, buffer2, 0)
      i = PostAppMessage(GetCurrentTask(), WM_QUIT, in, 0)
      return
      end
                

The following QuickWin driver program calls the subroutine in DLLTEST.FOR.

Sample Code - TEST.FOR

C Compiler options needed: /c /Od /Zi /MW

      program testdllstop
      print *, 'before calling DLL'
      call dllsub
      print *, 'back from sub1'
      end
                

The following DLL displays a dialog box and calls the exit subroutine to close the DLL and the calling application.

Sample Code - DLLTEST.FOR

C Compiler options needed: /c /Od /Zi /Aw /Gw

      interface to integer*2 function MessageBox[pascal]
     + (hwnd, boxtext, caption, boxtype)
      integer*2   hwnd[value]
      character*1 boxtext[reference]
      character*1 caption[reference]
      integer*2   boxtype[value]
      end

      subroutine dllsub
      integer*2 messagebox
      i = MessageBox(int2(0), 'Prior to STOP statement in DLL'c,
     + ' 'c, 0)
      call exit
      end
                

DLLTEST.DEF

LIBRARY     DLLTEST
EXETYPE     WINDOWS
CODE        PRELOAD MOVEABLE DISCARDABLE
DATA        PRELOAD MOVEABLE SINGLE
HEAPSIZE    1024
EXPORTS     DLLSUB
            WEP
                

MAKEFILE

all: test.exe dlltest.dll

test.obj: test.for
   fl /c /Od /Zi /MW test.for

dlltest.obj: dlltest.for
   fl /c /Od /Zi /Aw /Gw dlltest.for

exit.obj: exit.for
   fl /c /Od /Zi /AL exit.for

dlltest.dll: dlltest.obj exit.obj
   link dlltest exit, dlltest.dll, nul, /co /nod ldllfew, dlltest.def;

dlltest.lib: dlltest.def
   implib dlltest.lib dlltest.def

test.exe: test.obj dlltest.lib
   link test, test, nul, /co /nod llibfew dlltest,
      c:\fortran\binb\fl.def;
                


Additional query words: 5.10

Keywords: KB102693
Technology: kbAudDeveloper kbFORTRAN510DOS kbFortranSearch kbZNotKeyword3