winapi

Same DLL loaded twice in a process

I have an ActiveX control (foo.dll), when I embedded the same in the IE and start the page. I could see that the process explorer shows two instances of the foo.dll loaded from the same location. This causes the DLL_PROCESS_ATTACH to be called twice and the global data structures gets initialized twice. Is there a way to workaround thi...

Getting Batch Script Error Code

I would like a Win32 process to launch an external script and be able to retrieve the ERRORLEVEL that it returns. The other way around is quite easy. Just use exit(errorcode) or return errorcode; in your Win32 app and the calling script gets its ERRORLEVEL value set properly. But, from a Win32 calling application, getting the script e...

Is there any way to determine what type of memory the segments returned by VirtualQuery() are?

Greetings, I'm able to walk a processes memory map using logic like this: MEMORY_BASIC_INFORMATION mbi; void *lpAddress=(void*)0; while (VirtualQuery(lpAddress,&mbi,sizeof(mbi))) { fprintf(fptr,"Mem base:%-10x start:%-10x Size:%-10x Type:%-10x State:%-10x\n", mbi.AllocationBase, mbi.BaseAddress, mbi.RegionSize...

MoveWindow deadlock?

I have a window on thread A, which at some point (as a result of a message being received on its wndproc) triggers an action on thread B, and then waits for the action to complete (using some sort of sync mechanism). Thread B then calls MoveWindow(), to move a child window within thread A's window (a standard textbox, for example). At th...

Listening on a comm port and stdin in Win32

I'm trying to write a small utility that maps stdin/stdout to a serial port (a command line terminal emulator of sorts) using the Win32 APIs. I have the following code, which I think ought to work, but it doesn't appear to be receiving notifications properly from the serial port: HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE); HANDLE hC...

The instruction at "<address>" referenced memory at "<address>". The memory could not be "read."

A c/c++ app throws that error, how to start to debug (better idea than adding print statements)? ...

AppDomain.GetCurrentThreadID vs Thread.ManagedThreadID for Windows API calls?

Hi, I'm trying to create a hook to monitor the current position of the mouse cursor. Nothing important, I just need to count some pixels during interface design and wanted to learn how to create a hook, so I decided to go for a hard way instead of a sane way. I've found example code which declares the following function: <DllImport("U...

Show tooltip outside of current Window

Hello, I have .NET WPF application and one of requirement is that user may select and copy text outside of my application. My application has to respond to clipboard event. Look up word from dictionary and next to selected text show tooltip with word's translation. As I understand this has to be accomplished using calls to Windows API...

More threads, better performance?

When I write a message driven app. much like a standard windows app only that it extensively uses messaging for internal operations, what would be the best approach regarding to threading? As I see it, there are basically three approaches (if you have any other setup in mind, please share): Having a single thread process all of the me...

.NET get selected text position cordinates from another window

Hello, I have .NET WPF application, that sits in background, and responds to user selecting text for example in Microsoft Word. After user selects text I need to draw window next to selected text. My question is: How it is possible to get selected text coordinates in currently active application? As I understand it has to do with Int...

Create an ActiveX control with pure WinAPI? (no MFC/ATL/etc)

Hi all, I'm looking at getting into ActiveX development and hopefully make a couple browser plug-ins by the end of things. I'm a seasoned WinAPI developer who has stayed away from such wrappers as MFC and ATL in the past, so I have virtually no experience in either area. However, in searching for tutorials on creating ActiveX controls in...

Determining the parent process id from C#

I would like to determine the process id of the parent process for an arbitrary process in Windows. I need this method to work on both x64 and x32. Any ideas / sample code to make this happen. System.Diagnositics.Process does not include this info. I am a bit worried about using the toolhelp apis cause they are 32 bit specific. R...

win32: change MessageBox text?

My program has multiple threads. I am using messagebox to display information to the user. Is there anyway (or an alternative to message box) that I can have another thread update/change the message-box display text while the message box is still on the screen and visible by the user? ...

Zeroing out a struct in the constructor

A wide range of structures is used in Win32 programming. Many times only some of their fields are used and all the other fields are set to zero. For example: STARTUPINFO startupInfo; // has more than 10 member variables ZeroMemory( &startupInfo, sizeof( startupInfo ) ); //zero out startupInfo.cb = sizeof( startupInfo ); //setting size i...

MsgWaitForMultipleObjectsEx and alertable wait state.

Is it possible to enter an alertable wait state using MsgWaitForMultipleObjects() / MsgWaitForMultipleObjectsEx()? ...

TAB control background in ATL App, XP styles

I have an ATL application with a dialog containing a TAB control. The App uses a common controls manifest. Under XP with visual styles, the tab control background is a different color than the dialog and the controls (mostly checkboxes), so it looks quite ugly. Screenshot How can I fix that? ...

Test if a font is installed (Win32)

How can I test if a font is installed? Ultimately, I want to implement a HTML-like font selection, i.e. when specifying e.g. "Verdana,Arial", it should pick the first font that is installed. This Question provides an answer for .NET - it seems the recommended way is to create the font, and then cmpare the font face actually used. Is ...

Detecting Windows Pop Ups

I'm trying to screen grab a window. I'm checking that I'm grabbing the foreground window using GetForegroundWindow() so in theory, nothing should be drawn on top of the window. I then call GetDC(GetDesktop()) and copy the area of the screen that my window occupies to a bitmap. If I instead, call GetDC(myWindowHandle) I don't get the t...

alternative to DataGridView in Win API

Somewhere on net on one Blog I read a sentence that is "DataGridView something like Boeing 777, but what is goal when I do not know how to fly. Before I goo deep in creating my projects I wanna know is there alternative for DataGridView in C#. Something like jQuery in WEB api. The favors things which I am looking for is that is simple f...

Raster Operator to use for MaskBlt

I'm trying to use the GDI MaskBlt command to draw an image with transparency: http://msdn.microsoft.com/en-us/library/dd145047(VS.85).aspx I can't seem to find anything in the documentation about what raster operator to use for the obvious use case: a sort of MAKEROP4(SRCCOPY, DSTCOPY) - blitting where the mask is 1, and leaving the des...