New Book Published

I have recently published another book with Packt Publishing, entitled “Hands-On GUI Programming with C++ and Qt5“. This is the 3rd book I’ve written so far, and hopefully the content quality is improving more this time.

If you’re using Kindle for reading ebooks, you can get this book from Amazon. Otherwise, you can get the ebook and printed copy at Packtpub. You can also get all the source files used in this book at the Github page.

Killing MySQL Processes

Once in a while you might face problems related to MySQL being not responding. Most of the time it’s due to large database size or you’re running a select query on an un-indexed table. Instead of waiting for the process to complete (which may take hours), you can cancel the stalling processes using the following method.

First, open up another MySQL session and call the following query:

SHOW PROCESSLIST;

Next, you will see results like this:

+—-+—————–+———–+——+———+——+————————+——————+———-+
| Id | User | Host | db | Command | Time | State | Info | Progress |
+—-+—————–+———–+——+———+——+————————+——————+———-+
| 254772 | event_scheduler | localhost | NULL | Daemon | 2693 | Waiting on empty queue | NULL | 0.000 |
| 435342 | root | localhost | NULL | Query | 0 | Table lock | SHOW PROCESSLIST | 0.000 |
+—-+—————–+———–+——+———+——+————————+——————+———-+

Look for the ID of the query which you wish to terminate and use it in the following query, for example:

KILL 435342;

That’s it, the process will then be terminated by MySQL. Hope it helps.

Prevent Direct Execution of EXE

Back in early 2000s was the time when MMOs were very very very poppular in Asian countries. That was also the time when I was crazy about Ragnarok Online, one of the most famous korean MMORPGs of all time. Besides playing the game (which cost around US$10 per month, a large sum for a middle school student like me), I also went into modding the game and ran it on an emulator (private server running locally).

One thing that I noticed was the existence of a mysterious EXE file in its installation directory called “Ragexe.exe” which can never be executed; it will show you an error message whenever you double click on it.

Years later when I started to learn C/C++ programming I finally understood what the hell was that EXE file for; in-fact, it’s the actual game executable and not the other EXE that has the game icon on it, the other EXE is actually the updater client, nothing else.

So finally, the mystery has been solved. However, the question is: How can we re-create this for our own programs/games? What if we also want our users to run the updater first and not directly execute the main program? It turns out, it’s pretty easy to achieve. In the following example I will be using C/C++ and Qt but it should be pretty similar in other programming languages and platforms as well.

The sample code here is pretty simple:

#include "mainwindow.h"
#include <QApplication>

int main(int argc, char *argv[])
{
	QApplication a(argc, argv);

	if (argc <= 1)
	{
		QMessageBox::critical(0, "Application Error", "Please run MyGame.exe instead.");
		return 0;
	}
	else
	{
		if (argv[1] != "yourpassword")
		{
			QMessageBox::critical(0, "Application Error", "Please run MyGame.exe instead.");
			return 0;
		}
	}

	MainWindow w;
	w.show();

	return a.exec();
}

In the example above, your EXE will simply pop out an error message that says “Please run MyGame.exe instead.” if you double click on it directly. This is because the argc variable is either 0 or 1 (depending on platform, which means no additional input argument during launch) if you run it directly.

However, if there is one or more arguments being dumped to the program during launch, check (within the argv array) whether the second argument (the first argument is usually the program’s name) matches your secret phrase or password before allowing the program to launch. Usually there will be input arguments if the user drag one or more files to the EXE to make it launch, as this is very useful for programs like text editors or image editors. That’s why we must check if the argument matches your password or not.

Now that your program can no longer be run directly, what about the updater? How to ask the updater to execute your main program with an input argument? It’s actually pretty easy as well. In the following example I will be using C/C++ and Qt, but it should be similar across different programming languages and platforms:

QProcess *process = new QProcess(this);
process->setNativeArguments("yourpassword");
process->startDetached("MyGame.exe");
delete process;

exit(EXIT_SUCCESS);

In the code above, I simply declared a QProcess object and set the native argument before starting the main program and close the updater client.

That’s all, it’s very simple to achieve. The tutorial above is by no mean professional: Technical names and phrases are not necessarily accurate, and the method used is not necessarily the standard way. I’m just trying to share what I know and what I did with my own projects. Peace.

Gigabyte BRIX (Intel NUC) GB-XM12-3227 Review

So… the other day I bought this Gigabyte BRIX barebone which is basically an Intel NUC system, but manufactured by Gigabyte. I’ve tried the vanilla Intel NUC systems before and it worked great, except the older generation which had over-heating issue but resolved after adding a thermal pad to it as well as a firmware upgrade, but overall still pretty okay I guess.

Now, back to Gigabyte BRIX, specifically the GB-XM12-3227 model. I can’t talk about the other models as I have never used it before, so let’s just stick to this one.

All-and-all, it worked fine at first. It booted up Windows 10 without any problem, HDMI connected to the monitor without any problem, great resolution, etc. UNTIL I tried to use the web browser. Even though the internet status is “connected”, I still couldn’t use the damn internet on my browser.

After hours and hours of research and trials, I realized that the issue is the firmware. Not only it’s old (from 2013), but it’s supposedly for Windows 8.1, and not Windows 10. Went to Gibabyte’s website to look for the latest drivers, and guess what, they only have firmware updates up to 2014, so still, no Windows 10 support.

Further more, I downloaded the latest BIOS and tried to flash it, only to realize the BIOS utility doesn’t support 64-bit Windows, because it is a god-damn Windows XP Service Pack 2 executable file!

Then, I went to Windows 10’s Device Manager and check out my wireless network adapter’s properties. This is when I realized the WiFi adapter only supports up to IEEE 802.11b/g and not the newer IEEE 802.11b/g/n, which unfortunately is what I set on my router. So then I moved over to my router’s admin page and changed the Transmission Mode to the appropriate setting.

I have no idea what’s causing this. Outdated BIOS? Outdated drivers? I have no idea.

However, despite able to connect to the internet now, the speed is still very limited. Often time it took roughly 20 seconds or more just to load a web page.

Then, I used a Chinese software called 360安全卫士 (translated as “360 Safety Guard”) and went to the “Optimization and Speed-up” page. That particular page contains an automated scan-and-fix feature which includes “network speed-up” option.

After running the optimization process, my wireless network is finally back to usable state! What sorcery is that?? (However, IEEE 802.11b/g/n is still not supported).

Overall, the Gigabyte BRIX works okay except the BIOS and drivers are really outdated and urgently need an update. That’s all for today, have a nice day folks.

OpenGL Side Project

It’s been a long while since my last update. I was extremely busy for the past few months and only by now I have a little bit of spare time so I decided to work on a little side project just for fun.

I always wanted to learn OpenGL since a teen and hoped that one day I could make my own game engine that runs OpenGL. Even though I created a half-baked game engine/level editor thingy back in 2010 but I was using Irrlicht rendering engine so that doesn’t really count.

After messing around a bit with Qt 5 and OpenGL coding, I’m finally getting a pretty awesome results!! :

At the moment my prototype does the following:

  • Running OpenGL 3.2 core profile and GLSL 150
  • Loads OBJ files and PNG/JPEG textures
  • Move, rotate, scale model
  • Camera navigation (move, rotate, look at) using keyboard input
  • Skybox

Like I said, nothing fancy yet but even this took me quite some time to get it working since I’m using Qt 5 with OpenGL. Most of the tutorials out there only teach OpenGL with SDL, GLFW, GLUT, etc. but not with Qt. The reason why I’m using Qt instead of SDL is mainly because I like the additional features in Qt such as networking, image loader, file loader, etc. which will save a ton of my time since I don’t have to reinvent the wheel, or worse, trying to integrate my project with random 3rd party libraries that may or may not compatible with each other. I had a pretty bad experience when working on my Irrlicht project back then so I’m trying to avoid that now. Also, I may want to use Qt 5 to create a level editor for this project (currently only working on the ‘core’ library) so it makes sense if I also use Qt for the core parts.

Since this is a spare time side project so I might not work on it on a regular basis and might not even finish it, who knows? That’s all for today, ciao.