Map XML to a custom C/C++ function - c++

I come from an Android development background and I would like to know if there's a way to allow XML to execute a C/C++ method? This is similar to Android's onClick event where a method is executed when a event has been received i.e. a button press, but I just want the XML to map and execute the method.
Thanks

In general, no. For example, there is no way to make an XSLT document execute a C++ method.
There are some systems (.Net and XAML spring to mind, but I believe Android is similar), where a dialect of XML is used to define a GUI, and attributes or elements define the functions to be called. This works better in a language with reflection, where the engine reading the XML can directly call the functions, but with something like GetProcAddress or dlsym you could make it work.

Related

I want to create a DeskBand. Do I have to use C++?

I want to create a DeskBand to display some information on my Windows task bar, but I am struggling with implementing the functionality I need in C++. It's been about 10-15 years since I touched C++. I've been working entirely in .NET for the past 7 years.
Before you say it - I know that DeskBands are deprecated. But the suggested replacement UI element - thumbnail toolbars - don't meet my needs. I need a UI element that is constantly visible to the user no matter which application they switch to, and also that provides enough room to display a line of text - I could get by with room for 30 characters or so.
I've been able to get the DeskBand from the Windows SDK sample to compile and run, but now I need to implement some real functionality - specifically...
Locating the AppData\Local folder (SHGetKnownFolderPath(FOLDERID_LocalAppData...)
Watching an XML file for modifications. I need to parse and repaint whenever the file changes.
Parsing the XML file (I found pugixml)
Displaying some data from the XML file in my DeskBand
Setting a timer to repaint the DeskBand once per minute
... and I am realizing how little I know about C++, and how much I've come to depend on .NET's Base Class Library. This task would be super easy for me if I was writing it in C#. But I've learned elsewhere that you shouldn't write shell extensions in .NET.
What are my options? Is there an easier language to accomplish this in - maybe Python? Or do I have to just bite the bullet and do this in C++? If so, any advice for a .NET developer trying to implement a WinAPI shell extension in C++?
Thank you in advance.
Shell Extensions are COM objects, and C++ is generally the best language to use when developing COM objects because COM was designed primarily for C++, but it is not the only language possible. COM has a standardized architecture, so you can use any language outside of .NET that supports COM object development (Delphi, VB, etc) to develop Shell Extensions (similar to how the Win32 API is primarily designed for C, but any C-compatible language can access it).

Run a c++ method from JavaScript (QTWebkit)

I can inject JavaScript to qtwebkit like this:
view->page()->mainFrame()->evaluateJavaScript();
But is it a way to do the inverted process? Runnin a C++ Method from JavaScript?
I thought about parsing the *js files with C++ and include some prefixed calls in the javascript to detect calls.
Is there a way to accomplish this?
There is great built-in ability in Qt to integrate C++ and Javascript code. It is easily possible to make QObject available in script engine.
Just take a look at Making Application Scriptable.

Firefox extension and nsIMutationObserver

I am a Firefox C++ extension newbie. I need to get access to DOM mutation events in my extension during page load. Firefox by default doesn't send DOM mutation events during page load to improve page load performance.
I understand the reason, but understanding the consequences I still need access to the DOM mutation events. I read somewhere that nsIMutationObserver still gets invoked during page load (and is bit more efficient then DOM mutation events as don't have to walk up the DOM tree looking for listeners), however it's only available to native code.
So I have following questions :
Is nsIMutationObserver and nsIMutationObserver2 available to Firefox extensions?
If yes, how can I write a simple Firefox extension in C++ to get access to it and expose it to Javascript?
If folks can point me to a existing extension that does this forwarding from C++ land to JS, that will be highly appreciated.
Or can I use JS-CTypes to get access to that functionality from my Javascript based extension?
BTW, I asked this question in Firefox's extension forum, but no replies there.
Thanks in advance
Is nsIMutationObserver and nsIMutationObserver2 available to Firefox extensions?
Yes, binary Firefox extensions can use it. Of course, the drawback is that your binary XPCOM component will only work with one Firefox release - it will have to be recompiled for each new release.
If yes, how can I write a simple Firefox extension in C++ to get access to it and expose it to Javascript?
You create an XPCOM component (see example code) and implement nsIMutationObserver interface. You then attach this mutation observer to documents like this:
NS_IMETHODIMP
MyMutationObserver::AttachToDocument(nsIDOMDocument* document)
{
nsCOMPtr<nsINode> node(do_QueryInterface(document));
node->AddMutationObserver(this);
}
For reference: nsINode interface
If folks can point me to a existing extension that does this forwarding from C++ land to JS, that will be highly appreciated.
Sorry, don't know any. But your XPCOM component can expose an additional interface that your JavaScript code will use - e.g. to register a callback. You have to consider that it might not be safe to run JavaScript when the mutation observer gets called. Important methods here: nsContentUtils::IsSafeToRunScript() and nsContentUtils::AddScriptRunner() (see nsContentUtils.h).
Or can I use JS-CTypes to get access to that functionality from my Javascript based extension?
No, you cannot. These are Gecko internals, they aren't exposed to js-ctypes.
A binary extension can use nsIMutationObserver, but unless it's very very careful about what it does when it's notified (see the big WARNING above the interface declaration) it'll cause crashes and various other broken behavior and is likely to introduce security bugs. Like any other internal API, this is a footgun; probably a fatal one if not used extremely carefully. Things that are fine to do in a DOM mutation listener are NOT OK in an nsIMutationObserver.

C++ framework for separating UI design from business logic

Is there a c++ framework for building rich desktop applications?
Essentially the important feature I'm looking for similar to Flex4 MXML to separate the visual presentation and application logic into xml. Does Qt4, for example, allow the visual appearance to be specified in xml definition? This is state based, so on events the UI changes and has new visual content like this and this
Yes.
Using Qt's Designer tool, you can separate the UI design into an XML, and then a UI compiler (uic tool) compiles it into a UI class.
Your code uses that class (either by delegation or by inheritance) to show its own GUI.
And throw in Qt's signal-slot mechanism for event handling and you have a heavenly development framework for C++ GUI apps :)
Edit:
Although Qt has a tool to specify UIs in XML, you don't always have to do so. You can create UIs programmatically, but why would anyone do so, right? The day I learnt to use Qt Designer was the day I stopped creating UIs programmatically.
And I personally feel that Qt's paradigm of separating the UI from the event handling code (unlike netbeans UI designer) is aaawwweeesssooommmeee.
Qt does. The XML is compiled into code at build time, so the UI remains static (i.e., you have to re-compile to change it).
Just FWIW, with wxWidgets and XRC you can specify a dynamic UI in XML -- i.e., the XML file remains separate from application and changing the XML file makes matching changes to the UI (within limits, of course).

Converting registry access to db calls from MFC Feature Pack

We may start converting an old VS2003 MFC project to use the fancy new features provided by the MFC Feature Pack and VS2008. Several of the new UI controls would be very nice except for one thing - they automatically save their information to the registry. I don't have a problem with the registry, but for the multiple environments the users use out program from, it's much easier to save user data to the database.
So, I'm hoping that there is one main "access the registry" function that could be overloaded to point the database. But brief investigation hasn't turned up anything. Has anyone else had any success doing something similar?
It seems like it should be possible to do what you're suggesting, according to the information on this page in MSDN. I haven't tried this myself, so I don't know how difficult it will be in practice.
According to the documentation, you should create a class that inherits CSettingsStore to read and write the settings, and call CSettingsStoreSP::SetRuntimeClass so that the framework uses your class instead of the default.
The MFC feature pack uses code supplied by BCGSoft and they added this feature (so you can save state to an XML file, database, etc.) way back in 2001. I don't have the feature pack on this PC but try looking for a class called something like CMFCRegistrySP.
I will check myself tomorrow.
Does the StateCollection sample do this?
http://msdn.microsoft.com/en-us/library/bb983406.aspx