int VK_F_DOWN = GetVirtualKey('F', 0);
int VK_F_UP = GetVirtualKey('F', 1);
HWND hWnd = FindWindow(NULL,L"Calculator.exe");
SendMessage(hWnd, WM_KEYDOWN, toascii('F'), VK_F_DOWN);
SendMessage(hWnd, WM_KEYUP, toascii('F'), VK_F_UP);
It doesn't work on the Calculator.exe,however it can work on my visual studio when I change hWnd to HWND(0xFFFF).
And I also already got a non-zero hWnd. What am I missing here? Like authority or something?
Sounds like User Interface Privilege Isolation. As the Wikipedia article explains, you can request the access you want in your application manifest.
That said, you should be using SendInput rather than SendMessage. See one of Raymond Chen's blog entries on that point.
Related
Helo!
This is one another self answered question by me. I hope you get a little help.
So.. This is one permission error about the sdk23 or higher sdk devices. 'Cause the permission accepts are changed! Not the all permissions are can accepted at the installation moment. This change says that:
The user have the choice to accept or deny one permission while the app is running.Here are the automaticaly granted permissions:
android.permission.ACCESS_LOCATION_EXTRA_COMMANDS
android.permission.ACCESS_NETWORK_STATE
android.permission.ACCESS_NOTIFICATION_POLICY
android.permission.ACCESS_WIFI_STATE
android.permission.ACCESS_WIMAX_STATE
android.permission.BLUETOOTH
android.permission.BLUETOOTH_ADMIN
android.permission.BROADCAST_STICKY
android.permission.CHANGE_NETWORK_STATE
android.permission.CHANGE_WIFI_MULTICAST_STATE
android.permission.CHANGE_WIFI_STATE
android.permission.CHANGE_WIMAX_STATE
android.permission.DISABLE_KEYGUARD
android.permission.EXPAND_STATUS_BAR
android.permission.FLASHLIGHT
android.permission.GET_ACCOUNTS
android.permission.GET_PACKAGE_SIZE
android.permission.INTERNET
android.permission.KILL_BACKGROUND_PROCESSES
android.permission.MODIFY_AUDIO_SETTINGS
android.permission.NFC
android.permission.READ_SYNC_SETTINGS
android.permission.READ_SYNC_STATS
android.permission.RECEIVE_BOOT_COMPLETED
android.permission.REORDER_TASKS
android.permission.REQUEST_INSTALL_PACKAGES
android.permission.SET_TIME_ZONE
android.permission.SET_WALLPAPER
android.permission.SET_WALLPAPER_HINTS
android.permission.SUBSCRIBED_FEEDS_READ
android.permission.TRANSMIT_IR
android.permission.USE_FINGERPRINT
android.permission.VIBRATE
android.permission.WAKE_LOCK
android.permission.WRITE_SYNC_SETTINGS
com.android.alarm.permission.SET_ALARM
com.android.launcher.permission.INSTALL_SHORTCUT
com.android.launcher.permission.UNINSTALL_SHORTCUT
So we don't have any other things to do just ask the user what he wanna do.. This is the fund set up. Let's get coding. The code in the answer section! But do not forget to write permissions in the Manifest too for the older android sdk-s!!!
So here is the code:
create new int whith dont exist value. Examp: if you have one int with value 1, this int couldn't be 1.. Then this int will be something else.
int YOUR_PERMISSION_REQUEST = 1212;
&& In the onCreate method
//If the sdk level equals or higher than 23.
if (Build.VERSION.SDK_INT >= 23){
//The permission we wanna accept
int hasWriteContactsPermission = checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE);
//If is not accepted for this app ask the user he wanna accept it or not.
if (hasWriteContactsPermission != PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[] {Manifest.permission.READ_EXTERNAL_STORAGE},
YOUR_PERMISSION_REQUEST);
}
So you can asks the users to accept one permission. If you wanna ask about other permission you change the READ_EXTERNAL_STORAGE permissions in the code to your permission. Good Luck. Hope I can help you.
The Reference Source page for stringbuilder.cs has this comment in the ToString method:
if (chunk.m_ChunkLength > 0)
{
// Copy these into local variables so that they
// are stable even in the presence of ----s (hackers might do this)
char[] sourceArray = chunk.m_ChunkChars;
int chunkOffset = chunk.m_ChunkOffset;
int chunkLength = chunk.m_ChunkLength;
What does this mean? Is ----s something a malicious user might insert into a string to be formatted?
The source code for the published Reference Source is pushed through a filter that removes objectionable content from the source. Verboten words are one, Microsoft programmers use profanity in their comments. So are the names of devs, Microsoft wants to hide their identity. Such a word or name is substituted by dashes.
In this case you can tell what used to be there from the CoreCLR, the open-sourced version of the .NET Framework. It is a verboten word:
// Copy these into local variables so that they are stable even in the presence of race conditions
Which was hand-edited from the original that you looked at before being submitted to Github, Microsoft also doesn't want to accuse their customers of being hackers, it originally said races, thus turning into ----s :)
In the CoreCLR repository you have a fuller quote:
Copy these into local variables so that they are stable even in the presence of race conditions
Github
Basically: it's a threading consideration.
In addition to the great answer by #Jeroen, this is more than just a threading consideration. It's to prevent someone from intentionally creating a race condition and causing a buffer overflow in that manner. Later in the code, the length of that local variable is checked. If the code were to check the length of the accessible variable instead, it could have changed on a different thread between the time length was checked and wstrcpy was called:
// Check that we will not overrun our boundaries.
if ((uint)(chunkLength + chunkOffset) <= ret.Length && (uint)chunkLength <= (uint)sourceArray.Length)
{
///
/// imagine that another thread has changed the chunk.m_ChunkChars array here!
/// we're now in big trouble, our attempt to prevent a buffer overflow has been thawrted!
/// oh wait, we're ok, because we're using a local variable that the other thread can't access anyway.
fixed (char* sourcePtr = sourceArray)
string.wstrcpy(destinationPtr + chunkOffset, sourcePtr, chunkLength);
}
else
{
throw new ArgumentOutOfRangeException("chunkLength", Environment.GetResourceString("ArgumentOutOfRange_Index"));
}
}
chunk = chunk.m_ChunkPrevious;
} while (chunk != null);
Really interesting question though.
Don't think that this is the case - the code in question copies to local variables to prevent bad things happening if the string builder instance is mutated on another thread.
I think the ---- may relate to a four letter swear word...
I'm looking for some code where 'How to create & code a function which is used ONLY once - EVER! .... at first Start Up of AIR App.??? this I need to download the first set v1.0 of Xml base data files in an AIR Application and after that this particular function should never EVER be addressed again!
Any help would be appreciated regards aktell
a) write a function on init or CreationComplete event.
b) write an object extending objectproxy, introduce a flag, and allow it to use only if the flag is default, and then set the flag to other value.
c) write a static function with a static counter, and when you call it, check if counter != 0, to return, and counter++;
I think you have to use "SharedObject" in this case, so you can set a flag.
On each run the flag will be checked, if true or false you can trigger a function to execute.
Flex Mobile Development: storing data locally
you also can encrypt the stored data
Flex Mobile Development – Encrypting Data
Hope this will workout for you...
Sure you can, use the PersistenceManager to store a flag after first time run ,
for more info about PersistenceManager http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/spark/managers/PersistenceManager.html
I am trying to use MSFT HTML Help to provide Help System for one of our applications.
I encounter a problem and couldn't find any clue in any documentation. I believe it's a simple problem with easy solution, just need to know it:).
HTML Help keyword file allow users to create multiple level of keywords. After opening the Help Window and enter the "Index" tab, there is a "Type in the keyword to find:" area where user can input keywords, all available keywords are also showed below. While typing, the correct hit keyword will be scrolled into the window and highlighted.
The problem is second level keyword is not scrolled and high lighted correctly. After typing the first level keyword and finding the keyword, then next no matter pressing what key the second level keyword cannot be highlighted correctly. As an result, the topic relating to the second key cannot be displayed correctly.
Anyone know what is the separator key between the different level of keywords to use to continue to search in next level of keyword? This problem also happens using HTML Help API, where an F1 key should find the second level keyword but actually could not.
For example, I have the following keywords:
key1
key2
x_subkey_of_key2
y_subkey_of_key2
z_subkey_of_key2
key3
key4
After typing key2 and hilights key2, then no matter which key I press, it cannot highlight y_subkey_of_key2. Many key will high lights z_subkey_of_key2 which is the last subkey of key2.
Any ideas?
Thanks a lot.
Ahaa!!! After one hours' typing and trying, I figured out that TWO SPACES are needed between the first level keyword and second level keyword, and an Enter key is needed at last to show the topic linked from the second keyword!!!!
Remember, exactly two spaces! one or three does not work. The trick is, while typing the second space and second keyword, some other keyword get highlighted in the list of keywords, which can make you think you have already made a mistake and would not continue to finish typing the second keyword! Is this a hoax by Microsoft engineer?
However, although manually it works, seems the software API does not work immediately with the TWO spaces. If I call the following API in C# upon F1 key pressed:
System.Windows.Forms.Help.ShowHelp(this, "file:///C:/apps/MyHelpContentNew/QACT.chm",
System.Windows.Forms.HelpNavigator.KeywordIndex, "key2 x_subkey_of_key2");
it does not show the topic linked from x_subkey_of_key2. But it's almost there, the Help Window shows up with correct two levels' keywords put in the search TextBox, only missing a "Car-Return"!
Then I tried to add the car-return like this:
System.Windows.Forms.Help.ShowHelp(this, "file:///C:/apps/MyHelpContentNew/QACT.chm",
System.Windows.Forms.HelpNavigator.KeywordIndex, "key2 x_subkey_of_key2\n");
It doesn't work either. So I guess I need send a car-return key to the Help Window programmingly. Will post if I once I implement it.
Now I made it work also in the program in handling F1 key. Upon handling F1 key, I called this API to launch the Help Window and populate the keyword textbox with two levels keywords separated with two spaces:
{
System.Windows.Forms.Help.ShowHelp(this, "file:///C:/apps/MyHelpContentNew/QACT.chm",
System.Windows.Forms.HelpNavigator.KeywordIndex, "key2 x_subkey_of_key2");
}
Then, I need send a "ENTER" key to that Help Window. I read some MSDN doc and figured out the following ways to send the "ENTER" key to that window:
First we need call Win32 function EnumChildWindows() to lookup all open windows. The Win32 function will callback to C# for processing of each open window. So when calling the Win32 function, we need pass a C# function as callback. This C# function is defined as a Delegate and inside it we can filter out the HTML Help Window and send "ENTER" key to it. The HTML Help Window is usually called Your-App-Name+Help. For example, if you application is named "XYZ", then the HTML Help window launched by ShowHelp() is called "XYZ Help". Here is the code:
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
class YourClass {
[DllImport("user32.dll")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
// declare the delegate
public delegate bool WindowEnumDelegate(IntPtr hwnd,
int lParam);
// declare the API function to enumerate child windows
[DllImport("user32.dll")]
public static extern int EnumChildWindows(IntPtr hwnd,
WindowEnumDelegate del,
int lParam);
// declare the GetWindowText API function
[DllImport("user32.dll")]
public static extern int GetWindowText(IntPtr hwnd,
StringBuilder bld, int size);
//define your callback function:
public static bool WindowEnumProc(IntPtr hwnd, int lParam)
{
// get the text from the window
StringBuilder bld = new StringBuilder(256);
GetWindowText(hwnd, bld, 256);
string text = bld.ToString();
if (text.Length > 0 )
{
if (text == "XYZ Help")
{
//IntPtr h = p.MainWindowHandle;
SetForegroundWindow(hwnd);
SendKeys.Send("{ENTER}");
}
}
return true;
}
//In your F1 key handler, after launch the Help Window by calling ShowHelp(), instantiate the //callback function delegate and invoke the EnumChildWindows():
private void GenericTreeView_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.F1)
{
System.Windows.Forms.Help.ShowHelp(this, "file:///C:/apps/MyHelpContentNew/QACT.chm",
System.Windows.Forms.HelpNavigator.KeywordIndex, "key2 x_subkey_of_key2");
// instantiate the delegate
WindowEnumDelegate del
= new WindowEnumDelegate(WindowEnumProc);
// call the win32 function
EnumChildWindows(IntPtr.Zero, del, 0);
}
}
}
Voila!
You will see that upon pressing F1 key, the Help Window nicely opens the correct HTML file and slides to the anchor that is pointed to by the two level keywords!
BTW, I found putting the index inside the HTML file does not help (even if I enable the option of using keyword inside HTML file). I have to put the keyword in the keyword file explicitly.
Enjoy!
Would it be possible to see the CallStack in VBA for MS Access 2003? That is to say, would it be possible to see from what procedure or function another function was called?
At runtime, View menu -> Call Stack (or press CTRL + L).
There is no programmatic way in VBA to view the call stack that I know of. The usual solution to this problem is to use some structure to track calling of functions, but it always seems like a kludge to me, and really of use only when programming (not at runtime), in which case it seems to me that the VBE's built-in capability for seeing the call stack is sufficient.
And, BTW, I always put the call stack button on my VBE toolbar, since it's one of the most frequently used functions for me. I also add the compile button -- I think it's crazy that it's not on the toolbar by default because it encourages people to code without ever forcing a compile. Then again, Access 2000 didn't even use Option Explicit by default (supposedly for consistency with the other apps using the VBE -- in other words, dumb down Access in order to make it consistent with apps that aren't nearly as code-heavy).
But I digress...
Eventually, add an optional parameter to your function, and pass the caller name that way. For forms, you can use Me.Name as the parameter.
Yes it's possible, BUT it's not quite usefull!
Private Declare Sub SetMode Lib "vba332.dll" Alias "EbSetMode" (ByVal lngMode As Long)
Private Declare Function GetCallStackCount Lib "vba332.dll" Alias "EbGetCallstackCount" (lngCount As Long) As Long
Private Declare Function GetCallStackFunction Lib "vba332.dll" Alias "EbGetCallstackFunction" (ByVal Lvl As Long, ByRef strBase As String, ByRef strModule As String, ByRef strFunction As String, ByRef Done As Long) As Long
Before use GetCallStackCount and GetCallStackFunction call SetMode(2), and after SetMode(1).