撰寫者: Devil(璉璉) Devil.bbs@vlsi1.iie.ncku.edu.tw -------------------------------------------------------------------------- 建立 DOS & Windows 的雙重執行檔 讓您的程式能在 DOS 及 Windows 都能用該跑的模式來跑. 說穿了, 就只是把兩個程式都放在一個檔中. -------------------- test.for -------------------------------------------- Program Main Write(*,*) 'Test' end -------------------------------------------------------------------------- 1.copy FL.def test.def 這是最方便的方法了!! (c:\fortran\binb\FL.def) 2.修改 test.def, 可把註解列殺掉. --------------------- test.def ------------------------------------------ ; DOS & Windows NAME WINDOWAPI APPLOADER '__MSLANGLOAD' EXETYPE WINDOWS 3.0 STUB 'TESTdos.EXE' ; ^^^^^^^^^^^^^ ; 改成 DOS下的執行檔名, 不可和欲輸出的檔名相同. 其它可先不管 PROTMODE CODE PRELOAD MOVEABLE DISCARDABLE DATA PRELOAD MOVEABLE HEAPSIZE 1024 STACKSIZE 8096 --------------------------------------------------------------------- 編譯及連結: Win A:\DOSWIN>fl test.for -> 一般編譯 Microsoft (R) FORTRAN Optimizing Compiler Version 5.10 Copyright (c) Microsoft Corp 1982-1991. All rights reserved. test.for Microsoft (R) Segmented-Executable Linker Version 5.15 Copyright (C) Microsoft Corp 1984-1991. All rights reserved. Object Modules [.OBJ]: test.OBJ Run File [test.exe]: test.EXE List File [NUL.MAP]: NUL Libraries [.LIB]: Definitions File [NUL.DEF]: ; Win A:\DOSWIN>ren test.exe testdos.exe -> stub 的檔名 Win A:\DOSWIN>fl /c /MW7 test.for -> 編成 Windows 的執行檔 Microsoft (R) FORTRAN Optimizing Compiler Version 5.10 Copyright (c) Microsoft Corp 1982-1991. All rights reserved. test.for Win A:\DOSWIN>link test Microsoft (R) Segmented-Executable Linker Version 5.15 Copyright (C) Microsoft Corp 1984-1991. All rights reserved. Run File [test.exe]: List File [NUL.MAP]: Libraries [.LIB]: /nod:llibfor7 llibfew Definitions File [NUL.DEF]: test.def Win A:\DOSWIN>test -> 執行測試 Test Win A:\DOSWIN> 按照以上的方法即可使您的程式在 DOS 下及 Windows 下都能跑!!您甚至可安排 在 DOS 下及 Windows 下有不同的操作方法. 所以這種程式具有真實模式及保護 模式的機器碼. ps *.DEF 檔可用的關鍵字 -------------------------------------------------------------------------- ? NAME Names the application ? LIBRARY Names the DLL ? DESCRIPTION Embeds text in the file ? STUB Adds a DOS executable file to the file ? APPLOADER Replaces the default Windows loader ? EXETYPE Identifies the target operating system ? PROTMODE Specifies a protected-mode application or DLL ? REALMODE Supported for compatibility ? STACKSIZE Sets stack size in bytes ? HEAPSIZE Sets local-heap size in bytes ? CODE Sets default attributes for all code segments ? DATA Sets default attributes for all data segments ? SEGMENTS Sets attributes for specific segments ? OLD Preserves ordinals from a previous DLL ? EXPORTS Defines exported functions ? IMPORTS Defines imported functions