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...
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...
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...
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...
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...
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...
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...
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() 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...
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...
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...
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...
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"] =...
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...
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...
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...
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...
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;...
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...
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...
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...
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,...
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...
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...
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,...
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. ...
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...
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...
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...
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...
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,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...
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...
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...
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...
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,...
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...
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...
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...
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...
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...
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...
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...
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);....
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]))...
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...
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...
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....
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;...
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...
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";...
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...
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...
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...
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 );...
//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...
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."...
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...
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...
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...
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. ...
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;...
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 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...
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++,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...
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...
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...
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...
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...
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...
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...
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...
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...
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>....
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...
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); } ...
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...
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...
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...
You're looking for the Tag property, which can store an arbitrary object.
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"...
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...
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...
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...
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...
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....
.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...
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...
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...
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...
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...
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...
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...
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...
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,...