winapi

Does a DLL get removed if the DLL that loaded it is unloaded?

Take a standard Windows application. It loads a DLL using LoadLibrary to call a function in it (we'll call this DLL_A). That function loads another DLL (we'll call it DLL_B). The application now unloads the DLL_A DLL using FreeLibrary as it no longer requires it. The question is: Is DLL_B still in memory and loaded? Is this something...

InterlockedIncrement usage

While reading about the function InterlockedIncrement I saw the remark that the variable passed must be aligned on a 32-bit boundary. Normally I have seen the code which uses the InterlockedIncrement like this: class A { public: A(); void f(); private: volatile long m_count; }; A::A() : m_count(0) { } void A::f() { ::Inte...

Reasons for stack unwinding fail

I was debugging an application and encountered following code: int Func() { try { CSingleLock aLock(&m_CriticalSection, TRUE); { //user code } } catch(...) { //exception handling } return -1; } m_CriticalSection is CCricialSection. I found that user code throws an exception such that m_CriticalSection is...

Can the HWND from CreateWindow/CreateDialog be GetMessage'd from another thread?

Using the Win32 APIs, is it possible to create a Window or Dialog in one thread then collect events for it from another thread? Are HWNDs tied to threads? Trying the contrived example below I never see GetMessage() fire. HWND g_hWnd; DWORD WINAPI myThreadProc(LPVOID lpParam) { while(GetMessage( CreateThread(NULL, 0 myThreadP...

How do I get Windows Explorer to show a preview of my files in 'thumbnail' view?

I'm making a 3D editor and I want Windows Explorer to show previews of the 3D models in the files when it's in thumbnail view mode. How do I do that? ...

How can I decrypt a cipher from the middle?

I have to encrypt the output file in A application, then decrypt it in B application, but I found there are some limitations with MS encryption, if I encrypt a 1000 bytes buffer and then want to decrypt start for different position with different size in B application, the return values are error. Is there any encryption can meet my requ...

How can I make networking work in my WinCE app without launching IE first?

I have a simple WinCE network application (in C, Win32 APIs). I find that networking doesn't seem to work unless I launch IE (or another network app) first. I assume that IE is setting up my network interface in some way. How can I do this for myself? Might I need to display a list of available interfaces to the user (eg. WiFi/Ethernet...

Debugging multithreaded applications

I have an application written in C++ and MFC which is multithreaded running on windows. Occasionally I do get some complaints such as deadlocks or an unhandled exception which is caused because of these threads. Normally I use visual studio (if the problem is reproducible) or else use the WinDbg to analyse the dump files generated. Is th...

MSXML: How does one programmatically get the error text for failed transforms?

XMLNotepad provides the following text (for example) when a transform fails: Error Transforming XML The variable or parameter 'saturated-background-color' was duplicated with the same import precedence. How would I go about getting this error text programmatically? My code looks like this: CComPtr<IXSLTemplate> tmpl; HR...

Can a single SetEvent() trigger multiple WaitForSingleObject()

This: http://msdn.microsoft.com/en-us/library/ms686915(VS.85).aspx Would seem to suggest not. I have three processes communicating via pipes. Process A Creates an event, Process B & C each use WaitForSingleObject (in a second thread). So now we have -TWO- Processes each waiting for a -SINGLE- event. Process A fires the event with Se...

Restoring window focus back to previous owner

I've got an application that sits in the system tray, which when double clicked on opens a window, fairly standard; however, when you close the window I'd like the window that was focussed before mine was opened to be given back focus. If I pop my window up by a keyboard shortcut, I'm able to restore the previous focus on close by using...

COM-Interface for accessing file information (title, subject, author)?

Hi, On NTFS, any file can have extended file information based on an Alternate Data Stream. Explorer displays this as a tab in the file properties dialog. I am quite sure there is a COM-Interface for reading/modifying this information, but I seem to be unable to come up with the right terms for my search. Can anyone give me a short poi...

Win32 programming hiding console window

Im learning C++ and i made a New program and i deleted some of the code and now my console window will not hide is there a way to make it hide on startup without them seeing it ...

How to move the window default scrollbar above the status bar?

Every program does have the scrollbar above the status bar. Right? Well, not mine. When i tried to set up my own scroll bars in my program, i suprisingly made them work! So did i manage to get the status bar work too! Hurray! :-) ...But the status bar is ABOVE the scroll bar, when it should be UNDER the scroll bar. How do i move the scr...

Reverse engineer C++ DLL

I have a small utility that was originally written in VS2005. I need to make a small change, but the source code for one of the dlls has been lost somewhere. Is there a free or reasonably priced tool to reverse engineer the dll back to C++ code. ...

Wait for a specified amount of objects?

Using WaitForMultipleObjects: Makes it possible, to wait for one or all of specified objects to change to a singled state Question: How can one wait for a specified amount - such as 5, for example Usage dwEvent = WaitForMultipleObjects( maxExpectedConnections, ghEventsA, TRUE,//but wait for a specified number instea...

How can I write a generic C function for calling a Win32 function?

To allow access to the Win32 API from a scripting language (written in C), I would like to write a function such as the following: void Call(LPCSTR DllName, LPCSTR FunctionName, LPSTR ReturnValue, USHORT ArgumentCount, LPSTR Arguments[]) which will call, generically, any Win32 API function. (the LPSTR parameters are essentially be...

ShellExecuteEx or HlinkSimpleNavigateToString

I want to launch a web page in the default browser from my Win32 application. Both functions do the job. Is there any reason to use one or the other? ...

CComboBox automatically selects text after call to MoveWindow

I'm currently experiencing a very strange problem with a CComboBox used within a CFormView. After adding strings to the combobox (created with WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWN | CBS_SORT | CBS_AUTOHSCROLL), I'm selecting an entry via CComboBox::SetCurSel and resize the combobox via MoveWindow in the OnSize(...

API to validate the pointer before use

Is there any simple Win32 API to check whether a pointer points to a valid memory location before using it for write operation? ...