I have recently started a tutorial to learn how to code GUI using Windows API and I have come upon an unexpected question which I think is kind of silly. I am using Code::Blocks with OpenWatcom compiler as default and I have created a simple GUI program compiling and linking well. The problem is when I try to launch the program, even from the release version something like the command line shows up behind the window of my program, like I tried to run it through the compile & run option of the Code::Blocks. Is there any way to remove the command line from showing up?
EDIT: It is not a problem with my main definition. This is my main definition: |
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
In Windows, the PE executable format has a flag that indicates whether the executable mode is "console mode" or "GUI mode". If "console mode", then the OS will attach a console window (opening a new one if necessary) whenever the program is run.
There will be a linker setting somewhere in your build environment that controls whether the EXE you generate is marked as console or GUI.
This is controlled by the /SUBSYSTEM linker option. It is currently set to CONSOLE and you need to change it to WINDOWS. The documentation mandates how the main needs to be changed:
Application does not require a console, probably because it creates
its own windows for interaction with the user. If WinMain or wWinMain
is defined for native code, or WinMain(HISTANCE *, HINSTANCE *, char
*, int) or wWinMain(HINSTANCE *, HINSTANCE *, wchar_t *, int) is defined for managed code, WINDOWS is the default.
Specifically for Code::Blocks, the linker option can be changed by this process:
In Code::Blocks simply open the Project->Properties dialog, switch to
the "Build Targets" tab and change the "Type" of the build targets you
want to modify to "GUI Application" or "Console Application". No need
to worry about the "main" function.
Instead of a main function, you need to use Win32's standard entry point WinMain:
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow);
See: http://sol.gfxile.net/wintut/ch2.html
Or, if you can't recompile, in Windows 7 you can just do:
START myProgram {enter}
See: http://support.microsoft.com/kb/126410
Related
On Mac OS X the debug outputs go to the system logger that can be read with the Console Application. But when you are developing outside of Xcode (using QtCreator or just the terminal for example), it's not very practical to check the system logs for debugging.
Is there any way to force MacOS to print the backtrace to the terminal (similar to Linux behavior) without any trick on the application side ??
I'm developing a new feature for Clang so it's a C++ program. And I'm using MacOS 10.13.3.
If you are using qt, then include QDebug and then use qDebug() as follows:
qDebug() << debug_qstring;
And if you are using XCode and ObjC, look for NSLog.
void NSLog(NSString *format, ...);
Also printf in case of C and std::out in case of cpp are always your friends!
I am trying to use Qt Creator 3.5.1 to debug a piece of software I wrote. I noticed that whilst debugging my program would just halt at random points and I mistook these issues for threading problems. However, eventually I found out that even when I ran the simplest of programs the debugger would keep running for all eternity without finishing.
I am running on a Mac (El Capitan), with Qt 5.5.1 and Xcode 7.3.
This is my very simple test program:
#include <iostream>
int main(int argc, char *argv[])
{
std::cout << "Howdy, this is a simple test program." << std::endl;
return 0;
}
When I run this in debugging mode in Qt Creator without setting any breakpoints it just never finishes:
Debugging starts
Howdy, this is a simple test program.
It is only when I press the stop button several times that the debugger comes back at me with Debugging has finished
When I look at the "Debugger log view" it shows me a Python exception of something crashing. I have no idea how to troubleshoot this though.
ERROR: Lldb stderr: Exception in thread Thread-1:
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 763, in run
self.__target(*self.__args, **self.__kwargs)
File "/Users/Stan/Qt5.5.1/Qt Creator.app/Contents/Resources/debugger/lldbbridge.py", line 765, in loop
self.handleEvent(event)
File "/Users/Stan/Qt5.5.1/Qt Creator.app/Contents/Resources/debugger/lldbbridge.py", line 1383, in handleEvent
% self.hexencode(msg))
File "/Users/Stan/Qt5.5.1/Qt Creator.app/Contents/Resources/debugger/dumper.py", line 478, in hex encode
return s.encode("hex") eAttributeError: 'NoneType' object has no attribute 'encode'
It might be nothing, but I have quite a challenge on my hands right now and I'd rather not work with a debugger I can't trust.
Thanks.
Apparently, you can fix the problem directly by applying this patch in your Qt Creator's sources: https://codereview.qt-project.org/#/c/154748/
It worked for me.
I run Ubuntu to dual boot with Windows 7, I used to work on a C++ project on Windows in VS2013, I imported it to code:: blocks (the original project is in my other partition with Windows on, and I assume I don't have root privileges on it, but I don't really know what I'm talking about). When I try to run my project (which runs fine on Windows) I get the following messages in the "Build log":
-------------- Run: Release Win32 in Huffman (compiler: GNU GCC Compiler)---------------
Checking for existence: /media/shoham/BC5461BE54617C50/Users/Administrator.Shoham-PC/workspace/Huffman/Huffman/Huffman
Executing: /media/shoham/BC5461BE54617C50/Users/Administrator.Shoham-PC/workspace/Huffman/Huffman/Huffman (in /media/shoham/BC5461BE54617C50/Users/Administrator.Shoham-PC/workspace/Huffman/Huffman/.)
Process terminated with status 255 (0 minute(s), 0 second(s))
Most people on the Internet say to install xterm or change the terminal in Settings->Environment..., but it doesn't work for me, even though I have xterm.
What's weird is that it works on a new project I create on my system to test this. By that I mean this:
int main()
{
return 0;
}
In a new project works.
Do I not have privilleges to my project on my other partition?
Do I have to make a new project copying the files? Or can I link them to be the same one?
What do I have to do to fix this?
I got a similar message too when I compile my C++ code in Code::Blocks IDE. To correct the problem, I changed the default console program to "konsole-e".
Settings->Environment-> Terminal to launch console programs: konsole -e
This error occurs as Code::Blocks is trying to start its default application to run console programs. And since this is an app you've not installed on your local machine it stops and outputs the error
Process terminated with status 255 (0 minute(s), 0 second(s)).
Installing xterm could solve this problem if this really is the default app Code::Block is searching for, but there is no need to do so. It is more helpful to look up the current settings and to pick an app that you've already installed.
Go to Settings > Environment and you'll find a dropdown saying Terminal to launch console programs. Here you can select a different default app to launch console programs in.
In Linux Mint this should be: gnome-terminal. In other Linux OS this can be a good choice: konsole-e. If none of them work just set up a very simple C++ program such as:
#include <iostream>
int main(){
std::cout << "Hello world! << std::endl;
return 0;
}
and try out different options Code::Blocks successfully opens up a Terminal and displays Hello world!.
I have an MSI install program for my application, that writes something to the path environment variable, but is is not "refreshed" in Windows until I reboot or manually go into environment variables and click ok.
My client has requested that we fix this.
The install program is limited but I have the option to run a batch file or VBScript after installation is finished.
Anybody know if there is a command or a function I can use?
If restart is not an option, you can try to kill every instance of explorer.exe, but i think this will also be not acceptable.
The correct way of doing it is sending a message to all top most windows to notificate of changes in the environment. But i don't know anything in the OS to do that. If you can include an exe and have access to a c compiler, this should do the trick
#include "windows.h"
void main(void) {
SendMessageTimeout(
HWND_BROADCAST,
WM_SETTINGCHANGE,
(WPARAM) NULL,
(LPARAM) "Environment",
SMTO_NORMAL,
1000,
NULL
);
}
I've tried compiling it with mingw/gcc in Windows 7 64 and seems to work without problems.
I was able to compile libdwarf and libelf sucessfully with some warnings. I also successfully compiled the simplereader demo application but, failed to process the elf file. It always fail at:
void* _elf_read(Elf *elf, void *buffer, size_t off, size_t len)
in input.c under the libelf library.
I am using the latest 2012 libdwarf source code and the libelf from http://directory.fsf.org/wiki/Libelf
Any advise how I can fix it? If any who have done this port and is willing to share his/her work, will be greatly appreciated.
Thank you.
I have solved the problem. The problem is not in with the Libelf but in the application simplereader. This application opens the file for read only whereas the libelf expects the file to be opened in binary. By adding "| _O_BINARY" everything goes well.