How to set my custom entry point?

I think I have found the solution. Here is how:

  1. The main point is that you should not let cargo create a binary project, instead you must create a library crate. And the entry function is in that library crate. Let the name of that crate be "start".

cargo new start

  1. Now the project has been created. The lib.rs file is supposed to contain the start function, which in turn calls Win32 functions. Today I have not yet begun to write such calls, so I have left the body of start function empty. The content of lib.rs is as follows:

#![no_std]
#[no_mangle]
pub extern "C" fn start() {
}

  1. Now let cargo buid the target:

cargo build --release

  1. Now in the target\release directory, you should find the "libstart.rlib" file. This time we will let Microsoft linker to build the exe. Before that, make sure that the path of link.exe is included in the PATH environment string. In the target\release directory, type the following command:

link /NOLOGO /NXCOMPAT /LARGEADDRESSAWARE /SAFESEH /RELEASE /ENTRY:start /SUBSYSTEM:WINDOWS libstart.rlib /OPT:REF,ICF /LIBPATH:.\deps /OUT:start.exe

Some parameters in the above command line are still a mystery to me, as I just copied them from the cargo generated command line. To see how I obtained that command line, see my post Some findings of the rust compilation process - #3 by Michael-F-Bryan

And now the start.exe should have just been generated, except it does nothing at the moment.