Okay, I warned before that I have not a lot of experience with link.exe. Here a summary of my attempts.
GENERAL OBJECTIVE: I am trying to LINK the object file WindowsStub.obj and the DOS-executable HELLO.exe to form a windows executable WindowsStub.exe that has HELLO.exe as a DOS-STUB.
FIRST ATTEMPT TO REACH THE GENERAL OBJECTIVE (this attampt badly failed and is given for the sake of completion only, it is probably best the reader directly goes to the second attempt given below):
I tried to see if I could get link.exe to do something "simple": to create WindowsStub.exe from WindowsStub.obj.
In order to do this I first tried to use link.exe (obtained from the MASM32 package). I put the file link.exe in the same folder as the file WindowsStub.obj and went with the command prompt to that folder and issued the command
link WindowsStub.obj
I then got the following error message:
link.exe - Unable To Locate Component
This application has failed to start because mspdb50.dll was not found.
Re-installing this application may fix this problem.
So then, -following this suggestion-, I copied the file mspdb50.dll from the MASM32 package into the folder of the file WindowsStub.obj and again issued the following command on the command prompt:
link WindowsStub.obj
The following error massage appeared however:
LINK : fatal error LNK1104: cannot open file "crt.lib"
So I found the file crt.lib in the PellesC/Lib folder and copied that file also into the folder of the object file WindowsStub.obj. Again issuing the command
link WindowsStub.obj
now yielded the following error message:
LINK : fatal error LNK1104: cannot open file "kernel32.lib"
copying the file kernel32.lib from the PellesC package into my folder and issuing the command
link WindowsStub.obj
now resulted in:
WindowsStub.obj : error LNK2001: unresolved external symbol __imp__MessageBoxA@16
WindowsStub.exe : fatal error LNK1120: 1 unresolved externals
At this point I decided to give up because the above approach does not seem to work! Actually, the use of PellesC in the second attempt below sheds some light on the correct use of flags and options with link.exe.
SECOND ATTEMPT TO REACH THE GENERAL OBJECTIVE:(=To let PellesC do all the dirty work!)
I temporarily deleted the file polink.exe from the folder PellesC/bin
I put the file link.exe in this folder and renamed it into polink.exe.
In PellesC I changed the LINKFLAGS (accessed via Project->Project Options->MACROS) into:
-subsystem:windows -machine:x86 -stub:"C:\Documents and Settings\Bastiaan\My Documents\Pelles C Projects\WindowsStubMyPr\HELLO.exe" kernel32.lib user32.lib gdi32.lib comctl32.lib comdlg32.lib advapi32.lib delayimp.lib
Now I tried to build WindowsStub.exe using PellesC.
The following error message appeared:
polink.exe - Unable To Locate Component
This application has failed to start because mspdb50.dll was not found.
Re-installing this application may fix this problem.
(almost literally the same as one of the previous error messages)
So I next put the file mspdb50.dll from the MASM32 package) into PellesC/bin. Trying to build WindowsStub.exe using PellesC resulted in the following messages from PellesC:
Building WindowsStubMyPr.exe.
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
C:\Documents and Settings\Bastiaan\My Documents\Pelles C Projects\WindowsStubMyPr\HELLO.exe : warning LNK4060: stub file missing full MS-DOS header; rebuild stub with /KNOWEAS 16-bit LINK option
Done.
This was good to see as it reproduces what Pelle already observed!
Next, I tried to use the /KNOWEAS option, but it was not recognized by link.exe. Then, I noticed that the linker version is 5.12.8078 so not 5.5x as Pelle suggested. So that's probably why the /KNOWEAS option was not recognized...
So here I decided to give up for the moment and post the above experiences to the forum in the hope someone might come up with an easy solution. Perhaps I could have done more by trying to get the 16-bit LINK version 5.5x or higher, but I have the following doubts about it:
- the error message by link.exe says that the stub needs to be rebuilt. But what if that is not possible or very difficult? (For example when there is only a old style dos executable and no source code or .obj file are available. Is it then not difficult to rebuild the executable so it will have a 40 bit header? Pelle already said that "rebuilding the DOS exe into a NE exe is not really an option") .
- Possibly it is hard to get link.exe version 5.5x or higher or maybe it goes with Windows Platform SDK and the .NET Framework SDK (as mentioned by Stefan Pendl) which are both very large packages, VERY large given the fact that I am only interested in the small file link.exe ... .
- I like to use POLINK with PellesC because POLINK is the right linker specially made for PellesC. Using link.exe in PellesC does not "feel" right. (this is of course a very subjective argument)
FINAL REMARKS:In my previous posting on this topic (
http://forum.pellesc.de/index.php?topic=2423.0), I proposed a way of using ONLY PellesC to achieve the desired result (to use a different DOS-EXE as a stub in an executable generated from a PellesC project).
Given the difficulties in trying to achieve this result in another way with the aid of link.exe (which could possibly be used to convert the dos-exe into a dos-exe with 40 bit header) and given the difficulties in obtaining a dos c compiler that can generate dos-exe files with 40 bit header, it seems not unreasonable to say that my proposed approach deserves some more attention (and verification) because this could be worthwhile.