WinAPI | WinAPI functions for windows manipulation | Keyboard library
kandi X-RAY | WinAPI Summary
kandi X-RAY | WinAPI Summary
C# wrapper for WinAPI functions for windows manipulation, registry and mouse/keyboard events. Here’s a simple example.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of WinAPI
WinAPI Key Features
WinAPI Examples and Code Snippets
Community Discussions
Trending Discussions on WinAPI
QUESTION
My goal is to wrap Windows Thread API with my own struct.
Specifically, I want to use function_impl()
as a wrapper for function()
and have each instance of Thread
create a Windows thread with it's own function()
.
ANSWER
Answered 2021-Jun-14 at 19:28In C++, member functions are not regular functions. As you can see they always know which object they are working on through a specific this
pointer.
Win32 is a C API and it expects a regular function pointer. If you make your member function static
, then it's a regular function the C API can utilize. But in that case, how do you use non-static member variables from the object? The solution is to pass this
pointer as lpThreadParameter
to this static function and use it to access non-static member variables. Here is my implementation.
QUESTION
I read someone's code.
...ANSWER
Answered 2021-Jun-12 at 08:27The rules are simple: You include the header files you need. The documentation for any API call includes information on which header to include.
I don't know whether it is always an error to include both and . You would have to consult the documentation for every symbol used by the code to verify.
As noted, though, the Windows SDK header files aren't exclusively used by a C or C++ compiler. The Resource Compiler is another client of those header files. Including after is potentially not even superfluous in this case.
QUESTION
Having such a simple Win32 app:
...ANSWER
Answered 2021-Jun-11 at 14:27Reading documentation at https://docs.microsoft.com/en-us/windows/win32/winmsg/wm-quit:
The WM_QUIT message is not associated with a window and therefore will never be received through a window's window procedure. It is retrieved only by the GetMessage or PeekMessage functions.
Do not post the WM_QUIT message using the PostMessage function; use PostQuitMessage.
=== Portion after this was added after answer accepted for further clarification ===
As others have noted, there are sort of two things going on in the original code submitted. In the message map, there is a switch case entry for WM_QUIT. The documentation I quoted shows that the message is not for windows and so the case statement will never get processed.
However, there is another issue going on. Look at the message pumping:
QUESTION
In msdn,
...ANSWER
Answered 2021-Jun-11 at 02:01One benefit has been explained in the following Remarks.
Set the KEYEVENTF_SCANCODE flag to define keyboard input in terms of the scan code. This is useful to simulate a physical keystroke regardless of which keyboard is currently being used. The virtual key value of a key may alter depending on the current keyboard layout or what other keys were pressed, but the scan code will always be the same.
QUESTION
I am using JNA and writing some code to enumerate through all of the modules available in a process. I successfully obtain the snapshot handle via CreateToolhelp32Snapshot, however on my first Module32First call, I am getting error code 87 for "Invalid Parameter".
Below is the relevant code that I am using:
Code in question:
...ANSWER
Answered 2021-Jun-09 at 23:54Your mapping of a pointer as the second argument, while technically correct, requires you to do a lot more overhead with writing it. It is better to simply put the structure type as an argument. Structures are treated as .ByReference
when used as function/method arguments, and handle all of the auto-read and write for you. So if you do this, you can omit your write()
call:
QUESTION
When building a chain of WndProcs using SetWindowLongPtr
, we store the parent WndProc (the one that has less importance in the chain), so we are able to restore it and call it, like so:
ANSWER
Answered 2021-Jun-02 at 13:40We effectively set the proc, that was in place when first hooking, as the topmost WndProc. This means, that all WndProcs, that have been added after myWndProc (e.g. all kinds of Overlays), suddenly won't be called anymore. Furthermore all hooks that are added afterwards point to invalid memory with their oldProc.
This means, hooks done that way can't be properly unloaded without messing something up. While this would be fixable if all WndProcs belong to the same (our) codebase, this is not fixable with external code.
But you forget that hwnd
is your window, created by your process, so it is under your control. It means you must design your module to properly restore the chain of window procs. There is no "external code" that can set your window proc to something else.
The emphasis is on "your window."
EDIT
Putting back the WndProc
pointer will never affect the chain of window procedures. It is just that after putting it back, your procedure will not be called anymore, but the next one is called directly, which is exactly what you want.
QUESTION
So here is what is happening. I am using User32 to use the FindWindowA function, where my test case is Notepad (i.e. "Untitled - Notepad"). I then use several other functions like GetWindowInfo and GetWindowRect, and the values returned are strangely all 0. So here is what I do in Java:
...ANSWER
Answered 2021-Jun-02 at 01:46You are creating instances of your classes, and then manually calling getPointer()
on them to allocate native memory to give to the Win32 API to populate, but you are not read()
'ing that native memory back into your class members afterwards, which is why the members remain all zeros after the functions have exited.
Per the getPointer()
documentation:
Return a
Pointer
object to this structure. Note that if you use the structure's pointer as a function argument, you are responsible for callingwrite()
prior to the call andread()
after the call. These calls are normally handled automatically by theFunction
object when it encounters aStructure
argument or return value. The returned pointer may not have meaning forStructure.ByValue
structure representations.
For example:
QUESTION
I'm trying to use C++ to query registry values like the following
...ANSWER
Answered 2021-May-31 at 21:24I've figured out how to query the registry now, although i'm still not printing values succesfully. There were many different issues with the original code.
To query the registry i first had to use RegOpenKeyEx
and then query the values individually with RegEnumValue
, finally close the key handle with RegCloseKey
.
There was another issue with the RRF_RT_ANY
type values, explained more RegOpenKeyEx returning error code 2
I'm not printing the values correctly yet but when running the while loop for RegEnumValue
it iterates n
times for registry values with n
keys so i'm fairly confident that should be working correctly.
QUESTION
I need help in solving a problem, as I simply do not have enough experience. I created a simple winodws in Visual Studio 2019 and it works well, but I need to compile it as a dll library so that a third-party application can call a function from this library and the window is drawn.
I don't plan any interaction with the application that called this function from the dll yet - I just want to show a window.
The actual code for the exe file is quite simple:
...ANSWER
Answered 2021-May-26 at 08:49In Visual Studio, then change Project-> Properties-> Configuration Properties-> General-> Configuration Type from Application (.exe)
to Dynamic Library (.dll)
(Don't forget to choose the corresponding platform, your project is x64.)
QUESTION
I have a WinForms app written for the classical .NET Framework (namely v4.7.2). I need to process the mouse back and forward buttons in one of the forms. The problem is that the form is fully covered by other controls like SplitContainer and Panels, and I could not find a way to intercept the required buttons using standard native .NET techniques.
For example, a solution with overriding WndProc
...ANSWER
Answered 2021-May-26 at 05:19A solution based on IMessageFilter does the work:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install WinAPI
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page