winapi

How can I debug a win32 process that unexpectedly terminates silently?

I have a Windows application written in C++ that occasionally evaporates. I use the word evaporate because there is nothing left behind: no "we're sorry" message from Windows, no crash dump from the Dr. Watson facility... On the one occasion the crash occurred under the debugger, the debugger did not break---it showed the application s...

Identify process using a file

I have been trying to figure out how to programmatically identify the process that has a lock on a particular file. I've searched through the Win32 API and WMI, but so far I can't find anything. I know it's possible - Sysinternals is able to list every resource accessed/locked by every process on the system. Can anyone drop me a hint?...

Correct way to maximize form in delphi (without caption)

I have a form without caption, using on double click to maximize : Code looks like this: procedure xxxxxx; begin if Form1.WindowState=wsNormal then begin Form1.WindowState:=wsMaximized; Form1.SetBounds(0,0,screen.Width,screen.Height-getHeightOfTaskBar); end else begin Form1.Windo...

Network interface settings

How can we get the network interface name (i.e. the one that appears in the "Network connections" dialog) given the device description (i.e. the string that appears in the "Device Properties -> Connect using:" textbox)? We must do it in pure C/C++ language, or through some of the standard command line tools (e.g. netsh, ipconfig...), or ...

RegSaveKey returns ERROR_PRIVILEGE_NOT_HELD

I'm trying to save the contents of a particular registry key to a file using the RegSaveKey() API: HKEY key; LRESULT result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Software\\MyProduct", 0, KEY_ACCESS_ALL, &key); result = RegSaveKey(key, L"c:\\temp\\saved.reg", NULL); However, RegSaveKey() is returning ERROR_PRIVILEGE_NOT_HELD. The SDK d...

Debugging (Tracing) WMI queries?

I've got a third-party program that's making WMI queries to local WMI providers (so it's not using DCOM, so packet-sniffers are out). I'd like to find out what queries these are. It's also on XP, so the new Vista WMI tracing infrastructure is out, as well, unfortunately. Any pointers? ...

"Repair" network connections programatically/from command line

Does anyone know exactly what Windows XP does when you click "Repair" on a network connection? I'd like to do the same programatically or from a command line. I did a Google search and found this article, which has a good explanation, but I don't think it's complete. I can reliably reproduce a condition where I lose network connectivity...

Problems using EnterCriticalSection

I need to work with array from several threads, so I use CRITICAL SECTION to give it an exclusive access to the data. Here is my template: #include "stdafx.h" #ifndef SHAREDVECTOR_H #define SHAREDVECTOR_H #include <vector> #include <windows.h> template<class T> class SharedVector { std::vector<T> vect; CRITICAL_SECTION cs; ...

How do I setup a callback mechanism for RichEdit in win32

In win32, how do I setup a callback mechanism for RichEdit I have not created myself? PART 1 I'm reading from a textedit field in another application's GUI. This works just fine now, except after the first read I'd like to fetch only new or modified lines. In GTK+ or Qt I'd just install a callback on some signal the field edits when it...

How do I delete a file from a c++ app without console window in Windows?

I need do delete a temporary file from my c++ windows application (developed in Borland C++ Builder). Currently I use a simple: system("del tempfile.tmp"); This causes a console window to flash in front of my app and it doesn't look very professional. How do I do this without the console window? ...

In Java Swing how do you get a Win32 window handle (hwnd) reference to a window?

In Java 1.4 you could use ((SunToolkit) Toolkit.getDefaultToolkit()).getNativeWindowHandleFromComponent() but that was removed. It looks like you have to use JNI to do this now. Do you have the JNI code and sample Java code to do this? I need this to call the Win32 GetWindowLong and SetWindowLong API calls, which can be done via the Ja...

How can I check to see if system is in standby mode?

Hello, I'd like to check if the system is in standby mode, is there any Win32 API for that? I'm not sure if it's the same as the sleep mode. There's some code that gets executed in my app, which causes it to hang when coming out of standby (it's executed during the standby mode), so I'd like to avoid running that code when the computer...

How can I send null characters to the serial port using the Windows API?

I am working on a Windows utility program which communicates with some custom hardware using a standard COM port. The communication protocol (which is out of my control) requires me to transmit and receive raw 8-bit data bytes. I am currently using the following Windows API function to send data to the COM port: WriteFile(hFile, lpBuff...

Performance degrades when compiling with _win32_winnt=0x0501 instead of 0x400

Is anyone aware of any performance implications from changing the _win32_winnt from 0x400 to 0x0501? I am compiling C++ on VS2005. My Application is very communications oriented, doing quite a lot of Winsock work. ...

How do I convert a string array to a LPCWSTR in .NET to pass to a Win32 API function?

Hi all I have a piece of C# code that needs to convert a string array to a LPCWSTR to pass to a Win32 API function. I can't find nothing in the Marshal class that makes it straightforward. Does anybody knows how to do that? ...

winsock missing data c++ win32

Hello, I am writing an application that needs to send data over a network. I have the application completed but there is a problem with sending the data. Every time I send a piece of data, it is cut off after 4 characters and the rest is garbage. The application is a remote keylogger I am writing for a school project, which requires you...

keep a formless application from closing for a keyboard hook

Hello, I am working on a c++ win32 program that involves a keyboard hook. The application is a win32 project with no user interface whatsoever. I need to keep the application from closing without using causing the hook to not work or use up a bunch of system resources. I used to use a message box but I need the application to be complete...

LPHANDLE vs. HANDLE

While browsing some code I found a call to OpenPrinter(). The code compiles and works fine. But, we are passing a HANDLE instead of LPHANDLE (as specified in MSDN). I found out that in windef.h the following declaration exists: typedef HANDLE FAR *LPHANDLE; What does LP stand for? Should I use a LPHANDLE, or keep HANDLE? ...

Usage of CoTaskMemAlloc?

When is it appropriate to use CoTaskMemAlloc? Can someone give an example? ...

Critical section - to be or not to be?

I`m writing a chat using WinSock2 and WinAPI functions. And I have a little trouble. I store the std::vector of client connections on server. When new client connects, new thread starts and all work with the client is done in this new thread. I do not use classes (I know it is not very good) so this list of connections is just defined as...