Injected WPF Windows
I am trying to get my WPF Window to display from inside another process via DLL injection and remote CLR hosting. I know that the CLR is correctly hosted and able to run code as I can create MessageBox()'s from inside the remote process using ICLRRuntimeHost::ExecuteInDefaultAppDomain();
However, when I try to display my WPF Window (which is compiled into a Class Library), nothing happens. I have tried the following methods:
public static int Display(String pwzArgument)
{
App thisApp = new App();
thisApp.Run();
return 0;
}
and also:
public static int Display(String pwzArgument)
{
MainWindow win = new MainWindow();
win.Show();
return 0;
}
My App.xaml and MainWindow.xaml:
// App.xaml
<Application
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="WPFTest.App"
StartupUri="MainWindow.xaml" Startup="Application_Startup">
<Application.Resources>
<!-- Resources scoped at the Application level should be defined here. -->
</Application.Resources>
</Application>
//MainWindow.xaml
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
x:Class="WPFTest.MainWindow"
x:Name="Window"
Title="MainWindow"
Width="640" Height="378" Foreground="{x:Null}" Visibility="Visible" Topmost="True" Background="{x:Null}">
<Grid>
<Rectangle Stroke="Black" RadiusX="20" RadiusY="20" StrokeThickness="0.5">
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF13DCF2" Offset="0"/>
<GradientStop Color="#FF0D0D0D" Offset="1"/>
<GradientStop Color="#FFF2F2F2" Offset="0.289"/>
<GradientStop Color="#FF8C8C8C" Offset="0.56"/>
<GradientStop Color="#FF262626" Offset="0.819"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Button Content="X" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,5,17,0" FontWeight="Bold"/>
<Button Content="[ ]" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,5,3开发者_StackOverflow4.077,0" FontWeight="Bold"/>
<Button Content="_" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,5,56.247,0" FontWeight="Bold"/>
<Label Content="Injected WPF Test" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="12,-3,0,0" FontSize="18.667" FontStyle="Italic"/>
<Rectangle HorizontalAlignment="Left" StrokeThickness="0" Margin="0,31,0,52" Width="640" Fill="#53000000"/>
<Label Content="Placeholder:
" HorizontalAlignment="Left" Margin="0,162.678,0,173.401" d:LayoutOverrides="HorizontalAlignment, Height"/>
<Label Content="Process Name:
" Margin="0,121.124,0,0" d:LayoutOverrides="HorizontalAlignment" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<Label Content="PID:" Margin="0,79.204,0,0" HorizontalAlignment="Left" Height="41.92" VerticalAlignment="Top"/>
<Label Content="Placeholder:
" HorizontalAlignment="Left" Margin="0,0,0,121.124" VerticalAlignment="Bottom" d:LayoutOverrides="HorizontalAlignment, VerticalAlignment"/>
<Label Content="Placeholder:
" HorizontalAlignment="Left" Margin="0,0,0,79.204" d:LayoutOverrides="HorizontalAlignment" VerticalAlignment="Bottom"/>
<Label Content="PID_CONTENT
" HorizontalAlignment="Left" Margin="87.513,79.204,0,218" d:LayoutOverrides="HorizontalAlignment" Name="PIDCONTENT" Loaded="PIDCONTENT_Loaded" />
<Label Content="PROCNAME
" HorizontalAlignment="Left" Margin="87.513,121.124,0,0" d:LayoutOverrides="HorizontalAlignment" VerticalAlignment="Top" Name="PROCNAME" Loaded="PROCNAME_Loaded" />
<Label Content="PLACEHOLDER
" HorizontalAlignment="Left" Margin="87.513,163.044,0,163.043" d:LayoutOverrides="HorizontalAlignment, Height"/>
<Label Content="PLACEHOLDER
" HorizontalAlignment="Left" Margin="87.513,0,0,121.123" d:LayoutOverrides="HorizontalAlignment" VerticalAlignment="Bottom"/>
<Label Content="PLACEHOLDER
" HorizontalAlignment="Left" Margin="87.513,0,0,79.203" d:LayoutOverrides="HorizontalAlignment" VerticalAlignment="Bottom"/>
</Grid>
</Window>
Neither of the above methods display any window. I am very new to WPF and I'm sure there is something I'm missing.
精彩评论