How are ChildWindowFromPointEx and ChildWindowFromPoint different except the "flags" parameter? - windows

Windows API has ChildWindowFromPoint() and ChildWindowFromPointEx() functions and they differ in that the latter has uFlags parameter specifying which windows to skip.
It looks like if I pass CWP_ALL into ChildWindowFromPointEx() I'll get exactly the same effect as I would have with ChildWindowFromPoint().
Is the only difference in uFlags parameter? Can I just use ChildWindowFromPointEx() everywhere and pass CWP_ALL when I need ChildWindowFromPoint() behavior?

If it helps at all, I hacked up a quick test application that calls both functions and stepped into the disassembled USER32.DLL to see where the calls go.
For ChildWindowFromPoint, after some preamble, I reached this point:
The main processing was delegated to the call at 75612495.
Then, for ChildWindowFromPointEx, I step into the assembly and get this:
As that entry point is the target of the call from the first function, it seems pretty clear to me that ChildWindowFromPoint calls ChildWindowFromPointEx, presumably with uFlags set to CWP_ALL (my assembler knowledge is limited but I'm looking hard at that push 0 before the call - CWP_ALL is defined as zero).

If you intent to always use ChildWindowFromPointEx with CWP_ALL, you could just use ChildWindowFromPoint().
If you intent to always use ChildWindowFromPoint, you could just use ChildWindowFromPointEx with CWP_ALL.
ChildWindowFromPoint is equivalent to ChildWindowFromPointEx with CWP_ALL.
Advice: use ChildWindowFromPointEx (you may one day have usage for other flags value)

Related

Why does the first parameter of the function LdrRegisterDllNotification have to be zero?

As stated in the Microsoft docs, the parameter Flags of the LdrRegisterDllNotification must be zero, but no further explanation is provided. What's the purpose of defining this parameter at all if the only accepted value is zero? What happens if a non-zero value is passed instead?
Parameters where the documentation tells you to pass zero has two possible reasons:
The parameter is unused in all existing Windows versions but might be used for something in the future. The developer might have envisioned extra features but they did not have time to implement them etc.
The parameter is used to pass undocumented information/flags that triggers some private functionality inside the function. Windows 95 for example supports undocumented flags in its *Alloc functions that causes them to allocate shared memory visible to all processes.
Either way, the best practice is to just follow the documentation and pass zero.

Using std::move, and preventing further use of the data

I have been using c++11 for some time but I always avoided using std::move because I was scared that, while reading a library where the user does not have the access to the code, it would try to use the variable after I move it.
So basically something like
void loadData(std::string&& path);
Would not be enough to make the user understand that it will be moved.
Is it expected that the use of && would imply that the data will be moved. I know that comments can be used to explain the use case, but a lot of people dont pay attention to that.
Is it safe to assume that when you see a && the data will be moved, or when should I use std::move and how to make it explicit from the signature.
Is it expected that the use of && would imply that the data will be moved.
Generally speaking yes. A user cannot call loadData with an lvalue. They must provide a prvalue or an xvalue. So if you have a variable to pass, your code would generally look like loadData(std::move(variable)), which is a pretty good indicator of what you're doing from your side. forwarding could also be employed, but you'd still see it at the call site.
Indeed, generally speaking it is extremely rude to move from a parameter which is not an rvalue reference.

Usefulness of explicit Isolate parameter in V8 API

Some time in the past year, many functions in the V8 API were changed to have an explicit Isolate parameter. E.g. whereas you used to write ObjectTemplate::New(), now you must pass in an Isolate argument: ObjectTemplate::New(Isolate::GetCurrent()).
Is there any reason you would ever pass an isolate other than the one returned from GetCurrent()? If you were to do so, would that even work?
The reason I ask is that I'm writing bindings to use V8 for another programming language. If the Isolate parameter is always the current isolate, I might as well omit that parameter and hardcode the call to GetCurrent in the glue layer.

How to programmatically inject parameters/instructions into a pre-built portable executable

I have two executables, both manually created by me, I shall call them 1.exe and 2.exe respectively. First of all, both the executables are compiled by MSVS 2010, using the Microsoft compiler. I want to type a message into 1.exe, and I want 1.exe to inject that message into 2.exe (possibly as some sort of parameter), so when I run 2.exe after 1.exe has injected the message, 2.exe will display that message.
NOTE - this is not for illicit use, both these executables were created by me.
The big thing for me is:
Where to place the message/instructions in 2.exe so they can be easily accessed by 2.exe
How will 2.exe actually FIND use these parameters (message).
I fully understand that I can't simply use C++ code as injection, it must be naked assembly which can be generated/translated by the compiler at runtime (correct me if I am wrong)
Some solutions I have been thinking of:
Create a standard function in 2.exe requiring parameters (eg displaying the messagebox), and simply inject these parameters (the message) into the function?
Make some sort of structure in 2.exe to hold the values that 1.exe will inject, if so how? Will I need to hardcode the offset at which to put these parameters into?
Note- I don't expect a spoonfeed, I want to understand this aspect of programming proficiently, I have read up the PE file format and have solid understanding of assembly (MASM assembler syntax), and am keen to learn alot more. Thank you for your time.
Very few programmers ever need to do this sort of thing. You could go your entire career without it. I last did it in about 1983.
If I remember correctly, I had 2.exe include an assembler module with something like this (I've forgotten the syntax):
.GLOBAL TARGET
TARGET DB 200h ; Reserve 512 bytes
1.exe would then open 2.exe, search the symbol table for the global symbol "TARGET", figure out where that was within the file, write the 512 bytes it wanted to, and save the file. This was for a licensing scheme.
The comment from https://stackoverflow.com/users/422797/igor-skochinsky reminded me that I did not use the symbol table on that occasion. That was a different OS. In this case, I did scan for a string.
From your description it sounds like passing a value on the command line is all you need.
The Win32 GetCommandLine() function will give you ther passed value that you can pass to MessageBox().
If it needs to be another running instance then another form of IPC like windows messages (WM_COPYDATA) will work.

GCC syntax check ensure NULL passed as last parameter in function call with variable arguments

I want to do something similar to how, in GCC, you can do syntax checking on printf-style calls (to make sure that the argument list is actually correct for the call).
I have some functions that take a variable number of parameters. Rather than enforce what parameters are sent, I need to ensure that the last parameter passed is a NULL, regardless of how many parameters are passed-in.
Is there a way to get GCC to do this type of syntax check during compile time?
You probably want the sentinel function attribute, so declare your function like
void foo(int,double,...) __attribute__((sentinel));
You might consider customizing your GCC with a plugin or a MELT extension to typecheck more precisely your variadic functions. That is, you could extend GCC with your own attributes which would do more precise checks (or simply make additional checks based on the names of your functions).
The ex06/ example of melt-examples is doing a similar check for the jansson library; unfortunately that example is incomplete today October 18th 2012, I am still working on it.
In addition, you could define a variadic macro to call such a function by always adding a NULL e.g. something like:
#define FOO(N,D,...) foo((N),(D),##__V_ARGS__,NULL)
Then by coding FOO(i+3,3.14,"a") you'll get foo((i+3),(3.14),"a",NULL) so you are sure that a NULL is appended.
Basile Starynkevitch is right, go with a function attribute. There are a ton of other useful function attributes, like being able to tell the compiler "If the caller doesn't check the return value of this function, it's an error."
You may also want to see if splint can check for you, but I don't think so. I think it would have stuck in my memory.
If you haven't read over this page of GCC compiler flags, do that, too. There are a ton of handy checks in there. http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html

Resources