DCSIMG
Internals - Pavel's Blog
Sign in | Join | Help

Pavel's Blog

Pavel is a software guy that is interested in almost everything
software related... way too much for too little time

Browse by Tags

Reminder: WPDUG September Meeting
04 September 11 01:05 AM | pavely | with no comments
This Wednesday (the 7th) will hold a Windows Platform Developer User Group meeting in Microsoft’s offices in Ra’anana (Israel). Our first session will be about adding realtime and deterministic capabilities to Windows and its impact on the system and the ways to program such a system (all based on addons by a company called TenAsys ). The second session will demonstrate useful (and undocumented) debugging tips and tricks in Visual Studio (primarily for native developers). Should be interesting for...
Windows Platform Developers User Group (Sep 2011) Meeting
11 August 11 10:37 AM | pavely | with no comments
After some time of inactivity, the WPDUG is back! Our next meeting will be held on September 7th, in Microsoft Offices in Ra’anana. The agenda and registration form is here . Please register so you’d have a parking space and enough food is presented… See you there!
GetShellWindow vs. GetDesktopWindow
18 June 11 09:06 PM | pavely | with no comments
In his post about running a process as a standard user from an elevated process, Aaron Margosis uses a technique that gets the access token of the shell process (typically explorer.exe) and uses that token to launch the new process ( Sasha Goldshtein also blogged about that). The first thing his code does is try to locate the shell process id. One way is to look for “explorer.exe” in the list of processes, but that’s a bit limiting, as there may be a different shell, or it may have been renamed for...
Dealing With Native DLLs in .NET “AnyCPU” Builds
13 February 11 09:27 PM | pavely | 2 comment(s)
A .NET application can be compiled using the “AnyCPU” configuration, meaning the application runs as 32 bit on a 32 bit OS, and 64 on a 64 bit OS. As long as the application is purely managed, everything should be just fine. However, if the application must use some native DLL through interop (e.g. P/Invoke), then “AnyCPU” may be an issue. A native DLL cannot be both 32 and 64 bit – it’s one or the other. The traditional solution to the problem is to switch the .NET build to a “Win32” or “x64” configuration...
The Case of the Unexplained Sharing Violation
24 November 10 04:19 PM | pavely | with no comments
(pardon to Mark Russinovich for the title “The case of…”). This seemingly innocent code caused a sharing violation error (32) after a few iterations:     for ( int i = 0; i < 10000; i ++) {       sprintf_s ( text , "Text from process %d\r\n" , GetCurrentProcessId ());         HANDLE hFile = CreateFile ( _T ( "c:\\temp\\test.txt" ), GENERIC_WRITE , 0 , 0, OPEN_ALWAYS , 0, 0);       if ...
תגים:, , ,
Windows Platform Developers User Group meeting
06 October 10 10:45 PM | pavely | 3 comment(s)
This evening was a WPDUG meeting on CLR hosting and CLR profiling. Thank you all for coming! It was a pleasure to see so many of you there. My session was on CLR hosting, using the new CLR 4 hosting API. This is done using native code (C++) that uses COM for communication between the CLR and the host, both ways. I showed how to enumerate the installed runtimes, how to load a specific CLR (a new feature of CLR 4 – the ability to host multiple CLRs in a single process), how to create an application...
How to Annoy Your Boss (or get yourself fired)
04 September 10 05:24 PM | pavely | 6 comment(s)
If you want to make your boss a bit crazy, here’s what you can do: First, get him away from his computer. You can explain you need to run some connectivity test or configure some important service for the sake of the project. Once he’s out of the way, you can proceed: 1. Install the Debugging Tools For Windows package (if you don’t have it already). You can get the latest version from the Windows SDK installation , but any previous version will do. We’ll need the Global Flags utility from that package...
Strange Bundle: WDK & Debugging Tools
03 March 10 02:20 PM | pavely | 3 comment(s)
Microsoft has released an update Windows Driver Kit (WDK) a few days ago, but with a new twist: The Debugging Tools for Windows are now bundled with the WDK and are no longer available as a free (and easy) download. The WDK is only available to MSDN subscribers and via the Microsoft Connect web site. This doesn’t make sense to me. Although WinDbg and friends are essential in the device driver world, they are just as important in the user mode world. I hope Microsoft reverts this decision and will...
Windows Platform Developers UG Session
24 February 10 10:00 AM | pavely | 1 comment(s)
Last night I delivered a session entitled “Writing Software Device Drivers on Windows” in the Windows Platform Developers user group . I gave a “crash course” of 1.5 hours on writing a driver that allows me to execute code within the kernel to do things that are not possible from user mode. Thank you all for coming and for the great feedback! I’ve attached the presentation and the demo code, including the driver code, the installer and the client application. Note that to compile successfully with...
Next Windows Platform Developers UG Meeting
04 February 10 10:03 AM | pavely | with no comments
The next meeting will be held on March 23rd, at Microsoft Offices. This is the planned agenda: 17:00-17:30 Gathering 17:30-17:40 – MVP Summit impressions 17:40-18:55 Title: Developing connectivity based products (Bluetooth, Wireless-LAN and GPS) in complex environment – Alon Haze Project management and Software development for Bluetooth, Wireless-LAN and GPS for the handsets market is challenging. The environment is built from demanding cellular customers with strict requirements for low cost, low...
Gotcha: CreateProcess causes Access Violation
17 January 10 11:39 AM | pavely | 4 comment(s)
The famous CreateProcess function may fail with an access violation. For example, this innocent looking code causes a crash: STARTUPINFO si = { sizeof ( si ) }; PROCESS_INFORMATION pi ;   CreateProcess (0, _T ( "notepad" ), 0, 0, FALSE ,     0, 0, 0, & si , & pi ); What’s wrong with this code? Apparently nothing. The key here is that CreateProcess is not actually a function at all, but a macro that’s expanded to CreateProcessA or CreateProcessW depending a compile...
תגים:, , ,
Local Kernel Debugging and LiveKd Update
27 October 09 10:13 AM | pavely | 7 comment(s)
Local kernel debugging is the ability to view kernel data structures in a live system (i.e. not connecting to a target system through a null cable modem or USB or other alternatives), and is supported since Windows XP. This is a great way to explore windows on its darker side (the kernel and related subsystems) with all its mysteries and secrets. With Windows XP, starting local kernel debugging is pretty easy. Just fire up WinDbg (or kd for that matter), select from the menu File->Kernel Debug...
Multiple Instance Windows Media Player
23 September 09 12:21 PM | pavely | 1 comment(s)
When Windows media player (WMP) is open, any attempt to open it again simply reactivates the existing WMP window. WMP is running as a single instance. It uses a relatively well known methods for this, creating a named mutex on startup and seeing if it already exists (by calling GetLastError and comparing with ERROR_ALREADY_EXISTS ). WMP uses a mutex called "Microsoft_WMP_70_CheckForOtherInstanceMutex" and this name seems to be consistent between WMP versions (at least starting from Windows...
A Thread’s Stack
16 September 09 01:24 PM | pavely | 16 comment(s)
When creating threads, we don’t usually think of its stack size. In the native world, the CreateThread function accepts a stack size (second argument) which we usually pass as 0. In the managed world, the Thread class exposes a pair of constructors expecting a stack size argument (which I was reminded by a comment). Why is this important? Creating threads has its costs. This is not only the added work the Windows scheduler must undertake or the data structures that must be allocated in the kernel...
Upcoming Courses and an Event
09 February 09 11:28 AM | pavely | with no comments
I’ll be teaching next week (starting from the 16th) a five day course (split) entitled “The C# 3.0 programming language” on .NET and C# fundamentals. On the 18th of this month, I’ll do an open house at Microsoft on C# 3.0 and LINQ (same thing I did a few months back at Air Force house, so if you were there, no need to come again – unless you really like the food). You can register here . On March 1st, I’ll be teaching my Windows Internals class (for developers) on the (obviously) internals of the...