Getting screen resolution in C, w/o “windows.h”
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
|
show 1 more comment
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
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 havemain()
orWinMain()
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 renamingmain()
toWinMain()
won't work as both take different parameters. The error message you got tells you that. What does your definition ofWinMain()
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 usingmain
, compiler complains aboutWinMain
not to be found. Can't remember the exact address, but somewhere on the web I came across a get around by replacing themain
asWinMain
. 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
|
show 1 more comment
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
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
c sdl-2 mingw-w64
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 havemain()
orWinMain()
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 renamingmain()
toWinMain()
won't work as both take different parameters. The error message you got tells you that. What does your definition ofWinMain()
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 usingmain
, compiler complains aboutWinMain
not to be found. Can't remember the exact address, but somewhere on the web I came across a get around by replacing themain
asWinMain
. 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
|
show 1 more comment
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 havemain()
orWinMain()
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 renamingmain()
toWinMain()
won't work as both take different parameters. The error message you got tells you that. What does your definition ofWinMain()
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 usingmain
, compiler complains aboutWinMain
not to be found. Can't remember the exact address, but somewhere on the web I came across a get around by replacing themain
asWinMain
. 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
|
show 1 more comment
1 Answer
1
active
oldest
votes
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
add a comment |
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
add a comment |
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
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
answered Nov 23 at 1:23
ssd
7083723
7083723
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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()
orWinMain()
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 renamingmain()
toWinMain()
won't work as both take different parameters. The error message you got tells you that. What does your definition ofWinMain()
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 aboutWinMain
not to be found. Can't remember the exact address, but somewhere on the web I came across a get around by replacing themain
asWinMain
. 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