- DLL containing main() - LNK 4086 error
- Posted by Aks on December 6th, 2003
Hi,
I have a DLL containing a function and I want that function to be called
"main()".
This DLL's source does not have a DllMain() defined anywhere.
Now, when I try to build this DLL with VC++, the linker throws LNK 4086
warning : entrypoint "_mainCRTStartup" is not__stdcall with 12 bytes of
arguments; image may not run
When I rename my function to main1(), this error doesn't come.
More strangely, when I write an EXE and perform a LoadLibrary for this DLL
(containing main()), the EXE runs main() and exits. I didn't even perform a
GetProcAddress and invoke the "main" function, it ran straight away on
LoadLibrary() !
Why is the linker automatically assuming that an executable with a function
called main should have a corresponding entry point (_mainCRTStartup) in the
PE file ? When I rename the function to main1 and export this, no such entry
point is created.
-Aks
--
War doesn't determine who's right. War determines who's left
- Posted by Tim Robinson on December 6th, 2003
Looks like the linker is (mistakenly) seeing the main function and setting
the DLL's entry point to mainCRTStartup, which calls main then ExitProcess.
Because the DLL's entry point, which should be DllMainCRTStartup, gets
called on process attach, this is causing your main -- and ExitProcess -- to
be called when the DLL is loaded.
You might have some luck by setting the entry point in the Linker Settings
dialog to DllMainCRTStartup manually.
--
Tim Robinson (MVP, Windows SDK)
http://www.themobius.co.uk/
"Aks" <akshat@cs.sunysb.edu> wrote in message
news:3fd156b7$1_4@marge.ic.sunysb.edu...
- error in the main module (Microsoft Windows) by Lightbeamz
- can not see main (Networking) by M.Horsfall
- AS5350: Main Memory Write Bus Error Interrupt (Routers) by óÌÁ×Á þÅÒÎÏ×
- main( in c++ (Programming) by Williamiller9004
- Help please, on replacing the main HD. (Computer Hardware) by Steve Lee

