Menu
  • HOME
  • TAGS

Populating a List Control with the sorted contents of an `std::multimap`?

c++,winapi,stl,mfc,clistctrl

You cannot access the content of a std::multimap by index directly. But what you can do is store your sorted data in a std::multimap and then store iterator values in a separate std::vector and use that as the data source for your ListView. When the ListView asks for data by...

Hide Window from taskbar without using WS_EX_TOOLWINDOW

c,winapi

Simplifying a little, a window is represented in the taskbar if: It is not owned and does not have the WS_EX_TOOLWINDOW extended style, or It has the WS_EX_APPWINDOW extended style. So, the solution for you is to make the window be owned. It should be owned by the main window...

User process can't see global shared memory created by service

c++,windows,security,winapi,memory-mapped-files

Your service is closing its handle to the file mapping immediately after creating it, thus the mapping is being destroyed before the app has a chance to open its handle to the mapping. Your service needs to leave its handle to the mapping open, at least until after the app...

If I created a process, does it mean that I will always be able to terminate it?

c++,c,windows,winapi,process

I haven't tested it, but according the documentation you should always be able to successfully terminate process using the handle returned in the PROCESS_INFORMATION. In Windows security model permissions are normally only checked against the handle being used, nothing else. According to the MSDN documentation on Process Security and Access...

When and how often does the EV_RXCHAR event fire (from WaitCommEvent)?

c#,.net,winapi,events,serial-port

It's explained in more detail in the MSDN page on Communications Events: For example, if you specify the EV_RXCHAR event as a wait-satisfying event, a call to WaitCommEvent will be satisfied if there are characters in the driver's input buffer that have arrived since the last call to WaitCommEvent or...

C++ and WinApi - usage of GetWindowText() to get parameters for C++ code

c++,winapi,file-io

You need to properly handle WM_KEYDOWN, not WM_COMMAND, because windows receives WM_KEYDOWN after key is pressed and WM_COMMAND after variuos of events. case WM_KEYDOWN: { if(wParam == VK_RETURN) { DWORD dlugosc = GetWindowTextLength( g_hText ); LPSTR Bufor =( LPSTR ) GlobalAlloc( GPTR, dlugosc + 1 ); GetWindowText( g_hText, Bufor, dlugosc...

How to build a dynamic array in C++ and return it back to C#/.NET

c#,c++,.net,arrays,winapi

A very common way of implementing "dynamic arrays" in C++ is to use STL's std::vector. In your case, you can define a vector<SomeData>. std::vector can change its size dynamically (i.e. at run-time), as per your request: you can use its push_back or emplace_back methods for that purpose, adding new items...

Click-through Controls in VB.NET

vb.net,winapi,controls,click-through

If you don't want a window to receive input you have to disable it, calling the EnableWindow function: Enables or disables mouse and keyboard input to the specified window or control. When input is disabled, the window does not receive input such as mouse clicks and key presses. Mouse messages...

WTSEnumerateSessions from JNA

winapi,jna

WTSEnumerateSessions() returns: a pointer to an array of WTS_SESSION_INFO structures a pointer to a DWORD of the number of elements in the the array. So you need to pass a PointerByReference for the ppSessionInfo parameter, and a IntByReference for the pCount parameters. You can then use the values being pointed...

C++ Run-Time Library is set to /MT, but api-ms-win*.dll's are still missing

c++,multithreading,winapi

You are calling functions that are not available on versions earlier than Windows 8. Copying DLLs is certainly wrong. You absolutely cannot legally distribute Windows DLLs and in any case you cannot expect to use DLLs designed for one version on a different version. You will need to use dynamic...

RegisterApplicationRestart with different path

winapi

A can launch B using CreateProcess() before exiting, passing its own process handle to B. Before B accesses the resource, it can wait on A's handle using WaitForSingleObject() or related function. When the handle is signaled, A has fully terminated, so B can close the handle using CloseHandle() and move...

How do I declare OutputDebugStringA without windows.h macros?

c++,winapi

The issue is that the Windows API is C based, and thus the functions that are to be called are C functions, not C++ functions. The problem when compiled under a C++ compiler is that the function name gets mangled (due to C++ use of function overloading). Thus the function...

Sharing Folder API

c#,.net,winforms,winapi,shared-folders

You can do it through Win32 API: private static void QshareFolder(string FolderPath, string ShareName, string Description) { try { // Create a ManagementClass object ManagementClass managementClass = new ManagementClass("Win32_Share"); // Create ManagementBaseObjects for in and out parameters ManagementBaseObject inParams = managementClass.GetMethodParameters("Create"); ManagementBaseObject outParams; // Set the input parameters inParams["Description"] =...

c++ PE injecting additional functionality

c++,winapi

What you are trying to build is called a "binder". You can achieve the effect you want by having the wrapper "join" two PE files, the stub and the decoy. The stub will implement the main features you outlined (downloading from the link, timeouts e.t.c) and will also be responsible...

Troubleshoot why PrintWindow is blank

winapi,screenshot

Every window has a default implementation for WM_PRINT, you will use it if you call PrintWindow() and don't use the PW_CLIENTONLY flag. Provided by the default window procedure, DefWindowProc(). It is pretty straight-forward, it creates a memory DC and sends WM_PAINT. So what you get in the bitmap is the...

python Win32 Excel is cell a range

python,vba,winapi,range

What you may consider doing is first building a list of all addresses of names in the worksheet, and checking the address of each cell against the list to see if it's named. In VBA, you obtain the names collection (all the names in a workbook) this way: Set ns...

Why do some WinAPI functions need sizes of structs passed as their parameters?

c,windows,winapi

It's a simple form of versioning for the structures. A later version of the API could add more fields to the end of the structure, which would change its size. Programs written for the older version won't have set values in the newer fields and the cbSize parameter will reflect...

C++ Win32 how can i put this functions on separate cpp file?

c++,winapi

With current compilers you can't compile template code separately except for instantiations with known types/values. The main problem appears to be this code: template<typename T, typename... Args> void addToStream(stringstream& a_stream, const T& a_value, Args... a_args) { a_stream << a_value; addToStream(a_stream, a_args...); } template<typename... Args> void log(Args... a_args) { stringstream strm;...

Can a dialog intercept drag'n'drop messages passed to its controls?

winapi,mfc,drag-and-drop

If a dialog registers some of its controls as drop-targets, will drag'n'drop messages intended for those controls pass through the dialog's message processing in a way that the dialog can register a message handler to be notified/intercept those messages? If the controls are using DragAcceptFiles(), WM_DROPFILES messages will go...

Windows Crypto API CryptEncrypt with the HashObject

c,node.js,winapi,cryptography,mscapi

You should be using a password-hash function, not just a normal hash. A password-hash is salted and has a work-factor that makes it harder for an attacker to guess the password using a dictionary attack. Microsoft has created an implementation of PBKDF2 in the CNG framework. PBKDF2 is also contained...

MapViewOfFile() no longer works after process hits the 2GB limit

winapi,memory,out-of-memory

Why MapViewOfFile fails As IInspectable's comment explains freeing memory allocated with malloc doesn't make it available for use with MapViewOfFile. A 32-bit processes under Windows has a 4 GB virtual address space and only the first 2 GB of it is available for the application. (An exception would be a...

ICallFactory with 32-bit and 64-bit type libraries side by side

windows,winapi,com,registry,typelib

Figured it out. RegisterTypeLib and RegisterTypeLibForUser always write both 32-bit and 64-bit entries when running on a 64-bit OS (even if the process is 32-bit). This is perfectly acceptable in most cases since it's only the interface and type library metadata that gets written. When the interface key is written,...

How do I call LocalFree()?

c,winapi

Neither of those, but never LocalFree(lpText) From the looks of your code, the memory pointed to by lpText is going to be junk after you call LocalFree. If you call LocalLock, then you should call LocalUnlock(localHandle) before you call LocalFree(localHandle). Why not just use malloc? Is there some technical reason...

Win32 Message Pump and std::thread Used to Create OpenGL Context and Render

multithreading,winapi,opengl,c++11

A Win32 window is bound to the thread that creates it. Only that thread can receive and dispatch messages for the window, and only that thread can destroy the window. So, if you re-create the window inside of your worker thread, then that thread must take over responsibility for managing...

If statement not working in vb6

winapi,vb6

Your Mid() statement is wrong. The third parameter needs to be length - 1 instead of length + 1 to strip off the null terminator: title = Mid(title, 1, length - 1) Since you are not stripping the null terminator, your title variable does not actually contain "Personalization" by itself,...

Issue finding exe path of all windows in python

python,windows,winapi

That error indicates that you are executing 32 bit code in the WOW64 emulator on 64 bit Windows, and trying to gain information about a 64 bit process. To get past this you should switch to running 64 bit code. So, you'll need 64 bit Python. ...

How to start an application as a child of a newly created explorer process?

c++,winapi,process

If your really want to make the new Process a child of that other process, you have to use code injection. A search for CreateRemoteThread will give you plenty of reading material. The biggest problem is, that your process has to be the same bit-ness as the target. There are...

Why is _stprintf_s overwriting other variables but _stprintf is not?

c++,winapi,printf,malloc

also in my runs semaphores are overwritten with value 0xfefefefe This is a "magic value", it is written by the safe CRT functions (like _stprintf_s) to help you debug mistakes in the buffer length you pass. The debug build of these functions fill the entire buffer, using 0xfe as...

Edit control doesn't generate WM_COMMAND messages

winapi,controls,editcontrol

For an edit control, notifications are sent to the original parent of the control. That is, in your case, the message only window. In a comment to a similar question Raymond Chen says: Many controls cache the original parent. Not much you can do about it. You may be best...

std::vector content change when read inside the main()

c++,string,winapi,vector

A std::vector<LPWSTR> is a std::vector<wchar_t*> (since LPWSTR is a typedef for wchar_t*). Now, having a vector of raw owning pointers is very fragile. You can have a vector of raw observing pointers, and you must be sure that the strings pointed to are still allocated (kind of "live") when you...

winapi: from HDC to an HBITMAP

c++,winapi,bitmap,gdi

I think you just need some clarification about GDI. A DC is exactly what its name imply : a device context. It's just a context, nothing concrete. Some DCs are context to a real graphic device, some others (memory DCs) are context to a virtual graphic surface in memory. The...

C - Windows Exception Handler Invalid Handle

c,windows,winapi,exception,exception-handling

The __except block is never entered because ReadFile does not throw exceptions. Remember that the Windows API is agnostic of programming language and needs to present an interface that can be consumed by any programming language. And not all languages have support for exceptions, and even those that do use...

“Un-associate” socket from completion port

c++,sockets,winapi,winsock,iocp

A handle that is associated with an I/O Completion Port is removed from the port when the handle is closed. In case of a network socket, the handle is closed by calling closesocket(). The documentation for CreateIoCompletionPort contains remarks on resource handling: The handle passed in the FileHandle parameter can...

Win32, MFC: Ending threads

c++,multithreading,winapi,mfc

In general the correct way to end a thread is to ask it to finish and then wait for it to do so. So on Windows you might signal an event to ask the thread to finish up then wait on the thread HANDLE. Forcefully terminating a thread is almost...

Winapi AppendMenu LPCTSTR variable ampersand

c,winapi

Ampersand is a placeholder for menu access key. The following letter is underlined, and Windows can be set up to show the underscore always, or when Alt key is pressed. The underlined letter is an access key, so when particular menu is open you can press the key to activate...

Dialog resource as a main form

c++,winapi

Creating the dialog by itself is sufficient.

Named pipes and OVERLAPPED on Windows

winapi,named-pipes

You don't need to use FILE_FLAG_OVERLAPPED if all you're doing is reading and writing using the same handle at the same time. Other threads reading or writing to the same end of the pipe won't cause it to block. You only need it if you want to perform asynchronous I/O,...

Restarting a process from another process

c++,winapi

There are a few ways you could do this but two options are: When you launch ProcessA again, pass it a command line argument using the lpCommandLine parameter (e.g. /nolaunch). ProcessA can then get its command line using GetCommandLine when it starts up and see if it contains the /nolaunch...

what to return or to do in a winapi window procedure in order to intercept an error and produce an error log entry

c,winapi

You can only apply your policy to functions whose prototypes are in your control. A window procedure is out of your control. The meaning of the return value is not determined by you. The Windows API determines that, and does so in a way that is not compatible with your...

Is a StatusBar created in simple mode by default?

c,winapi

Status bars are created, as you have done, with a call to CreateWindowEx. When a status bar is first created it has no parts. Parts are added to status bars by sending a SB_SETPARTS message to the status bar. Is it created in simple mode or in multiple-part mode? Simple...

How do I write a Windows 10 universal class library that references native code?

winapi,native-code,windows-universal

Windows 10 Universal Applications run under the Windows Runtime API, a new "native" API for Windows. Applications using this API run in a sandbox which limits their access to devices and operating system services. While Win32 APIs can be accessed like normal, for example using P/Invoke in the case of...

Passing HWND through to a method and storing in a class

c++,winapi

Your IGraphicContext::SetWindowInfo method makes a copy of the passed in WindowInfo. If the original is then modified later on (e.g. by calling SetHndToWindow) this won't affect the copy that IGraphicContext holds. If you really want to share a structure like this between two separate classes you should look at holding...

is there a difference between running an executable and debugging it in Visual Studio?

c++,visual-studio-2010,winapi,runtime-error,visual-studio-debugging

Yes! Running a program directly form the debugger the debug heap is in use. Assuming it isn't compiled in debug mode. And the memory layout changes when the debugger is loaded into the process address space. So some weird things may happen. If you have such strange effects it is...

MessageBox won't work when handling WM_DESTROY event from DialogBox

c,user-interface,winapi

When you use DialogBox rather than DialogBoxParam, the dialog runs its own message loop that handles WM_DESTROY internally. When you post the WM_QUIT message from your dialog procedure you are generating an additional message* that the dialog box won't use, so it remains in your thread's message queue once the...

Splitting TCHAR into bidimensional vector

c++,winapi

You can use one of these following function: std::istream::get You can read about this function in here,istream& get (char* s, streamsize n);. Example: char *s; cin.get(s, 4); cout << s << endl; and output: string test str std::istream::read Or you can use this function, istream& read (char* s, streamsize n);....

Count digits in file using WinApi functions

c++,winapi,createfile

You don't need the extra level of complexity of creating a std::string, you've already got it in the form of a char array, and you can make use of dwRead, which is the no. of bytes read by ReadFile(). for (int i = 0; i < dwRead; ++i) if (iswdigit(data[i]))...

Read lines from file async using WINAPI ReadFile

c++,multithreading,winapi,createfile,overlapped-io

When you open a file with the FILE_FLAG_OVERLAPPED flag and then use an OVERLAPPED structure with ReadFile(), use the OVERLAPPED.Offset and OVERLAPPED.OffsetHigh fields to specify the byte offset where reading should start from. Also, you must use a separate OVERLAPPED instance for each ReadFile() if you run them simultaneously. This...

Non blocking SHFileOperation

winapi

So my question is, how is it possible to call SHFileOperation, close the process right after the call and it's still doing the job? It is not possible. If you kill the process then SHFileOperation will be stopped before completion. The only way to achieve this is to hand...

Confusion about CTRL_SHUTDOWN_EVENT handling in DLLs and WM_QUERYENDSESSION

c,winapi,console,shutdown

When you return TRUE from the handler you registered, Windows immediately terminates the process. When you return FALSE, the previous handler gets called. Ultimately that will be the default handler, it immediately terminates the process. So what you have to do is not return and block until you are happy....

Generating a self-signed X509Certificate2 certificate with its private key

c#,.net,winapi,pki,x509certificate2

The problem is with CryptKeyProviderInformation structure signature. It is missing CharSet (with either, Auto or Unicode) attribute, because container and provider names are expected to be unicode (after marshalling). Update structure definition as follows: [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] struct CryptKeyProviderInformation { public String pwszContainerName; public String pwszProvName; public Int32 dwProvType;...

How can a dialog become responsive while waiting for a call to DoModal() to return?

winapi,com,mfc,modal-dialog

The dialog has its own message pump/loop and inside the call it has a loop where it keeps receiving and dispatching window messages. This includes COM related messages worker windows receive and convert to COM callbacks you are seeing. Once the dialog is closed, respective windows are destroyed, the function...

How to get global Windows I/O statistics?

c++,windows,winapi

You can get the data one disk at a time using DeviceIoControl, something like this: #include <windows.h> #include <iostream> int main() { HANDLE dev = CreateFile("\\\\.\\C:", FILE_READ_ATTRIBUTES, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); DISK_PERFORMANCE disk_info { }; DWORD bytes; if (dev == INVALID_HANDLE_VALUE) { std::cerr << "Error opening disk\n";...

Get list of process

delphi,winapi

This is very platform-specific, and as such there is nothing in FireMonkey or VCL to help you with it. You have to use platform APIs directly. For instance, on Windows you can use CreateToolhelp32Snapshot(), Process32First() and Process32Next(): Taking a Snapshot and Viewing Processes Or you can use EnumProcesses(): Enumerating All...

Accessing GetConsoleHistoryInfo() from managed code

c#,winapi,console-application,dllimport,managed

You should declare it like this: [DllImport("kernel32.dll", SetLastError = true)] static extern bool GetConsoleHistoryInfo(ref CONSOLE_HISTORY_INFO ConsoleHistoryInfo); You will need the CONSOLE_HISTORY_INFO type too for this to work: [StructLayout(LayoutKind.Sequential)] public struct CONSOLE_HISTORY_INFO { uint cbSize; uint HistoryBufferSize; uint NumberOfHistoryBuffers; uint dwFlags; } A lot of useful PInvoke information can be found...

Disable application taskbar icon's context menu in Windows 8.0 and 8.1

windows,winapi,visual-c++,contextmenu,windows-taskbar

I found this registry value which does the job well: NoViewContextMenu: https://technet.microsoft.com/en-us/library/cc960925.aspx...

Is Multi-layered SRWLock Valid?

c++,winapi

This should work. "Acquiring a lock recursively" means acquiring the same lock twice. Example: SRWLOCK lock; ::InitializeSRWLock( &lock ); ::AcquireSRWLockExclusive( &lock ); // acquire the lock // Now we have the lock ::AcquireSRWLockExclusive( &lock ); // acquire the lock again!? // Now we still have the lock ::ReleaseSRWLockExclusive( &lock );...

New window opening with parent window's controls

c++,winapi

//same as vnWind ... vnEk.lpszClassName = L"vnTest"; No, that's not enough. It is not the name that matters, that's just a selector. It is the content of the WNDCLASSEX struct you pass to RegisterClassEx() that matters. And especially the lpfnWndProc member. Windows primarily behave different from one another by having...

MoveFileEx() File removal on reboot

c++,windows,winapi

The answer was that if a directory or file is not marked to be deleted then the directory in which it is in will not be deleted. (Just as IInspectable noted) "The system deletes a directory that is tagged for deletion with the MOVEFILE_DELAY_UNTIL_REBOOT flag only if it is empty."...

Is HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography\MachineGuid unique?

windows,winapi

If a machine is restored from a backup or clone (such as in disaster-recovery, lab rollout, or fast VM deployment scenarios) then the MachineGuid value would be the same on multiple machines. I note that the key value itself is read/write, so a post-setup or userland application could overwrite this...

Is it possible to set a multiple conditions Breakpoint in Visual Studio 2013?

c++,winapi,visual-studio-2013

Using && is allowed and should work. What's more, a lot of common C++ expressions are allowed. This page lists what is and what isn't allowed. Note that using this kind of breakpoint will considerably slow down your application. To the point where debugging is no longer feasible. This might...

Error when I try EnumProcessModules in windows 8 64bit

delphi,winapi

You don't enter an infinite loop; you enter a very long loop. When EnumProcessModules fails, it evidently sets cbNeeded := 0. That sets the length of you array to zero, too. You then enter a loop starting at 0 and ending at –1. Interpreted as a Cardinal, the value –1...

How to execute a file with a different extension's associated application?

delphi,winapi,shellexecute,file-association

Call ShellExecuteEx and specify the lpClass member of the SHELLEXECUTEINFO struct. Note that you must include SEE_MASK_CLASSNAME in the fMask member. For instance, set lpClass to '.txt' to request that the file be opened with the program associated with the .txt extension. ...

Get all supported FPS values of a camera in Microsoft Media Foundation

c++,windows,winapi,ms-media-foundation

The frame rates and other attributes can be retrieved with code similar to the following (error checking omitted for brevity): Microsoft::WRL::ComPtr<IMFSourceReader> reader = nullptr; /* reader code omitted */ IMFMediaType* mediaType = nullptr; GUID subtype { 0 }; UINT32 frameRate = 0; UINT32 frameRateMin = 0; UINT32 frameRateMax = 0;...

MASM console window creation troubles (maybe my stack frame??)

winapi,assembly,stack,x86-64,masm

mov dword ptr [rsp + 20h], 0 is wrong. The last parameter has the type LPOVERLAPPED, which is here a 64-bit pointer. Change the line to mov qword ptr [rsp + 20h], 0 Also, lea rcx, handle is wrong. WriteFile expects a value, not an address (pointer). Change it to...

SetWindowDisplayAffinity fails with error “Access denied”

java,winapi,jna

SetWindowDisplayAffinity can only be used on a window owned by the calling process. Hence the error. The documentation says: This feature enables applications to protect their own onscreen window content from being captured or copied through a specific set of public operating system features and APIs. The feature would be...

More convenient way to work with strings in winapi calls

string,winapi,rust

In your situation, you always want a maximum of 255 bytes, so you can use an array instead of a vector. This reduces the entire boilerplate to a mem::uninitialized() call, an as_mut_ptr() call and a slicing operation. unsafe { let mut v: [u16; 255] = mem::uninitialized(); let read_len = user32::GetWindowTextW(...

C++ Windows API DlgDirList sometimes don't return the correct listing

c++,winapi,listbox,directory-listing,file-listing

I think the clue is in the docs for the DlgDirList function: If lpPathSpec specifies a directory, DlgDirListComboBox changes the current directory to the specified directory before filling the list box. I've never used these functions myself but I'd bet that your current directory is being modified and so subsequent...

heap error after changing from new allocation to smartpointer

c++,winapi

LPWSTR wcSerialNumber = new wchar_t[newsize]; auto wcSerialNumber = make_unique<wchar_t>(newsize); Those two lines do very different things. The first dynamically allocates an array of wchar_ts with a number of elements equal to newsize. The second line dynamically allocates a single wchar_t, calling the constructor with newsize as an argument. std::unique_ptr is...

Does GetVolumeInformation() returns a unique volume serial number?

winapi

The volume serial number is a DWORD. There are 232 different possible values of a DWORD. Therefore it stands to reason that since there are a finite number of possible values, and an unbounded number of volumes in the world, that there could be multiple volumes sharing the same serial...

How do I free the standard icons and cursors (those loaded with LoadIcon/Cursor(NULL, IDI/IDC_WHATEVER))?

c,winapi

You don't unload the system-defined icons or cursors. The documentation for DestroyIcon, for instance, specifically says (emphasis added): It is only necessary to call DestroyIcon for icons and cursors created with the following functions: CreateIconFromResourceEx (if called without the LR_SHARED flag), CreateIconIndirect, and CopyIcon. Do not use this function to...

What does « program is not responding » mean?

windows,winapi,windows-process,not-responding

What this means is that the program is failing to service its message queue. From the documentation: If a top-level window stops responding to messages for more than several seconds, the system considers the window to be not responding. In this case, the system hides the window and replaces it...

Calling Win32 Functions From Julia

winapi,julia-lang

Yes you do need to supply a library name. The first argument to ccall is a tuple of the form (:function, "library"). So, if you were calling GetTickCount it would be (:GetTickCount, "kernel32"). You also need to specify the calling convention, return value type, and the parameter types. In the...

SetThreadExecutionState with ES_CONTINUOUS - what happens if app crashes before resetting flags

c++,winapi

Yes, the system will clear (or, more accurately, discard) the flags when the thread that set them no longer exists. It doesn't matter whether the thread exited cleanly or was terminated. NB: I can only confirm from my own experience that the flags will be ignored once the process has...

Implementing callback function for dialog-based application

c++,c,visual-studio,user-interface,winapi

So, I got it. The code created by the Visual Studio wizard indeed demonstrates correct implementation of the Windows API. Points to note: A dialog box procedure should not call DefWindowProc(). That's why the MessageBox is not working, as noted by Hans Passant in the comments. The purpose of the...

how to change Text to Speech voice and how to insert characters into char array

c++,arrays,windows,winapi,text-to-speech

StringCchPrintf is not working. That is because you ignored the warning in the documentation: Behavior is undefined if the strings pointed to by pszDest, pszFormat, or any argument strings overlap. You are specifying ptrData as both pszDest and an argument string, so your code has undefined behavior. You must...

call Win32 API in flex to set Window Display Affinity

winapi,flex,air

First you have to make sure that the main window does not have the WS_EX_LAYERED Windows style. That style makes SetWindowDisplayAffinity fails with code 8 (ERROR_NOT_ENOUGH_MEMORY), at least on my machine (Seven Pro 64 bits). In your -app.xml file, set the value to false for the node <transparent> under <initialWindow>....

Why/how does winapi reverse the order of messages?

c++,multithreading,winapi

PostMessage is thread safe, it is designed to forward messages to other threads. That means that the thread-unsafety you are experiencing lies in your code. In this case, you are opening a message box. The message box itself runs the message loop and so, if you set a break point...

Win32 API logic error: Code compiles fine but the main window doesn't show up

c++,winapi

I didn't see you assign a value to member variable cmdShow, so its default value is 0, which is SW_HIDE, so you should try the code below, see if the window can show up or assign cmdShow in WFrame initializer. void WFrame::show() { ShowWindow(this->hWnd, SW_SHOW); UpdateWindow(this->hWnd); } ...

How should I read the filename in FILE_NOTIFY_INFORMATION struct

c++,winapi,filesystems,file-monitoring,readdirectorychangesw

You have a number of problems that I can see immediately: According to the docs for the ReadDirectoryChangesW function, the buffer needs to be DWORD-aligned. As you are using a buffer on the stack this isn't guaranteed - you should allocate one from the heap instead. You don't seem to...

Play a sound file in masm32 and to stop the other sound file at the same time [closed]

winapi,assembly,x86,masm32,playsound

Read the documentation. PlaySound function pszSound A string that specifies the sound to play. The maximum length, including the null terminator, is 256 characters. If this parameter is NULL, any currently playing waveform sound is stopped. To stop a non-waveform sound, specify SND_PURGE in the fdwSound parameter. ... fdwSound Flags...

How To Get Window handles In Mozilla Firefox

winapi,mfc,ui-automation

Spy++ uses standard Windows API calls to inspect window hierarchies (EnumWindows, EnumChildWindows, etc.). If Spy++ doesn't show any native windows, then there aren't any native windows. Consequently, you cannot find any native windows either. Firefox uses what's called Windowless Controls. If you need to automate a GUI (which is likely...

How to associate data to a ListView item?

c#,.net,listview,winapi

You're looking for the Tag property, which can store an arbitrary object.

Same version number for different Windows versions

c,winapi

The GetVersionInfoEx API returns a fully populated OSVERSIONINFOEX structure (if requested). The documentation contains a complete table, alongside instructions on how to distinguish between OS versions with identical version numbers: The following table summarizes the values returned by supported versions of Windows. Use the information in the column labeled "Other"...

Issues trying to display a configuration window for my screensaver (from a GUI app running with high mandatory integrity level)

c++,c,windows,winapi,windows-shell

God damn Microsoft documentation (sorry, I just wasted the whole day today trying to fix it.) For whoever else runs into this -- it turns out one needs to call it as such: "C:\Windows\System32\mysvr.scr" /c:N where N is a window handle of the parent window expressed as an integer. Found...

Using System::AnsiString class

c++,winapi

Okay, so, it's not at all clear what AnsiString is; you've assumed it's the Embarcadero System::AnsiString class and, frankly, that looks like a reasonable assumption. I wouldn't go about trying to obtain it, though. I would focus on writing standard code, switching to std::string/std::wstring (as appropriate). It should be near-trivial...

physical screen size acquired by GetDeviceCaps is not the actual physical size of my screen

c++,winapi

As the comments indicate GetDeviceCaps(HORSZIE/VERTSIZE) is notoriously inaccurate. It's always been that way, and it will probably always be that way. There's nothing you can do about it, so you'll just have to pretend this API doesn't exist and move on. It won't help you find the real size of...

What is the correct way to get a LOCALE_SSHORTDATE that is guaranteed to have a full (4-digit) year number?

c,winapi,locale

No you can't rely on LOCALE_SSHORTDATE having a four-digit year, since the user is able to configure this through the Region control panel and options with two-digit years are available. If you want to enforce a four digit year (and override the user's preference) you may as well just provide...

Is it valid to mutilayered a critical section?

c++,winapi,critical-section

Whenever you have multiple locks and more than one lock may be held at one point in time, then you must make sure that the locks are always acquired in the same order. Failure to observe this can lead to deadlock. This is a widely known and widely discussed rule....

Explain what problems could have this function (if any)

.net,vb.net,winapi,pinvoke,getlasterror

From the documentation of GetLastError: The Return Value section of the documentation for each function that sets the last-error code notes the conditions under which the function sets the last-error code. Most functions that set the thread's last-error code set it when they fail. However, some functions also set the...

Specifying a Window Procedure for child Windows

c++,windows,winapi,wndproc,createwindowex

Your WndProc don't get WM_KEYDOWN messages because, if the user is typing inside the edit control, it means that it has the focus (not your window), so they are sent to the edit control window proc, not yours. But, the edit control window proc will send notifications to your WndProc...

Does LoadLibrary return NULL or an error code < 32 on failure?

winapi

In 32 and 64 bit Windows, LoadLibrary returns NULL on failure. In 16 bit Windows LoadLibrary returns a value less than 32 to indicate failure. KB142814 clearly dates from the 16 bit Windows days, and if you look closely you will see a kb16bitonly keyword. I think it is...

Obtain thread handles/id of a specific process

c++,multithreading,winapi

Instead of trying to forcefully suspend threads (which is likely to bring you trouble when you suspend in "not so lucky moment") you'd rather use a named CreateEvent() with manual reset. Named events are easily shared between processes. You simply CreateEvent() again with the same name. The typical name for...

How can I send data between 2 applications using SendMessage?

delphi,winapi

As noted in comments, you must use SendMessage with WM_COPYDATA. The primary reason for this is that the message sender is responsible for cleaning up the resources used for the transfer. As noted in the documentation : The receiving application should consider the data read-only. The lParam parameter is valid...

How to handle an event message while using chrome embedded framework (CEF)?

c++,winapi,visual-c++,chromium-embedded

see CefDoMessageLoopWork(), this is meant to be called from your own message loop. So you could implement your windows message loop and call this on idle. This is from the comment to cef_do_message_loop_work() which is what CefDoMessageLoopWork() calls and gives more information: // Perform a single iteration of CEF message...

PostThreadMessage Fails to “Cleanly” Close Application

vb.net,winapi

Your approach is fundamentally flawed, and while I understand that you're trying to learn how to do things, this is a rather advanced thing to do, and the comments in your code indicate that you don't understand enough of how Windows works to do these things. I'll start by picking...

How to run a dll as a service?

c++,c,winapi,dll,service

There's actually no inherent reason why you can't use rundll32.exe as the host executable, though use of rundll32 isn't recommended. (To expand on that: I gather you're trying to build a DLL service as an academic exercise, which is fine. In production, you should of course use an EXE, as...

How to create a submenu for a popup menu?

c,winapi

CreateMenu is for Window's horizontal menu bar. You can use CreatePopupMenu to make popup menu, as well as submenu for the popup: HMENU submenu = CreatePopupMenu(); AppendMenu(submenu, MF_STRING, 1001, L"submenu 1001"); HMENU mainmenu = CreatePopupMenu(); AppendMenu(mainmenu, MF_STRING, 100, L"main 100"); AppendMenu(mainmenu, MF_SEPARATOR, 0, NULL); AppendMenu(mainmenu, MF_STRING, 101, L"main 101"); AppendMenu(mainmenu,...