WinMain entry point in .lib

This is a discussion on WinMain entry point in .lib within the Windows Programming forums, part of the Platform Specific Boards category; Hi all, In my visual studio solution i have 2 projects. One is a Win32 App and the other is ...

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    100

    WinMain entry point in .lib

    Hi all,

    In my visual studio solution i have 2 projects. One is a Win32 App and the other is a static lib. I want the static lib to have the winmain entry point in and not the win32 app. Everything builds fine and the win32 appp does successfully link with the library. However when i run the program the winmain entry point in the library never executes.

    What do I have to do to get this to work?

    Thanks

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    Does the non-lib source have its own entry point? If not, and it is not using the one from the library, the program should not even link.
    If it does, remove it.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User
    Join Date
    Oct 2004
    Posts
    100
    Hi thanks for the reply :-)

    The Win32 app doesnt have an entry point no. However I believe it should have an entry point, because before i linked it with the library the compiler was complaining that there was no entry point defined. But once I linked it with the library it compiled fine.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    No, that's the point: the entry point is in the library, so the source doesn't have its own.

    Hmm ... what happens if, after compiling, you simply use the "Step" debug command? Where does it start? Trace the CRT init function until the call to WinMain. Where do you get?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    I'm curious, why do you need such a thing the first place?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  6. #6
    Registered User
    Join Date
    Oct 2004
    Posts
    100
    Hi,

    when i step debug the program ends. It doesnt go anywhere.

    I want to do this because im trying to program a piece of software that im coding a program and it may need to run on linux inthe near future aswell as windows. So the idea is to write the application completely OS independtly and all OS calls like the entry point will be handled through the library. So when its time to switch OS, I need to change the library and not the application.

    I have a valid reason why im doing it, but it is difficult to explain why lol. It's basically so when it comes time to switch OS's i dont need to make changes to the main application because it is completely OS independenty and all of the OS dependency is done through the library which I can easily replace with the linux equivelent.

    So the WinMain entry point would be replaced with in main to run on linux

  7. #7
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    I have no problem with such trick.
    Created Win Application project
    Created Static lib project
    Moved WinMain from the first project to the second one
    compiled
    Run - I enter the WinMain in the library.

    Using MSVC 6.0

    check your WinMain declaration

    My looks like:
    Code:
    int APIENTRY WinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPSTR     lpCmdLine,
                         int       nCmdShow)
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  8. #8
    Registered User
    Join Date
    Oct 2004
    Posts
    100
    hi there :-)

    What was in your win application project?

    Thanks

  9. #9
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    The default hello world project created by VC. It's a good start. I only cut the WinMain

    and of course - I disabled the precompiled headers because I hate to mess with them
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 02-19-2009, 08:37 AM
  2. C# COM entry point
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 07-14-2007, 01:51 AM
  3. const Point& and const Point are same
    By noobcpp in forum C++ Programming
    Replies: 5
    Last Post: 06-30-2007, 01:39 AM
  4. more with my 1st structure program
    By sballew in forum C Programming
    Replies: 42
    Last Post: 10-22-2001, 08:03 PM

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