Posts

Showing posts with the label windows

smallest EXEcutable

This is an interesting page discussing techniques to achieve the smallest EXE possible. http://www.phreedom.org/solar/code/tinype/ More, it says that if you add an UNC path as a name of an imported DLL in an executable, Windows will download and execute that file ! the server needs to be a WebDAV server.

Opening CHM Help files from Network or Internet

Due to a security patch Windows has restricted access to a CHM. More info here: http://support.microsoft.com/kb/896358. The attached reg script fixes one of the 4 problems described in the KB. It works for most of the CHM files. Here is the file. Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\HTMLHelp\1.x\ItssRestrictions] "MaxAllowedZone"=dword:00000004

registry tweaks

every now and then I need some Windows tweaks. i''ll put here all the things i need. here's the first ones: make OutlookExpress independent from Messenger (restart: no) Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Outlook Express] "Hide Messenger"=dword:00000002 Add 'Explore from here' to Windows folders(restart: no) Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\Directory\shell\Command] @="CommandPrompt" [HKEY_CLASSES_ROOT\Directory\shell\Command\command] @="cmd.exe /k cd \"%1\"" matching file names each time you press TAB in cmd. works in XP but doesnt by default on Win2000 Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\Microsoft\Command processor] "CompletionChar"=dword:00000009

windows install date

useful when u need something unique from the PC and easy to get HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion installdate value InstallDate REG_DWORD Time (in seconds) since 12:00 A.M, January 1, 1970 here's a VBS script which displays the info: Dim WshShell, TimeStampSet WshShell = WScript.CreateObject("WScript.Shell")TimeStamp = WshShell.RegRead(_"HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\installdate")WScript.Echo "Install date :" & _DateAdd("s", TimeStamp, DateSerial(1970, 1, 1))

process termination

Ive just looked to an interesting blog article talking about when a process terminates. http://blog.kalmbachnet.de/?postid=65 It seem that there is a subtle difference between how a console application (the main() CRT function) and a Win32 application (WinMain) is handling the process termination. if you have this: DWORD WINAPI MyThread2(LPVOID) { while(true) { } return 0; } #pragma comment(linker, "/entry:myMain") int WINAPI myMain() { DWORD dwThreadId; CloseHandle(CreateThread(NULL, 0, MyThread2, NULL, 0, &dwThreadId)); return 0; } the application is a windows application (using myMain entrypoint) and it run infinitely. but a similar console application: int t_main() { DWORD dwThreadId; CloseHandle(CreateThread(NULL, 0, MyThread2, NULL, 0, &dwThreadId)); return 0; } will return immediately after the 'return 0;' the difference is this one: the console application uses CRT which, after the user code return from main, it calls ExitProcess which terminates the a...

SuspendThread

as the msdn says SuspendThread is for debugging purposes and should not be used. it may be tempting to use it to pause a worker thread for example but it might not be ok. the worker thread can be in the middle of executing a CRT function which is thread safe, using sychronization. if the worker thread is paused after the lock is done, trying to execute from another thread a CRT function, which uses the same syncronization access, might get to a deadlock.

stuff to do on DLL_PROCESS_ATTACH

it is guaranteed you can call any Kernel32.dll function on the DLL_PROCESS_ATTACH. Calling any other function from other library is not ok, as the DLLs may not be loaded at that time (although your code links with those libs). more info can be found in the J. Richter book. and J.Robbins say some problem he had in the past with some thread work in DLL_PROCESS_ATTACH.

oversee CloseHandle

there are many WinAPI functions which create and return a HANDLE object, like CreateThread, CreateFile. in windows header file, a HANDLE is defined like this typedef void* HANDLE doing a 'CloseHandle' more than it is needed on the same HANDLE value is as bad as doing 'delete' on the same pointer. the docs say: "CloseHandle invalidates the specified object handle, decrements the object's handle count, and performs object retention checks. After the last handle to an object is closed, the object is removed from the system." so as long as the handle count is not zero, its logic of course to call CloseHandle. there are few considerations with the HANDLE objects: - some functions are not requiring to do CloseHandle on the their returned HANDLE object; so always, always read the docs; dont rely on the fact you are an experienced WinAPI programmer; the behaviour might be (it is !) different between functions (in fact you can find an example in the John Robbins bo...

multithreading issue

ok, here is my task: i have a dialog (main thread) and i have a worker thread running which updates a progressbar on the GUI. when i press the close button i want the main thread and the worker thread to end cleanly (i want tthe threads to be closed nicely, without any TerminateThread or anything) now, the problem stay in the fact that when i signal (using an event or something) the worker thread to end and then wait for it to end (using WaitForSingleObject for example) it is possible that in this time the worker thread to send a message to the GUI to update the progressbar(using SendMessage). Now, some may say why that SendMessage is a mistake but maybe not. I want to be sure that the GUI and worker are synchronized perfectly (i dont want to use PostMessage; in some situations, for example when a buffer is needed to be sent, PostMessage only will not work (the buffer needs to be available when the message arrive to the receiver queue), hence, for PostMessage, some queue mechanism migh...

shell api power

i've discovered some months ago that the shell libary shlwapi.dll has, beside some well known functions like SHBrowseForFolder also some tiny functions but very useful. instead of writing your own functions why dont use those which already exist, especially if come from OS DLL's ? u are sure they are working OK and also it may be faster then yours (applicatinos like Windows Explorer use the DLL already, hence the functions might already be loaded in the memory pages) those functions stay mostly in so called "Shell Lightweight Utility Functions", and they are grouped in String Functions, Path Functions Registry Functions Color Palette Functions, Miscellaneous For example, i needed a function which gives a text formatted to display the size of a file like this: 100 MB 123 KB ... this function already exists in shell lib, StrFormatByteSizeW Function or StrFormatByteSizeA Function so I will always check out the shell functions whenever i have this kind of small tasks to d...