winapi

Reasons not use Winsock for HTTP request?

I currently use a simple winsock solution (WSAStartup, socket, connect, send, recv, closesocket) for HTTP-requests to get a 32 byte response of our own server. Is there a performance or security reason to switch to WinHTTP or another library? ...

XcvData "AddPort" function call fails

When I am calling XcvData "AddPort" with PORT_DATA_1 structure -> I get ERROR_INVALID_DATA. After digging around for a while I found out that if reserved field in tcpxcv.h header in PORT_DATA_1 structure is increased by 2 bytes then everything works fine. Anyone else had similar issue ? ...

CreateRemoteThread, LoadLibrary, and PostThreadMessage. What's the proper IPC method?

Alright, I'm injecting some code into another process using the CreateRemoteThread/LoadLibrary "trick". I end up with a thread id, and a process with a DLL of my choice spinning up. At least in theory, the DLL does nothing at the moment so verifying this is a little tricky. For the time being I'm willing to accept it on faith alone. ...

Mystery HRESULT, 0x889000D

Decimal: 143196173 Hex: 0x889000D Results from a call to IAudioSessionControl2->GetProcessId(). GetLastError = 126* Message = "The specified module could not be found" I'm not really sure how to interpret this error. Additionally, I can't find a description of the HRESULT anywhere. The documented return codes are S_OK, E_POINTER, AU...

Win API C++ Control Edit compulsory

Hi, I'm developing a GUI in C++ using dev-c++. I have an edit control like this: hctrl = CreateWindowEx( 0, "EDIT", /* Nombre de la clase */ "", /* Texto del título, no tiene */ ES_LEFT | WS_CHILD | WS_VISIBLE | WS_BORDER...

How to get size of check and gap in check box?

I have a check box that I want to accurately measure so I can position controls on a dialog correctly. I can easily measure the size of the text on the control - but I don't know the "official" way of calculating the size of the check box and the gap before (or after) the text. ...

How to get the Windows Power State Message (WM_POWERBROADCAST) when not running a Win32 GUI app?

So basically I have a plugin dll that is loaded by a GUI-Application. In this dll I need to detect when Windows enters the Hibernate state. I cannot modify the GUI-App. GetMessage only works if the calling thread is the same thread as the UI-Thread, which it is not. Any ideas? ...

Mocking and Win32 API Calls

The current product I work on is a Windows Service written C++ and going forward all new functionality will have unit tests written for it. But this creates an interesting problem (for me at least) we do a lot Win32 calls for various things and behave accordingly, so for the unit tests to be complete it would be nice to test a variety o...

Some WinAPI to check which process created a named pipe?

Is there some WinAPI call which would tell me who (which process) has created the named pipe? Note: Asking this questions, I have a feeling it "smells" somehow, and a proper design will be to communicate the process ID/handle using other means, however getting this information from the pipe itself would be simpler, and therefore if ther...

What is the performance of boost::interprocess_mutex vs Win32 native mutexes?

Note that I can conduct the research inside the boost source code, and may do this to answer my own curiosity if there isn't anyone out there with an answer. I do ask however because maybe someone has already done this comparison and can answer authoritatively? It would seem that creating a shared memory mapped file between processes, ...

How to reserve bottom 4GB VM in an x64 C++ app

Working on porting a 32bit Windows C++ app to 64 bit. Unfortunately, the code uses frequent casting in both directions between DWORD and pointer values. One of the ideas is to reserve the first 4GB of virtual process space as early as possible during process startup so that all subsequent calls to reserve memory will be from virtual add...

Win32 Message Handler Error Propagation

I'm writing a (C++) application that utilizes a single dialog box. After setting up a message pump and handler I started wondering how I would go about propagating C++ exceptions to my original code (i.e., the code that calls CreateDialogParam, for instance). Here's a skeleton example of what I mean: BOOL CALLBACK DialogProc(HWND, UINT...

How do I generate an HTML file using XSL?

Hello, As I understand it, using XSL to generate documents has two parts: 1) An XML document which references an XSL stylesheet 2) An XSL stylesheet Let's say that I want to generate a document using XSL, and then send it to a friend. Without relying on the stylesheet being available on the internet, and without including the styleshe...

WM_KEYDOWN : how to use it?

Hello. I'm trying to send a key stroke to one application, through PostMessage. I am using too Spy++ to try to understand how to send the message, as I do not fully understand its inner workings. In this picture, the first item(selected item) was made with an actual key stroke made by myself. The one with a red elipse around it(below)...

How to mark a list control item as selected?

In a Win32 application I have a dialog with a list control which is defined is the dialog template: CONTROL "",IDC_LIST_Attributes,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP,7,36,246,110 In the runtime I retrieve the handle to that control and perform different operations with it - remove ...

How to get the plugged/unplugged cable state.

I know about the IsNetworkAlive function from the Windows API but IsNetworkAlive returns false until there's any network activity. That is, if you start your computer and test connectivity it will return false. If you then ping another computer (or recieve a ping or any network activity from another computer) then it will start returni...

Any tools available for packing 32bit/64bit executables together?

I really like the way the SysInternals utilities (e.g. Process Explorer) handle 64bit compatibility. It looks like the 32bit executable has the 64bit version embedded in it, and extracts it if necessary. I'd like a tool which automates this - i.e. takes 32bit and 64bit executables, packs them together somehow, and inserts stub code to l...

java - JNI/JNA - Get Window Title

Looking to get back into the development space; primarily using Java to call some native win32 functions (I don't desire to build in .NET).... Can someone point me to a place where I can read the title from a differnt running window using Java (JNI/JNA/SWIG). Assume you would know where in the memory space the application you are attemp...

Setting the initial directory of an SaveFileDialog?

I'd like a SaveFileDialog with the following behavior: The first time you open it, it goes to "My Documents". Afterwards, it goes to the last selected folder. What's the best way to accomplish this? If I don't set the InitialDirectory, it goes to the exe's directory - which is not what I want. It rememebers the last selected director...

CallNamedPipe & NamedPipeServerStream, access denied?

I'm trying to do some IPC between a managed and unmanaged process. I've settled on named pipes. I'm spinning up a thread in managed code, using NamedPipeServerStream: using (NamedPipeServerStream stream = new NamedPipeServerStream("MyPipe", PipeDirection.In)) { while (true) { stream.WaitForConnection(); stream.Read(buffer,...