forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Compiled and linked as /WINDOWS?

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General
View previous topic :: View next topic  
Author Message
wahorger



Joined: 13 Oct 2014
Posts: 451
Location: Morrison, CO, USA

PostPosted: Mon Feb 12, 2018 11:39 pm    Post subject: Compiled and linked as /WINDOWS? Reply with quote

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
View user's profile Send private message Visit poster's website
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 5354
Location: Salford, UK

PostPosted: Tue Feb 13, 2018 10:13 am    Post subject: Reply with quote

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
View user's profile Send private message
wahorger



Joined: 13 Oct 2014
Posts: 451
Location: Morrison, CO, USA

PostPosted: Tue Feb 13, 2018 4:40 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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