winapi

Writing files to USB stick causes file corruption/lockup on surprise removal

I'm writing a background application to copy files in a loop to a USB stick with the "Optimize for quick removal" policy set. However, if the stick is removed part way through this process (specifically in the WriteFile() call below, which returns ERROR FILE NOT FOUND) the application hangs, the drive is then permanently inaccessible fro...

Why does CreateDIBSection() fail when the window is offscreen?

I'm building a Delphi component to embed an SDL rendering surface on a VCL form. It works just fine as long as the form is on-screen at the moment that the SDL surface is created. Otherwise, it's not able to create any rendering textures. I traced into the SDL code and ended up with the following function call, which fails (returns NUL...

How do you handle right click on a treeview in WTL/Win32 apps?

I have a basic app written with ATL, using the wizard with VS2008. I have a treeview in the left side of the app. I see how to (painfully) add tree items. Question is how do I show a menu when the mouse is right clicked? How do I trap any click events on each item that could be selected? ...

How to make a single line systabcontrol32 that scrolls but doesn't show a scrollbar

Hi I'm creating a systabcontrol32 control with the TCS_SINGLELINE style when I resize my window so the tab won't fit an up-down control appears that should allow me to scroll so I can see all the tabs. The thing is that the up-down buttons don't seem to work unless I add a the WS_HSCROLL property to the tab control witch makes it ugly ...

Normalize file path with WinAPI

Given two file path strings with potentially different casing and slashes ('\' vs '/'), is there a quick way (that does not involve writing my own function) to normalize both paths to the same form, or at least to test them for equivalence? I'm restricted to WinAPI and standard C++. All files are local. ...

querying through wmi & win32.client objects with python

Hi all, Could someone shed some lights upon querying through wmi and win32.client objects? Anytime i try to query throught win32.client object i get this error: Error: '' object has no attribute 'UserName' though, i know (wmic class "Win32_ComputerSystem", wmiexplorer etc.) the certain attribute belongs to the object i'm trying...

pygame is screwing up ctypes

import mymodule, ctypes #import pygame foo = ctypes.cdll.MyDll.foo print 'success' if i uncomment the import pygame this fails with WindowsError: [Errno 182] The operating system cannot load %1. the stack frame is in ctypes python code, trying to load MyDll. win32 error code 182 is ERROR_INVALID_ORDINAL. if the pygame import is no...

QueryFullProcessImageName failing with valid HINSTANCE?

//window is an HWND LPWSTR path = new WCHAR[1024]; DWORD size = 1024; GetWindowText(window, path, 1024); HINSTANCE instance = (HINSTANCE)GetWindowLongPtr(window, GWLP_HINSTANCE); QueryFullProcessImageName(instance, PROCESS_NAME_NATIVE, path, &size); This code fails on the call to QueryFullProcessImageName(...) with an error code 6 ...

C wINnet InternetConnect()

Say I wanted to do an anonymous login, would it be to blank strings. "" "" ? ...

Handling desktop position, font and other win32 console parameters

Is it possible to programmatically set such windows console parameters as its left-top desktop position, console font, fast insert and selection by mouse options, etc. ? EDIT Unfortunately we can set some console parameters by invoking undocumented Windows API. For example: SetConsoleFont, GetConsoleFontInfo, GetNumberOfConsoleFonts fro...

How to create directory with all rights granted to everyone

I need to programatically create a directory that grants "Full Control" to the group "Everyone". If I use CreateDirectory(path, NULL) This will, according to the Win32 SDK documentation this will create a directory that inherits from its parent directory. I do not want to inherit the access rights of the parent directory I need to e...

how can i change form shape in vb.net

I used to change the Form shape in VB 6.0 using the following code: Private Declare Function CreateRoundRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long) As Long Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVa...

How do you programmatically resize and move windows with the Windows API?

How do you programmatically resize and move windows with Windows API? The scenario is: I want to vertically tile two windows (80%/20% width proportions). ...

How can I get the process filename under Vista?

I have an application that aids people with disabilities. In order to work, it tracks the what window is currently in the foreground. Normally, I use this function to get process executable. bool GetWindowProcessExe2(HWND hwnd, wxString& process_exe) //LPTSTR buf, DWORD size) { DWORD result = 0; DWORD pid = 0; ...

Executing command prompt's functionality using Win32

What Windows API functions are available to execute command prompt's functionality? For example, I like to execute dir command and want to show the output in GUI without using cmd.exe in Windows. ...

"Spy++ has encountered a problem in the message hook"

I am deep in the middle of troubleshooting some Windows API messaging problem and I find that Spy++ is not working anymore. It doesn't even work on Notepad. On some occasions, it brings up this message: --------------------------- Microsoft Spy++ --------------------------- Spy++ has encountered a problem in the message hook. To preven...

Make multiple monitors go to sleep with Windows API?

How exactly would I make both of my monitors go to sleep, I want to write an application myself because I'd like to add certain functionality, and so far I can't find anything on MSDN relating to making your display go to sleep. ...

Temporarily Hide a Modal Dialog

I have a modal dialog displayed with the main application window set as owner (as in dialog.ShowDialog(mainAppWindow)) and I would like to temporarily allow the user to interact with the main application window before returning to the modal dialog again. How can I do this? I am using Windows Forms. Edit: AutoCAD does this well. ...

Run-Time Check Failure #0 loading QueryFullProcessImageName from kernel32.dll

I have an application that needs to run both on WinXP and Vista64. My program requires QueryFullProcessImageName() to work on Vista but not on XP. I try to load QueryFullProcessImageName() (instead of linking statically) via the kernel32.dll so that the same executable can run on both WinXP and Vista. The code that loads it is: //only ...

Getting a dump of a process that crashes on startup

On a customer machine (WinXP SP2) to which I have no access, I have a Win32 EXE (unmanaged C++) that crashes on startup. I guess the best way to troubleshoot this is to obtain a (mini-)dump and analyze it later with windbg or similar. Now, I would normally tell the customer to install Debugging Tools for Windows and run cscript adplus....