Getting screen resolution in C, w/o “windows.h”












-1














Just working on a small project using SDL2...



System info: Windows



App info: using C (pure C, no c++), mingw-x64 & SDL2.



Now;



Firstly, SDL.h requires the main function to be renamed as WinMain.



On the other hand, when getting the screen resolution, I tended to use the GetSystemMetrics function, which requires windows.h to be included in the pre-processor section and at this point, WinMain in my code conflicts with WinMain declared previously in winbase.h. When I'm using both (SDL.h and windows.h), compiler responds:




previous declaration of 'WinMain' was here: int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd);




That's because, WinMain is declared somewhere in the winbase.h, which is auto-included via windows.h.



Is there a way to get the screen resolution w/o using GetSystemMetrics / windows.h? Any other ideas?










share|improve this question


















  • 3




    stackoverflow.com/questions/25594714/…
    – DeiDei
    Nov 21 at 9:36






  • 3




    SDL.h requires the main function to be renamed as WinMain Thats not true. If you have main() or WinMain() as entry point of your program is determined by what windows subsystem you write code for (CONSOLE or WINDOWS (or others that are irrelevant here)). Also, simply renaming main() to WinMain() won't work as both take different parameters. The error message you got tells you that. What does your definition of WinMain() look like?
    – Swordfish
    Nov 21 at 9:44












  • There is just no requirement at all that #include windows.h also requires WinMain(). Using the winapi works just fine in a console app that starts from main() for example, including GetSystemMetrics(). Hard to guess how this train jumped off the rails. But you certainly need to delete your WinMain() function, SDL already takes care of that.
    – Hans Passant
    Nov 21 at 9:55












  • @Swordfish : When using main, compiler complains about WinMain not to be found. Can't remember the exact address, but somewhere on the web I came across a get around by replacing the main as WinMain. Gave it a try... and this solved my problem --though no sure about the internals. Anyway, SDL_GetDesktopDisplayMode seems to solve my issue. Thanks a lot!
    – ssd
    Nov 21 at 9:57








  • 3




    Internals: How SDL2 does its initialisation magic on Windows and how to get rid of that behaviour: stackoverflow.com/a/38803842/3975177
    – Swordfish
    Nov 21 at 10:02
















-1














Just working on a small project using SDL2...



System info: Windows



App info: using C (pure C, no c++), mingw-x64 & SDL2.



Now;



Firstly, SDL.h requires the main function to be renamed as WinMain.



On the other hand, when getting the screen resolution, I tended to use the GetSystemMetrics function, which requires windows.h to be included in the pre-processor section and at this point, WinMain in my code conflicts with WinMain declared previously in winbase.h. When I'm using both (SDL.h and windows.h), compiler responds:




previous declaration of 'WinMain' was here: int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd);




That's because, WinMain is declared somewhere in the winbase.h, which is auto-included via windows.h.



Is there a way to get the screen resolution w/o using GetSystemMetrics / windows.h? Any other ideas?










share|improve this question


















  • 3




    stackoverflow.com/questions/25594714/…
    – DeiDei
    Nov 21 at 9:36






  • 3




    SDL.h requires the main function to be renamed as WinMain Thats not true. If you have main() or WinMain() as entry point of your program is determined by what windows subsystem you write code for (CONSOLE or WINDOWS (or others that are irrelevant here)). Also, simply renaming main() to WinMain() won't work as both take different parameters. The error message you got tells you that. What does your definition of WinMain() look like?
    – Swordfish
    Nov 21 at 9:44












  • There is just no requirement at all that #include windows.h also requires WinMain(). Using the winapi works just fine in a console app that starts from main() for example, including GetSystemMetrics(). Hard to guess how this train jumped off the rails. But you certainly need to delete your WinMain() function, SDL already takes care of that.
    – Hans Passant
    Nov 21 at 9:55












  • @Swordfish : When using main, compiler complains about WinMain not to be found. Can't remember the exact address, but somewhere on the web I came across a get around by replacing the main as WinMain. Gave it a try... and this solved my problem --though no sure about the internals. Anyway, SDL_GetDesktopDisplayMode seems to solve my issue. Thanks a lot!
    – ssd
    Nov 21 at 9:57








  • 3




    Internals: How SDL2 does its initialisation magic on Windows and how to get rid of that behaviour: stackoverflow.com/a/38803842/3975177
    – Swordfish
    Nov 21 at 10:02














-1












-1








-1







Just working on a small project using SDL2...



System info: Windows



App info: using C (pure C, no c++), mingw-x64 & SDL2.



Now;



Firstly, SDL.h requires the main function to be renamed as WinMain.



On the other hand, when getting the screen resolution, I tended to use the GetSystemMetrics function, which requires windows.h to be included in the pre-processor section and at this point, WinMain in my code conflicts with WinMain declared previously in winbase.h. When I'm using both (SDL.h and windows.h), compiler responds:




previous declaration of 'WinMain' was here: int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd);




That's because, WinMain is declared somewhere in the winbase.h, which is auto-included via windows.h.



Is there a way to get the screen resolution w/o using GetSystemMetrics / windows.h? Any other ideas?










share|improve this question













Just working on a small project using SDL2...



System info: Windows



App info: using C (pure C, no c++), mingw-x64 & SDL2.



Now;



Firstly, SDL.h requires the main function to be renamed as WinMain.



On the other hand, when getting the screen resolution, I tended to use the GetSystemMetrics function, which requires windows.h to be included in the pre-processor section and at this point, WinMain in my code conflicts with WinMain declared previously in winbase.h. When I'm using both (SDL.h and windows.h), compiler responds:




previous declaration of 'WinMain' was here: int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd);




That's because, WinMain is declared somewhere in the winbase.h, which is auto-included via windows.h.



Is there a way to get the screen resolution w/o using GetSystemMetrics / windows.h? Any other ideas?







c sdl-2 mingw-w64






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 at 9:33









ssd

7083723




7083723








  • 3




    stackoverflow.com/questions/25594714/…
    – DeiDei
    Nov 21 at 9:36






  • 3




    SDL.h requires the main function to be renamed as WinMain Thats not true. If you have main() or WinMain() as entry point of your program is determined by what windows subsystem you write code for (CONSOLE or WINDOWS (or others that are irrelevant here)). Also, simply renaming main() to WinMain() won't work as both take different parameters. The error message you got tells you that. What does your definition of WinMain() look like?
    – Swordfish
    Nov 21 at 9:44












  • There is just no requirement at all that #include windows.h also requires WinMain(). Using the winapi works just fine in a console app that starts from main() for example, including GetSystemMetrics(). Hard to guess how this train jumped off the rails. But you certainly need to delete your WinMain() function, SDL already takes care of that.
    – Hans Passant
    Nov 21 at 9:55












  • @Swordfish : When using main, compiler complains about WinMain not to be found. Can't remember the exact address, but somewhere on the web I came across a get around by replacing the main as WinMain. Gave it a try... and this solved my problem --though no sure about the internals. Anyway, SDL_GetDesktopDisplayMode seems to solve my issue. Thanks a lot!
    – ssd
    Nov 21 at 9:57








  • 3




    Internals: How SDL2 does its initialisation magic on Windows and how to get rid of that behaviour: stackoverflow.com/a/38803842/3975177
    – Swordfish
    Nov 21 at 10:02














  • 3




    stackoverflow.com/questions/25594714/…
    – DeiDei
    Nov 21 at 9:36






  • 3




    SDL.h requires the main function to be renamed as WinMain Thats not true. If you have main() or WinMain() as entry point of your program is determined by what windows subsystem you write code for (CONSOLE or WINDOWS (or others that are irrelevant here)). Also, simply renaming main() to WinMain() won't work as both take different parameters. The error message you got tells you that. What does your definition of WinMain() look like?
    – Swordfish
    Nov 21 at 9:44












  • There is just no requirement at all that #include windows.h also requires WinMain(). Using the winapi works just fine in a console app that starts from main() for example, including GetSystemMetrics(). Hard to guess how this train jumped off the rails. But you certainly need to delete your WinMain() function, SDL already takes care of that.
    – Hans Passant
    Nov 21 at 9:55












  • @Swordfish : When using main, compiler complains about WinMain not to be found. Can't remember the exact address, but somewhere on the web I came across a get around by replacing the main as WinMain. Gave it a try... and this solved my problem --though no sure about the internals. Anyway, SDL_GetDesktopDisplayMode seems to solve my issue. Thanks a lot!
    – ssd
    Nov 21 at 9:57








  • 3




    Internals: How SDL2 does its initialisation magic on Windows and how to get rid of that behaviour: stackoverflow.com/a/38803842/3975177
    – Swordfish
    Nov 21 at 10:02








3




3




stackoverflow.com/questions/25594714/…
– DeiDei
Nov 21 at 9:36




stackoverflow.com/questions/25594714/…
– DeiDei
Nov 21 at 9:36




3




3




SDL.h requires the main function to be renamed as WinMain Thats not true. If you have main() or WinMain() as entry point of your program is determined by what windows subsystem you write code for (CONSOLE or WINDOWS (or others that are irrelevant here)). Also, simply renaming main() to WinMain() won't work as both take different parameters. The error message you got tells you that. What does your definition of WinMain() look like?
– Swordfish
Nov 21 at 9:44






SDL.h requires the main function to be renamed as WinMain Thats not true. If you have main() or WinMain() as entry point of your program is determined by what windows subsystem you write code for (CONSOLE or WINDOWS (or others that are irrelevant here)). Also, simply renaming main() to WinMain() won't work as both take different parameters. The error message you got tells you that. What does your definition of WinMain() look like?
– Swordfish
Nov 21 at 9:44














There is just no requirement at all that #include windows.h also requires WinMain(). Using the winapi works just fine in a console app that starts from main() for example, including GetSystemMetrics(). Hard to guess how this train jumped off the rails. But you certainly need to delete your WinMain() function, SDL already takes care of that.
– Hans Passant
Nov 21 at 9:55






There is just no requirement at all that #include windows.h also requires WinMain(). Using the winapi works just fine in a console app that starts from main() for example, including GetSystemMetrics(). Hard to guess how this train jumped off the rails. But you certainly need to delete your WinMain() function, SDL already takes care of that.
– Hans Passant
Nov 21 at 9:55














@Swordfish : When using main, compiler complains about WinMain not to be found. Can't remember the exact address, but somewhere on the web I came across a get around by replacing the main as WinMain. Gave it a try... and this solved my problem --though no sure about the internals. Anyway, SDL_GetDesktopDisplayMode seems to solve my issue. Thanks a lot!
– ssd
Nov 21 at 9:57






@Swordfish : When using main, compiler complains about WinMain not to be found. Can't remember the exact address, but somewhere on the web I came across a get around by replacing the main as WinMain. Gave it a try... and this solved my problem --though no sure about the internals. Anyway, SDL_GetDesktopDisplayMode seems to solve my issue. Thanks a lot!
– ssd
Nov 21 at 9:57






3




3




Internals: How SDL2 does its initialisation magic on Windows and how to get rid of that behaviour: stackoverflow.com/a/38803842/3975177
– Swordfish
Nov 21 at 10:02




Internals: How SDL2 does its initialisation magic on Windows and how to get rid of that behaviour: stackoverflow.com/a/38803842/3975177
– Swordfish
Nov 21 at 10:02












1 Answer
1






active

oldest

votes


















0














Ok! I've realized what I was doing wrong...



For the linking phase, I was using the following libraries and the linker was complaining about the WinMain function not to be found.



-lSDL2main
-lSDL2


Then I added the mingw32 library as shown below and the problem got solved (the order of the libraries does matter I think).



-lmingw32
-lSDL2main
-lSDL2





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53408985%2fgetting-screen-resolution-in-c-w-o-windows-h%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Ok! I've realized what I was doing wrong...



    For the linking phase, I was using the following libraries and the linker was complaining about the WinMain function not to be found.



    -lSDL2main
    -lSDL2


    Then I added the mingw32 library as shown below and the problem got solved (the order of the libraries does matter I think).



    -lmingw32
    -lSDL2main
    -lSDL2





    share|improve this answer


























      0














      Ok! I've realized what I was doing wrong...



      For the linking phase, I was using the following libraries and the linker was complaining about the WinMain function not to be found.



      -lSDL2main
      -lSDL2


      Then I added the mingw32 library as shown below and the problem got solved (the order of the libraries does matter I think).



      -lmingw32
      -lSDL2main
      -lSDL2





      share|improve this answer
























        0












        0








        0






        Ok! I've realized what I was doing wrong...



        For the linking phase, I was using the following libraries and the linker was complaining about the WinMain function not to be found.



        -lSDL2main
        -lSDL2


        Then I added the mingw32 library as shown below and the problem got solved (the order of the libraries does matter I think).



        -lmingw32
        -lSDL2main
        -lSDL2





        share|improve this answer












        Ok! I've realized what I was doing wrong...



        For the linking phase, I was using the following libraries and the linker was complaining about the WinMain function not to be found.



        -lSDL2main
        -lSDL2


        Then I added the mingw32 library as shown below and the problem got solved (the order of the libraries does matter I think).



        -lmingw32
        -lSDL2main
        -lSDL2






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 at 1:23









        ssd

        7083723




        7083723






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53408985%2fgetting-screen-resolution-in-c-w-o-windows-h%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            404 Error Contact Form 7 ajax form submitting

            How to know if a Active Directory user can login interactively

            TypeError: fit_transform() missing 1 required positional argument: 'X'