winapi

Implementation details of GDI clipping

Consider the following code snippet: HRGN clip = ::CreateRectRgn(50, 50, 100, 100); ::SelectClipRgn(context, clip); ::Rectangle(context, 0, 0, 50, 50); Is Microsoft's clipping implementation intelligent enough to return immediately from the call to Rectangle without attempting to draw anything? I suspect it probably is but have been u...

How can you allow a window in an MDI app to leave it's parent container w/Win32?

I have an MDI app. I would like to add an icon to the non client title bar of the child window that allows the window to float separately from the parent MDI container, allowing the user to take the child windows and arbitrarily place them around the desktop, outside of the MDI window. I have seen it done so I know it's possible, but I'...

Behavior of WaitForMultipleObjects when multiple handles signal at the same time.

Given: I fill up an array of handles with auto reset events and pass it off to WaitForMultipleObjects with bWaitAll = FALSE. From MSDN: “When bWaitAll is FALSE, this function checks the handles in the array in order starting with index 0, until one of the objects is signaled. If multiple objects become signaled, the function returns t...

How can I restart a Windows service application written in Delphi?

I have a Windows service written in Delphi. One of the third-party resources it uses occasionally gets corrupted, and the only way I've found to fix the situation is to exit and restart the program. I can detect when the resource is corrupted from within the program, and I can tell Windows to restart the service after it stops, but I c...

Cast to LPCWSTR???

I'm trying to create a (very) simple Win32 GUI program, but for some reason the compiler (I'm using VC++ 2008 Express) wants me to manually typecast every string or char* to LPCWSTR: I get this compiler error every time I do this, for example I get this error for the "Hello" and "Note": error C2664: 'MessageBoxW' : cannot convert param...

SwapBuffers crashing my program!

I have an OpenGL program that works on all of my computers but one. It's a desktop with Vista 64 and a Radeon HD4850. The problem seems to be in my call to SwapBuffers(hdc). It compiles fine and then gives me an exception: Unhandled exception at 0x00000000 in Program.exe: 0xC0000005: Acces violation. Using VC++ to break before the cal...

Calling CreateProcessAsUser from C#

I've been attempting to create a new process under the context of a specific user using the CreateProcessAsUser function of the Windows API, but seem to be running into a rather nasty security issue... Before I explain any further, here's the code I'm currently using to start the new process (a console process - PowerShell to be specifi...

How to reload a crashed process on Windows

How to reload a crashed process on Windows? Of course, I can run a custom monitoring Win service process. But, for example, Firefox: it doesn't seem to install such a thing, but still it can restart itself when it crashes. ...

What is the correct usage of GetLastError and FormatMessage in Delphi ?

Hi, I have a problem using a third-party component in Delphi 2006 (also Delphi 7), in which I get an "Unspecified Error" when executing a function call to that component. Do you have example code that utilises GetLastError and FormatMessage in Delphi, that would allow me to access more information about the error ? TIA :) ...

Encoding of string returned by GetUserName()

How do I get the encoding that is used for the string returned by GetUserName from the win32 API? I'm using pywin32 and it returns an 8-bit string. On my German XP, this string is obviously encoded using Latin-1, but this might not be the case for other Windows installations. I could use GetUserNameW, but I would have to wrap that mysel...

Throwing a Win32Exception

I've been writing a lot of code recently that involves interop with the Win32 API and have been starting to wonder what's the best way to deal with native (unmanaged) errors that are caused by calls to Windows API functions. Currently, the calls to native functions look something like this: // NativeFunction returns true when successfu...

Custom Painted Controls

We need to automate GUI testing of an application developed in Win32 API. Developer's have created this application by custom painted controls. They have controls which look like Grid, Buttons etc., but they are not basic Windows controls. What is custom painted controls? and how we can test these controls? ...

Navigate from a process to it's parent

Hello, I'm stuck with the process model of IE8, where a GetWindowThreadProcessId() for my MFC embedded window will give me a child IE PID, as the GetWindowThreadProcessId() for my container page will give me the root IE PID. Which is bad, as I want to filter my container out, while enumerating windows. So I'm looking for a way to get...

How do I get the results from an FTP command run through FtpCommand?

I've wrapped most of wininet with no problems, but now I'm stuck. I am trying to p/invoke FtpCommand from wininet.dll, but every command I run returns "500 syntax error". Even simple commands like dir, or ls. If I connect to the same server with ftp.exe the commands work fine and return expected results. Here's the method definition: [...

Win32 printing - cannot set landscape mode

I've got an old app that I need to get to print in landscape mode. The documentation I've found says to get a DEVMODE structure, change a couple of fields, and put it back in. What I've got is: HANDLE printer_handle; LPHANDLE printer_handle_pointer(&printer_handle); OpenPrinter(printer_name.get(), printer_handle_pointer, N...

Why can't Win32::TieRegistry list subkeys?

Using Cygwin Perl v5.8.8 and Win32::TieRegistry 0.26. We can get a tied hash object thing for HKEY_CURRENT_USER: $ perl -e ' my %RegHash; use Win32::TieRegistry( TiedHash => \%RegHash ); use Data::Dumper; my $Key = $RegHash{"HKEY_CURRENT_USER"}; print Dumper $Key;' $VAR1 = bless( {}, 'Win32::TieRegistry' ); And this works for sub key...

Why does a Rich Edit control ignore character formatting on trailing whitespace?

I have a Unicode rich edit control v4 (based on MSFTEDIT.DLL). I'm using WTL, which I don't believe is interfering. The test OS is Vista x64. The application is 32-bit Unicode. All text is added programatically, and the control is read only. The user gets to pick the fonts used for inserted text, and those fonts can vary across the text...

How to set up a Winsock UDP socket?

I want to create a Winsock UDP socket that only sends data to a client. I want the kernel to choose an available port for me. On the other hand, I want to indicate which local IP to use, since I'm running a few nics. I've tried combing through the maze of socket options, as well as binding with the port in the socket address set to 0 t...

How to guarantee a function will not be entered again if it does not return within a thread?

I don't want the function to be entered simultaneously by multiple threads, neither do I want it to be entered again when it has not returned yet. Is there any approach to achieve my goal? Thank you very much! ...

How can I determine which displays are attached to the same physical device using Direct3D9?

Using Direct3D9, I can count the available adapters using IDirect3D9::GetAdapterCount(). However, this returns the number of outputs, i.e. 2 for a single dual-head graphics card. Using Win32 API, I can enumerate the display devices and the monitors attached using the following snippet: DISPLAY_DEVICE displayDevice; ::ZeroMemory(&display...