how to define a custom entry point

This is a discussion on how to define a custom entry point within the Windows Programming forums, part of the Platform Specific Boards category; hello all, I am just wondering if anyone could please tell me how/where I can define a custom entry point ...

  1. #1
    Madly in anger with you
    Join Date
    Nov 2005
    Posts
    211

    how to define a custom entry point

    hello all,
    I am just wondering if anyone could please tell me how/where I can define a custom entry point in Visual C++ 6.0?

    I created my project/workspace as "A Win32 Application" with an empty workspace. but I will not be using the traditional Windows application entry point:

    Code:
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    I will be using:

    Code:
    int Entry(void)
    I don't need all the parameters/local variables that WinMain supplies.

    can anyone tell me how to do this? I think its possible in Project -> Settings but can't find where, and I also think its possible by a #pragma comment.


    thanks!

    Intel Core 2 Quad Q6600 @ 2.40 GHz
    3072 MB PC2-5300 DDR2
    2 x 320 GB SATA (640 GB)
    NVIDIA GeForce 8400GS 256 MB PCI-E

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    You could always do something like this (leaving out the parameter names if you're using C++ to avoid warnings):
    Code:
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
        Entry();
        return 0;
    }
    But I'm sure you've thought of that.

    Why do you want to change the entry point? If you simply don't need the parameters and are using C++, try this:
    Code:
    int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
        // code
    }
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    It's easy in assembly, but I'm afraid it's not possible in C++...

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Sure it is. It's just pretty silly.
    Code:
    $ cat entrypoint.c
    #include <windows.h>
    
    #ifndef ENTRYPOINT
        #error You must define ENTRYPOINT
    #endif
    
    void ENTRYPOINT(void);
    
    int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
        ENTRYPOINT();
        return 0;
    }
    $ cat customentry.c
    #include <iostream>
    
    void ENTRYPOINT(void) {
        std::cout << "Hello, World!\n";
    }
    $ gcc entrypoint.c customentry.c -o customentry -DENTRYPOINT=Entry
    $ ./customentry
    Hello, World!
    $
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    The entry point is still WinMain...

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Yes but you can pretend it's ENTRYPOINT because as far as customentry.c is concerned it is.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  7. #7
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    LOL that is stupid...

  8. #8
    Madly in anger with you
    Join Date
    Nov 2005
    Posts
    211
    found out how from some open source yesterday:

    Code:
    #pragma comment(linker, "/ENTRY:Entry")

    Intel Core 2 Quad Q6600 @ 2.40 GHz
    3072 MB PC2-5300 DDR2
    2 x 320 GB SATA (640 GB)
    NVIDIA GeForce 8400GS 256 MB PCI-E

  9. #9
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Now that's the real deal

  10. #10
    Disrupting the universe Mad_guy's Avatar
    Join Date
    Jun 2005
    Posts
    258
    Quote Originally Posted by maxorator
    It's easy in assembly, but I'm afraid it's not possible in C++...
    It's not language specific. Defining custom entry points is a feature of your linker. Hence, your ability to do this depends on your linker in question. The previous code will work in Microsoft compilers. GCC & Co. is a different story.
    operating systems: mac os 10.6, debian 5.0, windows 7
    editor: back to emacs because it's more awesomer!!
    version control: git

    website: http://0xff.ath.cx/~as/

  11. #11
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    It should be noted that the actual default entry function for MSVC is not WinMain but WinMainCRTStartup (or similar variant). This function initialises the C run-time, calls C++ constructors for global variables and then calls WinMain. Once WinMain returns, it does run-time cleanup, calls global destructors, and finally calls ExitProcess. Therefore, if you define your own entry function, you can not use the C or C++ run-time libraries or C++ global variables. You must also call ExitProcess at the end of your entry function as there is nothing to return to. There is some more information on this topic in the LIBCTINY article.
    Last edited by anonytmouse; 09-18-2006 at 04:45 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. For the numerical recipes in C types!
    By Smattacus in forum C Programming
    Replies: 5
    Last Post: 10-28-2008, 07:57 PM
  2. Bor to DevC++ prog convert prob
    By kryptkat in forum Windows Programming
    Replies: 16
    Last Post: 09-18-2007, 05:11 AM
  3. Help getting multiple keypresses in a DOS compiler
    By Nongan in forum Game Programming
    Replies: 2
    Last Post: 04-01-2005, 09:07 PM
  4. LISP (DrScheme) any one?
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 03-31-2004, 11:52 AM
  5. FAQ: Directional Keys - Useing in Console
    By RoD in forum FAQ Board
    Replies: 38
    Last Post: 10-06-2002, 04:42 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21