AppDomain and native window messages - appdomain

I have a problem which is also related to AppDomain's and Windows messages.
A web page to be hosted in Internet Explorer that would contain a .Net WinForms UserControl derived control - HelloWorldCtl. This control is inside a C# written assembly - HelloWorldControl.dll. The control uses code from another assembly that is written in C++/CLR - HelloWorldLibCPP.dll.
HelloWorldCtl loads HelloWorldLibCPP.dll and calls code that would create a Win32 native window and places that window in HelloWorldCtl's area.
Navigate to the web page, HelloWorldCtl loads, I can see it as well as the native window in the center of HelloWorldCtl's area.
Both the C# control and the native window have some message handlers and the messages are all working fine and reaching both the C# control's window and the native window; mouse clicks, re-paints and so on... However, some of the message handlers of the native window need to call methods on the C# control which is the parent of the native window. This is done using an interface that the C# control implements and which the native window holds a reference to by storing it in a GCHandle (from System::Runtime::InteropServices.) I used the gcroot<> template for the GCHandle.
The failure is happening at this point when code in the native window is trying to use the GCHandle to call any method on the C# control. (The c++ code is compiled as managed code with /clr.)
The exception that is thrown is :
"Cannot pass a GCHandle across AppDomains"
I put some debugging code to display the Id and FriendName of the CurrentDomain in both the C# and the native window and I found out that these AppDomains are not the same.
During the creation of the native window, the CurrentDomain is the same as that of the C# control, but when the native window receives messages and those messages are handled, the CurrentDomain is different from the C# control's.
Can this situation be changed? Is it possible to have both the native window messages hanlder run in the same AppDomain as that of the C# control?
Any other suggestions perhaps?
Thanks,
Roger

I have actually found a solution for the problem in question indeed. I successfully implemented my code in a similar fashion to what is described in the following post from the "Thoughts from Mirality,
Random thoughts and musings from Miral at Mirality Systems" blog under the subject "Unmanaged callbacks across AppDomains".
Good Luck,
Roger
http://lambert.geek.nz/2007/05/29/unmanaged-appdomain-callback/

Related

How to add a property page to DirectShow filter

I have written an DirectShow-Filter *.ax to integrate a Hardware (Camera). All works fine with my filter.ax and there Transport Images to Skype success.
Now I am want to integrate a Dialog to handle the camera-options with UI.
In my Filter.ax is calling the function QueryInterface(REFIID riid, void **ppv)
when riid == IID_ISpecifyPropertyPages
I am have seen that the Dialog must be in a other DLL like Com ?
My try to open the Dialog directly works, but no windows Messages are incoming.
I must also write an MFC Dll they is starting by PropertyPage IIID ? My Propertypage is a large MFC Controles TabControl with some items. I can see it if i start the filter from MFC Test app. AfxInit I can't execute. (Wrong Lib versions I must use the directshow baseclass(knowledge example)
I don't now why my Dialog got no Messages, what is the right way ?
You don't need to implement a property page in a separate DLL (even though it is a possible).
DirectShow filter property pages are regular COM property pages implemented using ISpecifyPropertyPages. Property pages are separate COM objects implementing well known interfaces like IPropertyPage.
Windows SDK Ezrgb24 sample shows how to implement a simple transform filter and also features a property page (CEZrgb24Properties class). It should be a good start for a property page implementation for your filter.
If you prefer to implement the property page in a separate DLL, a typical way is to define a shared COM interface, the filter would implement it and reference the property page by its CLSID, the property page would query this interface from the filter instance and use it for configuration actions.

XamlParseException when using UserControl from class library dll

I have created a library which has a Popup UserControl similar to the one here.
When I create a fresh Universal Windows App and create the same UserControl inside an app and open the popup, it opens.
But if I create a Class Library and create the same UserControl inside it and try to use it (by opening the popup) inside an app, I get a XamlParseException.
It is as follows -
Windows.UI.Xaml.Markup.XamlParseException occurred
HResult=-2144665590
Message=XAML parsing failed.
Source=Windows
StackTrace:
at Windows.UI.Xaml.Application.LoadComponent(Object component, Uri resourceLocator, ComponentResourceLocation
componentResourceLocation)
at PopupTestLibrary.MyUserControl1.InitializeComponent()
I am not able to understand exactly why this is happening, since the code works fine when not called from an external class library.
Some Questions I found to be similar to mine, here on SO -
XamlParseException when consuming a Page from a library
Cannot instantiate UserControl from another assembly
All help is appreciated!
You need to Add a Resource Dictionary in your App and Add the Usercontrol Xaml content to it
as Xaml is Considered as a Content file not compiled into the code
I think that this post is just as yours.. :
https://social.msdn.microsoft.com/Forums/en-US/63f071be-a3c5-4f2d-ace2-73ca750e3252/rtm-usercontrol-class-library-and-assembly-name-with-
And, It's known issue:
Dot in the project's name cause XAMLParseException
I hope that this will help you in your issue..

How does a Qt GUI application runs

how does a gui application in qt5 runs, what is the ui pointers role in it. I'm new to qt pls help me,Why we will pass this in the constructor like, Ui->setup(this).Thanks in advance.
Long story short: the uic parses the xml that Qt Designer generates (from form you create into the designer) and creates C++ code from that xml, and you need to use that code into your window class, there are many ways you can use that code, see the documentation and using that ui pointer is one of those ways (actually that is a pointer to an instance of a class from the generated code) as for how setupUi actually works you can see into the generated code - short answer is: it creates the form's layouts and widgets as children of this.

Test automation - Win32 app - White/UI automation - problem with recognizing objects

I’m looking for alternative for existing tests written in QTP for my Win32 application written in Borland C++.
My candidate is White which based on UI Automation because it’s native solution,
I can create my tests using .NET/C# and easily integrate it with nUnit and Hudson.
White
http://white.codeplex.com
MS UI Automation
http://msdn.microsoft.com/en-us/library/ms747327.aspx
UI Verify
http://uiautomationverify.codeplex.com
I use UI Verify as a spy to identify properties of objects I want to find in my tests.
More or less when I can see something in the spy, I can find it using UI Automation/White.
Generally I don't have much problems with recognizing objects
but when I try to search some content inside the tab contained in Tab Panel
or try to see MenuItems of Menu bar then the problem appears.
UI Automation/UI Verify works wired. When I run UI Verify (1.0 version) I see that objects can be registered properly only then
when I set 'Focus tracking' option and click on target objects or change the keyboard cursor on them. Otherwise it's impossible to find them.
UI Verifier can show me children of my 'tab' panel then. But I can’t find them using UI Automation/White. This is example code:
Tab tab = window.Get();
ITabPage tabPage = tab.SelectedTab;
AutomationElementCollection newCol = tabPage.AutomationElement.FindAll(TreeScope.Descendants, Condition.TrueCondition);
window.Get("buttonName");
the collection is empty even though spy see the children.
Does any of you have some experience with White/UI Automation library that he/she would like to share with me?
I want to implement the tracking feature from the spy to my tests. Can you help me with that? I'm trying to study the code of UIA Verify spy. I think that there are two classes responsible for catching the objects: FocusChangeListener and FocusTracer - this is the code:
http://uiautomationverify.codeplex.com/SourceControl/changeset/view/9992#214260
http://uiautomationverify.codeplex.com/SourceControl/changeset/view/9992#214192
Requirements:
1. Windows SDK
2. .NET 3.5
3. White
4. UIA Verify code
Do you have any better alternative for White/UI Automation?
R.
Could you, the R or YoYo, put your form compiled or in source codes (preferable without the internal logic) somewhere on a file share?
I've never seen a control that'd be not caught using UI Automation if UIAVerify sees it. I saw such windows, which could be only caught with the Focus Tracking feature of UIAVerify. This case, such a window is untouchable by UI Automation search.
Regarding a control, are you sure that the controls you struggling with have the Name property? Maybe, this is a value available only by means of ValuePattern, not the Name?

Library for using SVG in Windows Forms / WPF?

Are there any libraries which
Allow to draw svg direct to a Windows Forms application
to a WPF application
I draw graphics and design everything with Inkscape, because I love that program.
Then I have those stunning svgs and have to either export them to png (WinForm) to use them or convert them to xaml-code (WPF) (Kaxaml helps me).
Is there a way to directly use my svgs?
Wow, I just read that Inkscape supports saving as XAML. I didn't realize that up to now shame.
But that still doesn't solve my problems with WinForms...
I personally hate how there's no native support for SVG in Microsoft's products/development tools. I've found two fairly complete but still immature SVG libraries that seem to be active as of this writing, definitely in need of contributors though.
WPF : Svg2Xaml (open source)
WinForms : SVG rendering engine (open source)
IIRC both libraries output a Drawing object which can be used directly through the Image class; You'll figure it out, they're both pretty straightforward to use.
If you want to load them directly into WPF,
I got better results from: https://github.com/ElinamLLC/SharpVectors
Yes, you can use ReaderSVG from AB4D to get WPF directly from XAML.
Regarding WinForms, removed a previous link to Kent Boogart's example as it was deleted sometime in 2019.
Copy below from this dotnetways post
To host a WPF control or WPF user control (wpfControl in this example) into Windows Form application, create an instance of ElementHost Class and add your WPF control/user control as child to the instance of ElementHost.
using System.Windows.Forms.Integration;
//Assembly: WindowsFormsIntegration (in WindowsFormsIntegration.dll)
//...
ElementHost elementHost = new ElementHost();
elementHost.Dock = DockStyle.None;
elementHost.Child = wpfControl;
Now, add the instance of ElementHost to a container control in your windows form (for instance containerPanel here)
containerPanel.Controls.Add(elementHost);