|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
wahorger
Joined: 13 Oct 2014 Posts: 1217 Location: Morrison, CO, USA
|
Posted: Mon Feb 12, 2018 11:39 pm Post subject: Compiled and linked as /WINDOWS? |
|
|
Is there a way to tell, at run-time, whether or not a program has been compiled and linked as WINAPP or /WINDOWS?
I have a module that will log events to a file and (optionally) create a window to display a warning/error. If I don't link with /WINDOWS, or include WINAPP for the main program, I get a program crash when the window is created.
Which makes sense!
But, is there a way to tell, at run-time, whether or not /WINDOWS was specified and take a different programmatic path to inform the user of an issue? |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7925 Location: Salford, UK
|
Posted: Tue Feb 13, 2018 10:13 am Post subject: |
|
|
I would not necessarily expect a crash since you can call MessageBox or winio@ from a console application.
I don't know of a Windows API function that provides this information. The simplest approach may be to somehow provide a flag in your code that matches your build setting.
It is not particularly difficult to write a function that tests for this. It would get the path of the current application (probably using GetModuleFileName), read in as much of the PE header as you need, and then access the WORD corresponding to the offset for OptionalHeader.Subsystem. This value is 2 for a Windows application otherwise it is 3. |
|
Back to top |
|
|
wahorger
Joined: 13 Oct 2014 Posts: 1217 Location: Morrison, CO, USA
|
Posted: Tue Feb 13, 2018 4:40 pm Post subject: |
|
|
Thanks, Paul, this will help. I'll investigate the PE header.
I was also surprised that there was a crash, but simply re-compiling the main with WINAPP and all was well. If I get some free time, I'll poke around to find the root cause. Unfortunately, the call-back trace ended before any of my code was referenced, so I'm mostly guessing the root cause.
Again, appreciate the hints! |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|