Я тебя породил, я тебя и убью. Писать надо на своем языке, у англичан есть всякие stackoverflow
Wednesday, June 20, 2018
Инглиш маст дай
Я тебя породил, я тебя и убью. Писать надо на своем языке, у англичан есть всякие stackoverflow
Monday, August 29, 2016
Tuesday, March 22, 2016
Feedback on “Design of Everyday Things” by D.Norman
Some time ago we’ve discussed general GUI improvements which might greatly improve usability
in some lucky release. We’ve even investigated Adobe and other software,
for comparing reasons.
From
reading “Design of Everyday Things” I’ve learned that in development process,
and even in GUI improvement, we miss user feedback.
Example 1
A company was selling car of one model, while
having already developed second model. Car #1 has got recognition from
automobile community, got prizes on car show. But they didn’t get feedback from
customers. Car #2 has adopted some issues from car #1. Design #2 didn’t react
any negative feedback from car #1.
We
have the same, while developing release #4, we put release #3 GUI errors to backlog. We
even don’t have anything special for usability, and users don’t file DRs, since
usability issues are not errors. But some issues are very urgent, and easy to
fix. If we had official usability channel for handling GUI issues which
are easy to fix (alternative to DR bug tracking), we might better
keep/satisfy some customers.
I adore AE's work of features, predicting
future needs, so that we have good future. But when relating only on application engineers (not customer
feedback), all GUI related things will go to backlog, while 1/5 of GUI things
are urgent for customer and are very easy to fix.
ON_NOTIFY vs. OnNotify
It is not always easy to catch WM_NOTIFY send from control to its parent window.
In this case they want to notify parent CFileView from control CViewTree with WM_NOTIFY TVN_SELCHANGED message. And here message map just doesn't work:
They should do it in virtual OnNotify function, not using message map. If OnNotify doesn't met correct handler, message would go to parent CMainFrame, and there you can use message map.
In this case they want to notify parent CFileView from control CViewTree with WM_NOTIFY TVN_SELCHANGED message. And here message map just doesn't work:
ON_NOTIFY(TVN_SELCHANGED, 4, OnItemsSelChanged)
They should do it in virtual OnNotify function, not using message map. If OnNotify doesn't met correct handler, message would go to parent CMainFrame, and there you can use message map.
BOOL CFileView::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) { if (nmHdr->idFrom != 4) return CDockablePane::OnNotify(wParam, lParam, pResult); if (nmHdr->code == TVN_SELCHANGED) { OnItemsSelChanged((NMHDR*)lParam, pResult); return TRUE; } return FALSE; }
Thursday, November 12, 2015
Decryption of DLGINIT .rc file entry
Visual Studio saves ComboBox item list in DLGINIT entries of .rc files as ASCIIZ strings, in WORD format:
Using simple type conversion we can reveal, what do these strings contain.
IDD_DIALOG1 DLGINIT
BEGIN
IDC_STR1, 0x403, 16, 0
0x7241, 0x2063, 0x6c63, 0x636f, 0x776b, 0x7369, 0x0065,
IDC_STR2, 0x403, 18, 0
0x6c41, 0x6177, 0x7379, 0x6120, 0x2074, 0x6874, 0x2065, 0x6964, 0x0065,
0
END
Using simple type conversion we can reveal, what do these strings contain.
Thursday, September 17, 2015
Understanding Mutex entity
Studying example from MSDN article Using Mutex Objects some questions arise about mutex entity.
Here are experimentally proved suggestions:
Some create mutex via CreateMutex while having ERROR_ALREADY_EXISTS
Pic 1. Running 10 of these programs:
Example sources are here...
Here are experimentally proved suggestions:
- Mutexes are like files, open and create them with CreateMutex, close with CloseHandle (for files you use CreateFile, CloseHandle)
- Unnamed mutex is like critical section
- Mutexes are deleted after CloseHandle when no application currently have them opened
HANDLE hSome programs create h = 0x3c, some h = 0x44
main(){
h = CreateMutex("Global\\SuperMutex")
CreateThread(WriteToDatabase)
CloseHandle(h)
}
WriteToDatabase()
{
WaitForSingleObject(h)
ReleaseMutex(h)
}
Some create mutex via CreateMutex while having ERROR_ALREADY_EXISTS
Pic 1. Running 10 of these programs:
Example sources are here...
Monday, August 31, 2015
Test f() for multithreading
Here is a copy-paste template to test your code for multithreading. Let's say you want to test your function
int f() { ... }for multithreading. Use this code to test f() running from number of threads simultaneously:
struct TESTPARAM
{
int threadNo;
LONG* m_pnCount;
};
DWORD WINAPI _msgTestThread(void* pParam)
{
TESTPARAM* par = (TESTPARAM*)pParam;
char buf[1014];
int tmax = 1000;
int tstep = 100;
for (int t = 0; t<tmax; t+=tstep)
{
f();
Sleep(tstep);
}
InterlockedDecrement(par->m_pnCount);
delete par;
return 0;
};
int Start()
{
LONG nThreadCount = 0;
int THREAD_MAX = 10;
//msg::Message threads
for (int i = 0; i<THREAD_MAX; i++)
{
//new, otherwise TESTPARAM will not reach thread in _msgTestThread,
//and will be deleted on closing scope }
TESTPARAM * par = new TESTPARAM;
par->threadNo = i;
par->m_pnCount = &nThreadCount;
InterlockedIncrement(par->m_pnCount);
DWORD dwThreadID = 0;
CreateThread(0, 0, _msgTestThread, par, 0, &dwThreadID);
}
//Call window procedure until threads are finished
while (nThreadCount > 0)
{
MSG msg;
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
Sleep(10);
}
}
Thursday, October 23, 2014
Filtering log files on Windows 7
Note: this is just a reminder about Windows analogues of grep - find and findstr.
Being inspired by this article: http://habrahabr.ru/post/71568/
now leaving some how-to's when working with large log files, containing messages from many processes.
How to get all messages from a process with PID=8238
C:\logs> type file.log | find "8238"
2014-09-19 16:40:22 8238 [INFO] Closing Session
2014-09-20 16:40:22 8238 [INFO] Closing Session
2014-09-22 16:40:35 8238 [WARNING] Error: No IC output on selected net (i.e., no driver).Stopping.
2014-09-22 16:40:50 8238 [INFO] Close Session: Design file: demo2.p
2014-09-22 16:41:38 8238 [INFO] Close Session: Design file: demo2.p
2014-09-26 15:45:11 8238 [INFO] Close Session: Design file: demodiff.p
How to get messages from interval [2014-09-22, 2014-09-26]
C:\logs> type file.log | findstr /r /C:"2014-09-2[2-6]"
2014-09-22 16:40:22 [INFO] Closing Session:
2014-09-22 16:40:35 [WARNING] Error: No IC output on selected net (i.e., no driver).Stopping.
2014-09-22 16:40:50 [INFO] Close Session: Design file: demo2.p
2014-09-22 16:41:38 [INFO] Close Session: Design file: demo2.p
2014-09-26 15:45:11 [INFO] Close Session: Design file: demodiff.p
Note that /r stands for regular expressions. But regexps are limited in findstr, only [class] or [a-b] is allowed. See http://technet.microsoft.com/ru-ru/library/bb490907.aspx for reference.
Being inspired by this article: http://habrahabr.ru/post/71568/
now leaving some how-to's when working with large log files, containing messages from many processes.
How to get all messages from a process with PID=8238
C:\logs> type file.log | find "8238"
2014-09-19 16:40:22 8238 [INFO] Closing Session
2014-09-20 16:40:22 8238 [INFO] Closing Session
2014-09-22 16:40:35 8238 [WARNING] Error: No IC output on selected net (i.e., no driver).Stopping.
2014-09-22 16:40:50 8238 [INFO] Close Session: Design file: demo2.p
2014-09-22 16:41:38 8238 [INFO] Close Session: Design file: demo2.p
2014-09-26 15:45:11 8238 [INFO] Close Session: Design file: demodiff.p
How to get messages from interval [2014-09-22, 2014-09-26]
C:\logs> type file.log | findstr /r /C:"2014-09-2[2-6]"
2014-09-22 16:40:22 [INFO] Closing Session:
2014-09-22 16:40:35 [WARNING] Error: No IC output on selected net (i.e., no driver).Stopping.
2014-09-22 16:40:50 [INFO] Close Session: Design file: demo2.p
2014-09-22 16:41:38 [INFO] Close Session: Design file: demo2.p
2014-09-26 15:45:11 [INFO] Close Session: Design file: demodiff.p
Note that /r stands for regular expressions. But regexps are limited in findstr, only [class] or [a-b] is allowed. See http://technet.microsoft.com/ru-ru/library/bb490907.aspx for reference.
Thursday, October 2, 2014
Compiling .cpp files in FAR by pressing Enter
Sometimes we write small prototype console applications to test any functions or learn C++ features. It would be nice just to edit .cpp file and get .exe compiled at once, like Linux guys can do just by entering gcc command.
What you have to do - just to mimic
Start->All-Programs->Microsoft Visual Studio 2008->Visual Studio Tools->Visual Studio 2008 Command Prompt, which simply calls
What you have to do - just to mimic
Start->All-Programs->Microsoft Visual Studio 2008->Visual Studio Tools->Visual Studio 2008 Command Prompt, which simply calls
%comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat"" x86
Thursday, September 25, 2014
Odd HINSTANCE
Being called from DLL module, guess, which one would give you odd result?
HINSTANCE h1 = AfxGetInstanceHandle();
HINSTANCE h2 = GetModuleHandle(NULL);
HINSTANCE h3 = AfxGetApp()->m_hInstance;
HINSTANCE h4 = theApp.m_hInstance;
Wednesday, August 27, 2014
A hole in decorated C++ names
At the first glance Decorated C++ Names are ideal, they encode all possible C++ method names and allow links between .obj and .lib files. Read Format of a C++ Decorated Name.
But sometime these names can bring some mystics into your life. Today we spent plenty of time revealing a method of a one class doesn't work. It IS called, but you NEVER hit it. This became possible because there were TWO(!!) different classes of the same name.
Here is a prototype project reproducing such a case.
ClassB.obj:
But sometime these names can bring some mystics into your life. Today we spent plenty of time revealing a method of a one class doesn't work. It IS called, but you NEVER hit it. This became possible because there were TWO(!!) different classes of the same name.
Here is a prototype project reproducing such a case.
ClassA.h:
#include "Base.h"
class ClassA : public Base
class ClassA : public Base
{
public:
ClassA(void);
int f(void);
};
ClassB.h:
#include "Base.h"
class ClassA : public Base
class ClassA : public Base
{
public:
ClassA(int a);
int g(void);
};
The reason why compiler and linker produce no errors is because they have different Decorated C++ Names.
ClassA.obj:
?g@ClassA@@QAEHXZ
(public: int __thiscall ClassA::g(void))
??0ClassA@@QAE@H@Z (public: __thiscall ClassA::ClassA(int))
??1ClassA@@QAE@XZ (public:
__thiscall ClassA::~ClassA(void))
?f@ClassA@@QAEHXZ
(public: int __thiscall ClassA::f(void))
??0ClassA@@QAE@XZ (public: __thiscall ClassA::ClassA(void))
??1ClassA@@QAE@XZ (public:
__thiscall ClassA::~ClassA(void))
Decorated Name of destructors are the same, but linker was surprisingly silent.
(See Viewing Decorated Names for reference)
Monday, August 11, 2014
Fitting multilungual resources in Visual Studio C++ project in user-friendly manner
Going to I18n with our MFC Visual Studio C++ projects, we were considering several methods for organizing resources, (read here for details):
- Language-dependent binary
- One resource DLL for all languages
- One resource DLL per target language
I bet #2 is the best one, and here is how to organize .rc files and VS projects in the way good both: for machine and for humanity. Good for machine, because:
- DLLs would get compiled,
- Visual Studio resource editor would work with many-language resources the way it worked having only English ones, and
- there will be no TEXTINCLUDE section issue (read Cure for broken TEXTINCLUDE section of VC++ resource files )
- resources for all languages will be capable of manual editing with Visual Studio (thus you can keep resources synchronized among different languages),
- It would be possible to edit TEXTINCLUDE from VS GUI.
Plenty of time spent for investigation, reading docs, exploring existing projects and collegial disputes made it possible to get desired structure of VS C++ project and .rc files. This structure might be used as a template for other projects, and even might be an Ariadne's thread in localization labyrinth.
Thursday, June 5, 2014
Buffer overflow? No problem
I used to work with printf() function for decades. And I've proved that I'm experienced guy in it. It was harder for me to catch buffer overflow, than to find memory leaks.
The problem that data.descr COULD be > 256 bytes length...
std::string Format( Data & data )
{
std::string res;
char buf[256];
sprintf(buf, "[%s] %s", data.GetSeverity(), data.descr.c_str());
res = buf;
res.append("\n");
return res;
}
The problem that data.descr COULD be > 256 bytes length...
Thursday, May 29, 2014
Haunting memory leaks in Visual Studio with DEBUG_NEW
The simplest ever way to find where it leaks.
1. Insert well known piece of code in all .cpp files suspected for leakage:
1. Insert well known piece of code in all .cpp files suspected for leakage:
#ifdef _DEBUG2. Use CMemoryState to dump blocks allocated within suspected region:
#define new DEBUG_NEW
#endif
CMemoryState msOld;See further how #define DUMP_NEW can help you automate leak searching
msOld.Checkpoint();
CPerson* pper1 = new CPerson();
CPerson* pper2 = new CPerson();
msOld.DumpAllObjectsSince();
Friday, September 27, 2013
Embedding C++ code analysis into Visual Studio
Once needed to perform C++ code analysis in order to find multibyte-unfriendly code. Perl with regular expressions helped me a much. Then I've realized that asking everybody in my team to work from DOS console would be inconvenient, thus I've started thinking how to embed this stuff into my lovely IDE (*)
I even asked the community a question: How do I modify View.FindResults1 contents in Visual Studio?
and got am advice to my own version of the "Find Results" window by creating a Visual Studio extension myself. We can start by having a look at Extending Visual Studio > Tool Windows
Probably writing VisualStudio extensions is a deal of my future self-development. For now I've stopped on calling the script from Post-Build process:
"Output" window:
"Error List" window:
* - I bet Visual Studio is the best one IDE.
PS see: Formatting the Output of a Custom Build Step or Build Event
I even asked the community a question: How do I modify View.FindResults1 contents in Visual Studio?
and got am advice to my own version of the "Find Results" window by creating a Visual Studio extension myself. We can start by having a look at Extending Visual Studio > Tool Windows
Probably writing VisualStudio extensions is a deal of my future self-development. For now I've stopped on calling the script from Post-Build process:
perl $(SolutionDir)\Localization\test_resource_funs.pl $(InputDir)thus having its output in Compile Output window. No additional efforts are needed. I can even use "Errors List" to sort and observe all of script warnings.
"Output" window:
"Error List" window:
* - I bet Visual Studio is the best one IDE.
PS see: Formatting the Output of a Custom Build Step or Build Event
Wednesday, September 25, 2013
Line count with .bat
When it comes to routine, some can think of wasted hours, yearning, many cups of cofee trying to to fall asleep during your work. In that case it's better to think about robots. Let robots do their staff.
I have a perl script which has to be called 100 times for each of VS solution subdirectory. I don't want to write another Perl script to automate it, so let's use .BAT file:
I have a perl script which has to be called 100 times for each of VS solution subdirectory. I don't want to write another Perl script to automate it, so let's use .BAT file:
@echo offThanks to Brett Batie I've written Linux wc command analogue to count # of lines in the archived 100 .txt files:
if "%1" == "" GOTO HELP
for /D %%D in (%1*) do perl the_script.pl %%D > %%D.txt
goto END
:HELP
echo test_resource_funs_loop.bat - calls test_resource_funs.pl with each subdirectory
echo Usage example: test_resource_funs_loop.bat C:\Dev-9.1\hyp_src\
:END
@echo off
findstr /R /N "^" %1 |find /C ":"
Tuesday, September 17, 2013
Suggest using of Visual Assist X
I’d highly recommend using of the subject since it
significantly improves code traversing, understanding of code written by
others, code refactoring, etc.
Visual Assist is a Productivity and code refactoring plugin
an is much more effective than Visual Studio Intellisence. You can switch off
Intellisence and use Visual Assist X instead.
Sweets:
- Its “Go to definition” never fails and works even if you have compile errors;
- Find references finds much more precisely then
of Intellisence
For example, it can find all usages of CString::operator+() rather than searching for ‘+’ with “Find-In-Files”, which might be very useful;
- “Call tree” and “Caller tree” gives you opportunity to investigate without running the code. Sometimes you even don’t have idea how to run/debug this particular function.
- “Rename” and “Extract function” speeds up any rewriting.
- It highlights the same variables/words on a screen that cursor is currently staying on. Helps a lot finding all ‘i’-s in a function.
- It speeds up navigation among tons of sources an classes/function names. To look for a function named either “FillDirectory” or “DirectoryFill”, just type “Directory” and choose from the list.
Read more about Visual Assist Features,
try its 30-days trial, if interested
This is my proposal, it’s up to you whether to ask for
purchasing it. But it has good discount policy: 5
copies costs as 4 separate purchases.
PS Note that it is not a static analysis tool like Klockwork
or Coverity. Static analysis tools goal is to warn you about potential errors,
thus code is written not according to Code Complete
Thursday, September 12, 2013
Dual personality of while
At a first glance nothing special. Then you see dual personality
while(1)
{
ch = ::CharPrev(m_str1, ch);
TestString s(ch);
} while (ch!=m_str1);
Friday, September 6, 2013
Thursday, September 5, 2013
Why is UTF-8 treated as not multibyte?
It’s a long discussion and object of
terminology. Multibyte is a slippery term and is not the best one.
Visual Studio has 3 options for characters
sets:
a) No characters set, which means it works OK
with single byte characters sets (SBCS) like CP1251
(ru-RU) or CP1252
(en-US)
characters take 1 byte
characters take 1 byte
b) MBCS, which means it works OK with
multibyte Character sets like CP936,
characters take 1 or 2 bytes, GUI accepts such characters if appropriate locale is selected in Control Panel
characters take 1 or 2 bytes, GUI accepts such characters if appropriate locale is selected in Control Panel
c) Unicode, which means working with UTF-16BE,
characters take 2 bytes, selected locale doesn’t make any sense
characters take 2 bytes, selected locale doesn’t make any sense
Note that there is no option to work with
utf-8.
There are conversion functions utf8
<-> MBCS.
In Microsoft documentation term “multibyte”
is related to MBCS. It was hard for me to achieve, and I suppose there could be
misunderstanding among the team regarding this term.
Even having the same way of coding and
having floating amount of bytes, utf8 is a way of encoding Unicode characters,
it is not related to MBCS at all.
In order to have
our virare and maina (it.) we’ve agreed to call MBCS multibyte
Subscribe to:
Posts (Atom)




