winapi

Freeing memory on the heap. Should I and how?

I'm writing a CESetup.dll for a Windows Mobile app. It must be unmanaged, which I have little experience with. So I'm unsure of whether I should free the memory I allocate and how I do it. Here's the function I've written: Uninstall_Init( HWND hwndParent, LPCTSTR pszInstallDir ) { LPTSTR folderPath = new TCHA...

How do I get a list of domain user accounts with win32 api?

How do I get a list of domain user accounts with win32 api? In particular, I can't get this list when the computer is not the domain controller. Instead it is a member of the domain. ...

How to check if program is running in local console?

In Windows Server 2003, how I can check if my program is running in local console ("on the screen of the server machine") instead of remote session? I'm using Delphi Win32, so any Windows API based method should work.. ...

Setting underlining of menu-hotkeys by API (windows)

By default Windows (XP) shows the underlined hotkeys only, when ALT is pressed. This can be changed in display-properties in the subdialog "Effects" so, that the hotkeys are always underlined How can it be changed programmatically? Which API-call or registry-setting can be used to change this setting? ...

Opening pipe connection to a file descriptor in C#

I have a legacy app where it reads message from a client program from file descriptor 3. This is an external app so I cannot change this. The client is written in C#. How can we open a connection to a specific file descriptor in C#? Can we use something like AnonymousPipeClientStream()? But how do we specify the file descriptor to connec...

How are Windows VK_ constants declared?

For example VK_LEFT, VK_DELETE, VK_ESCAPE, VK_RETURN, etc. How and where are they declared? Are they constants, #defines, or something else? Where do they come from? If possible, please provide a file name/path where they are declared. Or some other info as specific as possible. ...

APIs in C# for grabbing CPU IDs and drive/volume serial

I'm aware that I can grab the CPU identifier and the volume serial number for a physical drive by querying WMI, but WMI usually takes its sweet time. What other speedier options, if any, are available to retrieve this information? Are there Win32 APIs that would accomplish this? Edit: Allow me to clarify. By CPU identifier, I'm referrin...

Modify the behaviour of a NotifyIcon with via a 3rd party application

I've always been curious to see if I can show, hide or change a NotifyIcon created by another application via a C# application. Could someone please post an example on how to do this? :) ...

Detect changes in a filesystem since last scan

Programs that index filesystems seem to know which parts have changed since their last index and only rescan that part. How can I determine where the filesystem/files have changed since my last index. Don't care what language you answer in but I'm thinking c and windows. An example of such a program is Sequoia View which generates a tre...

Resetting Waitable Timers

From MSDN: The CancelWaitableTimer function does not change the signaled state of the timer. It stops the timer before it can be set to the signaled state and cancels outstanding APCs. Therefore, threads performing a wait operation on the timer remain waiting until they time out or the timer is reactivated and its state is set to si...

Issues with using unsupported Win32 GDI Pens modes?

The MSDN documentation is (somewhat) clear about the following two facts about GDI Pens: A Cosmetic pen (create via CreatePen or ExtCreatePen w/ PS_COSMETIC) must be 1 unit wide (well, <= 1, but let's not go there). A Geometric (ExtCreatePen w/ PS_GEOMETRIC) pen must solid (PS_SOLID only, no PS_DASH, etc). They can, however, draw fatt...

Why is RegOpenKeyEx() returning error code 2 on Vista 64bit?

I was making the following call: result = RegOpenKeyEx(key, s, 0, KEY_READ, &key); (C++, Visual Studio 5, Vista 64bit). It is failing with error code 2 ("File not found") even though "regedit" shows that the key exists. This code has always worked on 32bit XP. Why is it "file not found" when it clearly is there? ...

Is there an auto-update framework for C++/Win32/MFC (like Sparkle)?

I've decided to add auto-update functionality to one of my applications and was looking for any existing solutions that compare the current running version with the latest version that is then downloaded from the web. I know Sparkle on Mac OSX which is very nice and powerful, but was wondering whether there is something similar for Win3...

Crossplatform Bidirectional IPC

I have a project that I thought was going to be relatively easy, but is turning out to be more of a pain that I had hoped. First, most of the code I'm interacting with is legacy code that I don't have control over, so I can't do big paradigm changes. Here's a simplified explanation of what I need to do: Say I have a large number of si...

Help with CredEnumerate

As a follow-up to this question I am hoping someone can help with the CredEnumerate API. As I understand from the documentation the PCREDENTIALS out parameter is a "pointer to an array of pointers to credentials". I am able to successfully call the CredEnumerate API using C# but I am not sure of how to convert the PCREDENTIALS into so...

How can I mute/unmute my sound from PowerShell

Trying to write a PowerShell cmdlet that will mute the sound at start, unless already muted, and un-mute it at the end (only if it wasn't muted to begin with). Couldn't find any PoweShell or WMI object I could use. I was toying with using Win32 functions like auxGetVolume or auxSetVolume, but couldn't quite get it to work (how to read th...

How much memory does a thread consume when first created?

I understand that creating too many threads in an application isn't being what you might call a "good neighbour" to other running processes, since cpu and memory resources are consumed even if these threads are in an efficient sleeping state. What I'm interested in is this: How much memory (win32 platform) is being consumed by a sleepin...

Can I monitor the size of a thread's message queue?

Our application is getting a System Call Failed RPC error from DCOM (0x80010100), we suspect that the target thread's message queue is full (although I'm not convinced this is ture). I know the queue is limited to 10,000 messages and I want to see if we're close to this number in the common cases. Is there a way to monitor the size of a ...

Weird compile error dealing with Winnt.h

When trying to compile a file that include winnt.h via windows.h, I get the following error: MyGl.cpp ..\microsoft sdks\windows\v6.0a\include\winnt.h(964) : error C2988: unrecognizable template declaration/definition ..\microsoft sdks\windows\v6.0a\include\winnt.h(964) : error C2059: syntax error : 'typename T, size_t N> char (*RtlpNumb...

Bring a window to the front in WPF

How can I bring my WPF application to the front of the desktop? So far I've tried: SwitchToThisWindow(new WindowInteropHelper(Application.Current.MainWindow).Handle, true); SetWindowPos(new WindowInteropHelper(Application.Current.MainWindow).Handle, IntPtr.Zero, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); SetForegroundWindow(new WindowInter...