How can I determine the arguments for a private API function? - macos

I want to create a replacement for the app switcher (aka 'cmd + tab').
I know that it's possible because Lite Switch X does it.
What I've got achieved so far:
By force quitting the dock and calling CPSRegisterForKey() (which is a private API function) I can prevent the default cmd+tab from working.
The second step is two register the hot key for my app. The standard way of doing this, RegisterEventHotKey(), doesn't work. A bit of googling and GDBing suggests that the Dock and Lite Switch X use CGSSetHotKeyEnabled() and CGSSetHotKey() (both of these are private API functions). The problem I have is that I do not know what arguments these functions take.
How can I determine the arguments for a private API function?
Update:
I've got a little further with CGSSetHotKey():
OSErr setupResult = CGSSetHotKey(_CGSDefaultConnection(), unknownArg, unknownArg, unknownArg, kCGEventFlagMaskCommand, ???, ???, ...);

Have you tried using class-dump? It's usually pretty helpful.

Related

GTK Obtain "external app" GtkClipboard "owner" (Windows)

Have created a Gtk based app. It can Cut/Copy/Paste (CCP) "internally" and across to/from other apps via the GtkClipboard.
One concern arise when CCP'ing from an another app into ours, say from Excel or Firefox, into ours. Out Gtk code can determine the full list of available "formats" (i.e. Atoms/Targets) that each external app is capable for providing.
That list, of course, depends on the "owner app" (i.e. where the CCP originated).
Unfortunately, we can't find a way to determine the actual "owner app" that send/owns the CCP'd material. For example, we can't figure out if it came from Excel of Firefox (of course one can analyse the last of Atoms/Targets and have a "guess" (e.g. if the Atoms/Targets include BIFF's, its probably from a spreadsheet etc.
What is actually required is a direct and explicit way to obtain the "owner app". That is, if the CCP came from "Excel", then we should be able to (hopeful) use some Gtk strategy to extract that information.
It appears to be possible with pyGkt, and possibly only on X, such seen on this page (http://commonsmachinery.se/2013/07/copy-paste-linux/) where the clipboard owner returns the "app" (e.g. Firefox, etc).
Is that also possible with standard Gtk+? We note:
1) the following:
gtk_clipboard_get_owner (GtkClipboard *clipboard);
is not of much help, if we understood it correctly, since it returns only "owners" that are actually set explicitly within Gtk (e.g. by
gtk_clipboard_set_text (GtkClipboard *clipboard, const gchar *text, gint len);
etc.
Yes, we have tested the code, it doesn't work (or at least not in the sense we would like it). Have tried many variations directly with the different types of callbacks (since different callbacks provide different data). For example "owner-change" provide GtkSelectionData, but the "owner" component of that is just the Atom/Target of the owner ... and so on, and so forth, with many permutations/combinations (e.g. request_content(), request_target(), etc etc, each with their specific callbacks).
So is it possible in standard Gtk, and on Windows, to determine the explicit name of the "ownder" of the selection on the clipboard, or is it only available, say, on pyGtk on X etc ... we fear we may have missed something all too simple?
Please advise.
OK, we think we have arrived at "one answer", though it is not very satisfactory (but it may be as good as it gets).
CAVEAT: we are "end users/math geeks", not "developers/IT geeks", and would invite Gtk and WinAPI "Gods" to comment/verify.
The "answer":
1) Taking together our research prior to posting, andlabs comments above, and more research since ... we believe that Gtk CANNOT actually determine the App from which the current clipboard's content originate.
2) That looks fairly likely the case on Windows, and it seems that perhaps even on Linux, Gtk does not have such means.
We corresponded with Jonas (the author of this page (http://commonsmachinery.se/2013/07/copy-paste-linux/) cited above) where it seemed that Gtk (at least pyGtk) did manage this. In fact, it did not. Jonas wrote to us with:
"this isn't a feature of neither pyGtk or anything other Gtk. It's merely making use of the Xlib method get_wm_name(). Whether Windows has something similar in its equivalent of Xlib, I'm afraid that we do not know."
3) Accepting that Gtk can't do it, we took andlabs indication and Jonas' comments that we would need to look to the WinAPI for our solution. We did the following:
a) Create a standard GtkClipboard signal for "owner-change".
b) In the callback function for that signal we inserted (first creating the appropriate "interface blocks" to the WinAPI function) a couple of WinAPI functions, namely of the form:
OwnerHandle = GetClipboardOwner() ! GetClipboardOwner() is the WinAPI for the "Windows HANDLE" of the current clipboard ownder
We could not find a WinAPI that returned the "app" that owns the current clipboard. The best we could find is a WinAPI that returns the "Title" of the Window from which the "bits" were Cut/Copy'd, which is the function GetWindowText().
Unfortunately, the OwnerHandle could be the Handle of a "child window" in the owner app, as we discovered from the comments of Syed Waqas at this SO posting (Get Clipboard owners Title/Caption). So, we wrote a loop that checked if the "current owner Handle" is a child, by implementing the WinAPI GetParent(), creating code that roughly looks like this (we have aliased the WinAPI routines to have local names that begin with "w32_" etc., and this example omits the overloading of both ANSI and UNICODE, showing only the ANSI variant) :
!
w32_GetClipboardOwner_Test = w32_GetClipboardOwner()
w32_GetClipboardOwner_cInt = w32_GetClipboardOwner_Test
!
Do While ( w32_GetClipboardOwner_Test > 0_c_IntPtr_t )
!
w32_GetClipboardOwner_Test = w32_GetParent(w32_GetClipboardOwner_Test)
!
! the "If" portion of the next line may be pedantic
! with some compilers/languages,
If( w32_GetClipboardOwner_Test > 0_c_IntPtr_t ) w32_GetClipboardOwner_cInt = w32_GetClipboardOwner_Test
!
End Do
!
! Get length of text in buffer, ir there is a valid Handle
!
If( w32_GetClipboardOwner_cInt > 0_c_IntPtr_t ) Then
w32_GetWindowText_nAct_cInt = w32_GetWindowTextLengthA(w32_GetClipboardOwner_cInt)
End If
!
! get the text (window title) and put in the buffer implied by lpString
!
w32_GetWindowText_nAct_cInt = w32_GetWindowTextA(hWnd = w32_GetClipboardOwner_cInt, &
lpString = w32_GetWindowText_Str_cPtr, &
nMaxCount = w32_GetWindowText_nMax_cInt)
, where the type c_IntPtr_t has been stated to form an "equivalent" to the Windows HANDLE "pointer/entity", at least for these purposes (yes, we know it's more complicated compared to traditional pointer, but likely not an issue here, as suggested by other sources).
Unfortunately, and as indicated by Syed Waqas, even with this extra care, there is no guarantee that the owner can be identified, since it is possible for apps to own data on the clipboard without having a "connection" to their "Window Title".
Bizarrely, none of the "big name apps" actually worked in this process (e.g. Excel, Word, FireFox, etc.), whereas many "no name" apps at least return the "app.exe" or "something".
We also discovered that MS Office also has the OfficeClipboard, and the OLEClipboard, which "attaches itself" to the "standard" clipboard somehow. We don't know how that works, and could use some much appreciated help.
Of course, we were looking the get the "owner app" (not some window title), but this is as far as we got toward "a not so satisfactory solution".
This is rather unsatisfactory for us, since for example, once there has been a Cut/Copy, the Paste step has many possibilities based on all the formats (Atoms/Targets) the clipboard data can be converted to. While we have written a "Paste Special" routine to list all the Targets, so the user can choose the format of the Paste, we were looking to be able to provide a "default" choice, but which (of course) would depend on the owner App (e.g. the default for Excel CCP might be BIFF8 or XML etc, while for Notepad, UTF8 etc.)
The Excel connection is a bit more important for our specific Gtk app, since it too has spreadsheet component, and would like to be able to CCP between Excel and our Gtk spreadsheet in a sensible manner.
ASIDE: A question for the SO moderators. As this issue has now morphed from a GtkClipboard matter to a WinAPI/OLE etc matter, should we post a new question purely in the WinAPI context, and with the new issues?

Can someone show a known good working function in Xojo 2014?

So.. I just downloaded Xojo 2014 for OS X, and up to this point have found it a pretty simple and effective development environment.
However, I've been trying to make a function or sub routine for 45 minutes. Every time I try following tutorials or the Xojo documentation I get the following error:
I've followed (even though I could be missing something) the directions here: http://docs.xojo.com/index.php/Function
Even though there is no full example in the documentation (bad development environment).
Also, in the screen shot is showing a sample function I copied and pasted off Xojo forums and is supposed to work. I'm not a programming newb per say, but more an Xojo newb. I've also had experiences with silly bugs in RealStudio in the past.
Can someone maybe point out what I could be missing?
You cannot use the Function, Sub, End Function, or End Sub lines in the method editor. Doing so will cause a syntax error because method declarations are automatically added by the IDE based on the values you enter into the method editor's name, parameters, and return type fields.
e.g.
as said,
Function, Sub, End Function, or End Sub is done for you,
you can do 'exit sub' if nothing need to be returned, else just return a proper value
like some events need a true or false, so if you need the exit the function, just return false
You cannot add inline functions within your Xojo code. You add methods to your project items these ways:
Insert->Method
"+" button on editor toolbar, then Method
Insert button on main toolbar, then Method
Option-Command-M (on OS X)

CBService/CBCharacteristic UUIDString returns nil

I have an iOS app that generates a new UUID when it's going to talk for the first time with my OSX app, which is then stored, this way I can have different characteristics identifiers for different devices.
After calling
peripheral.discoverCharacteristics([], forService: service as CBService)
in the "didDiscoverServices" method in the OSX app, in "didDiscoverCharacteristicsForService" I do this to try to find out what the new device's UUID is, so that I check if they've talked before, if not, I will store it:
for characteristic in service.characteristics {
println("\(characteristic.UUIDString)")
}
The problem is that it prints nil, if I use characteristic.UUID instead, it gives me "Unknown (<46c35c38 c4994106 b6d351c9 8d900368>)" which is not the format I want to deal with.
Any idea why?
Another thing I've noticed is that, after testing what I've explained repeatedly with LightBlue to see what my app is advertising, sometimes certain services/characteristics seem to get stuck and just won't go away, I've even had to restore my phone to get rid of them once. Is this normal?
Thanks a lot
It seems that the documentation for CBUUID is incorrect. Although it references the UUIDString method, as you pointed out in your comments this gives an unrecognised selector exception.
I tried both Swift and Objective C code.
The CBUUID that is returned from a CBMutableCharacteristic does respond to the UUIDString selector, but obviously you don't get CBMutableCharacteristics from the discovery process.
As a design note, your approach probably isn't the most efficient. It would probably be better to have a known characteristic that contains an identifier (such as identifierForVendor) and then you can use the contents of the characteristic itself rather than the identifier of the characteristic to determine if this is a new device or not.
This way you can send the list of desired characteristics to discoverCharacteristics and write more "defined" code, rather than having to assume that the "unknown" characteristic is the identifier.

Load a Windows predefined icon with wxIcon

I'm trying to use IDI_INFORMATION with wxWidgets 2.8.11 (from wx/version.h) (for wxMemoryDC::DrawIcon). But first I have to load the icon: wxICON(IDI_INFORMATION) fails, LoadFile(wxT("IDI_INFORMATION")) also fails ( but LoadFile(IDI_INFORMATION) compiles and crashes, IDI_INFORMATION is a fake string pointer too tricky for wxWidgets). Hmmm, then I add some ifdefs to use Windows API: ::LoadIcon(NULL, IDI_INFORMATION) works, then wxIcon::SetHICON. While DrawIcon apparently works, the nasty surprise is that wxIcon::GetWidth, wxIcon::GetHeight return 0. Hmmm, let's get the size and use wxIcon::SetSize. Now it is finally done... wait!, but who's gonna destroy my icon? Not sure, so add the ifdef, SetHICON(NULL) and DestroyIcon.
The small question: do I have to destroy the icon myself?
The big question: is wxIcon entirely useless in this case?
PS After some debugging I discover that LoadFile(wxT("wxICON_INFORMATION")) works, wow!, but is it really multi-platform? Do I have read all the wx sources for drawing a standard icon?
The cross-platform solution is provided by wxArtProvider, just use its GetIcon() method with wxART_INFORMATION argument.

Does anyone know what parameters to pass to dwmapi.dll ordinal #113?

Does anyone know what parameters to pass to dwmapi.dll ordinal #113? (Windows 7)
I'm trying to incorporate this method into an application that I'm writing. From what I can tell, this method is responsible for doing the Aero peek thing for windows. If I pass no params to the method it will show the desktop and outlines of all open, non-maximized windows. Nothing happens when I try passing parameters - which I've done using trial and error.. mostly error.
Any help would be greatly appreciated.
Don't do it. It's undocumented for a reason and is subject to change and/or removal at any time. Given that Windows 7 hasn't been release yet you won't even be able to guarantee that it'll be there in the final version.
Your tags are inconsistent. An API is an application programming interface. Ordinal #113 is undocumented because it's not part of the interfaces for applications. It is likely present because the OS needs it itself, or because the current RC hasn't finished removing it, etc.
Well, I've used to mimic Alt-Tab with AeroPeek feature.
using System.Runtime.InteropServices;
...
[DllImport("dwmapi.dll", EntryPoint = "#113", SetLastError = true)]
internal static extern uint DwmpActivateLivePreview(uint a, IntPtr b, uint c, uint d);
...
//To call it
IntPtr peekHwnd = //<-- here goes the application Handle to aeropeek
//to enable
DwmpActivateLivePreview(1, peekHwnd, 0, 1);
...
//to disable
DwmpActivateLivePreview(0, peekHwnd, 0, 1);
Use it carefully, since many comments tell you that it is undocumented for some reason.
I think is because aeropeek is not supported by all windows editions, home basic is not supported, maybe you can implement your own window peek or at least fake it using alpha transparency (while drawing some border) and querying for underlying windows using the window rectangle coordinates like the rectangle collision detection algorithm.
Please go read Raymond Chen's blog until you realize this is a really, really, really bad idea!
There's a reason that apps can't activate Aero Peek - the user gets to choose when that happens, not you.

Resources