Category Archives: Windows programming tips

A custom EVENT object for lighting fast thread synchronization

Several weeks ago, while I was working on the next version of Horodruin, I was optimizing the multithreaded file copy engine. This optimization phase pops up an unexpected event on the standard event object processing.  It seems that frequent uses of SetEvent() API are not exactly processing-resources free. This is probably caused by some code overhead needed for a system object… During these evaluations, I … Continue reading A custom EVENT object for lighting fast thread synchronization »

HOWTO easily use NASM into windows C/C++ applications

After installed NASM and configured our VisualStudio to use it, we are now able to use it in our C/C++ projects. Assembler usually has a huge advantage in terms of performance at the cost of rigid code usage. You cannot use it in both 32-bits and 64-bits versions of the same C/C++ code.  Each version shall fulfill several different ‘environmental’ requirements that cannot be ignored … Continue reading HOWTO easily use NASM into windows C/C++ applications »

Few Considerations About Functions Returning an Object

I am rewriting a VCL program using MFC, and I have converted many functions of this kind: CString MyFunction () { return L”Sample test”; } This kind of function declaration is comfortable, but the question is: is it also convenient?   The answer I found is that it might not be so convenient, especially if used inside a loop. When we call this function, we … Continue reading Few Considerations About Functions Returning an Object »

HOWTO Make Windows SlimRW Lock More Confortable

Recently I tripped into SlimRW Lock API. It’s a Windows synchronization object very similar to the critical section, with the support of two different types of lock: shared and exclusive. Essentially you should get the shared lock for all read-only activities, while the exclusive lock shall be used for all the other cases. The Basic Implementation I wrote this simple class to include them in … Continue reading HOWTO Make Windows SlimRW Lock More Confortable »

HOWTO Automatically Catch Problems While Debugging

Suppose to have the ability to add dozens of breakpoints into your program main error detection points, whenever you start a debugging session. This should allow you to easily track down some hidden/unnoticed problems. For example, suppose to have a C function like the below one: __MYOBJECTDATA * WINAPI MYOBJGetPtr (HANDLE hMyObject) { __MYOBJECTDATA *pObj; pObj = (__MYOBJECTDATA *) hMyObject; __try { if ((pObj != … Continue reading HOWTO Automatically Catch Problems While Debugging »

Visual Studio 2017 remote debugger

Suppose to have a problem in your program occurring only a specific PC. You can study it by: installing a copy of your VS2017 on that PC. copy VS2017 Remote Debugger console Naturally the second way is simpler and more efficient, since you have to copy a folder. You can find it, in the following path: C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\Remote Debugger or (into 32 … Continue reading Visual Studio 2017 remote debugger »

About Letting Your Program Die in Peace

requirement: medium knowledge of C/C++ or similar languages under MS Windows. One of the problems of writing a problem are the coding errors. There are many types of errors but the worst ones are those that trigger a Chernobyl reactor like effect. Something wrong occurs during the program execution, and instead of dying peacefully, it loses any control multiplying the magnitude of the event. Although … Continue reading About Letting Your Program Die in Peace »

About Using & Designing DLLs

requirement: medium knowledge of C/C++ or similar languages under MS Windows. Introduction Some days ago, I was explaining how a .DLL works, and how to use them in programs written into C or C++. Supposing to have MYAPP.EXE and MYLIB.DLL, we will face the following main scenarios: scenario MYAPP.EXE MYLIB.DLL 1 The program uses MYLIB.DLL. The used functions are all exported. 2 The program uses … Continue reading About Using & Designing DLLs »