我需要托管一个窗口,该窗口是从我创建的窗口中的另一个进程衍生而来的,以便发送命令(例如按键等)以及从该进程中检索信息以进行调试(这是为了调试游戏引擎)使用源代码,我们无权访问。)
X11的XReparentWindow方法似乎是完成此任务所需要的;但是,我一直收到X11错误:BadMatch(无效的参数属性)。
public bool LoadMugen_UNIX(int profileNo)
{
Display = new XDisplay(null);
var dummy = new XWindow(Display, this.Handle);
var allWindows = new XWindow(Display, new IntPtr(Display.Root));
var sw = new Stopwatch();
IntPtr processPtr = IntPtr.Zero;
// Wait for MUGEN to be recognized
sw.Start();
while (sw.ElapsedMilliseconds < 5000 && processPtr == IntPtr.Zero)
{
try
{
processPtr = FindWindows(Display.Handle, "M.U.G.E.N").FirstOrDefault(ptr => ptr != IntPtr.Zero);
}
catch
{
}
}
sw.Stop();
processWindow = new XWindow(Display, processPtr);
var pWindow = processWindow;
var container = new XWindow(Display, this.backgroundBox.Handle);
if (processWindow != null)
{
if (this.p == null || this.p.HasExited)
{
this._mugen_type = MugenWindow.MugenType_t.MUGEN_TYPE_NONE;
if (this.p != null)
this.p.Dispose();
this.p = (Process)null;
if (LogManager.MainObj() != null)
LogManager.MainObj().appendLog("Failed to load the exe file.");
return false;
}
if (processWindow.Handle == IntPtr.Zero)
{
if (LogManager.MainObj() != null)
LogManager.MainObj().appendLog("Failed to load the exe file.");
this.CloseMugen();
return false;
}
X11NativeMethods.XReparentWindow(Display.Handle, processWindow.Handle, container.Handle, 0,0);
MugenProfile profile = ProfileManager.MainObj().GetProfile(profileNo);
if (profile != null)
{
DebugForm.MainObj().SetSpeedModeCheckBox(profile.IsSpeedMode(), true);
DebugForm.MainObj().SetSkipModeCheckBox(profile.IsSkipMode());
DebugForm.MainObj().SetDebugModeCheckBox(profile.IsDebugMode(), true);
DebugForm.MainObj().PreInitTriggerCheck(this._mugen_type);
this._workingProfileId = profile.GetProfileNo();
}
this._isMugenFrozen = false;
this._isGameQuitted = false;
this._isMugenCrashed = false;
this._addr_db = MugenAddrDatabase.GetAddrDatabase(this._mugen_type);
if (!this.mugenWatcher.IsBusy)
this.mugenWatcher.RunWorkerAsync();
return true;
}
return false;
}
X11 XReparentWindow在单独的文件中定义为DllImport,如下所示:
[DllImport("libX11.so")]
public static extern int XReparentWindow(IntPtr display, IntPtr w, IntPtr parent, int x, int y);
我得到的错误如下:
X11 Error encountered:
Error: BadMatch (invalid parameter attributes)
Request: 7 (0)
Resource ID: 0x8600062
Serial: 2238
Hwnd: Hwnd, Mapped:True ClientWindow:0x8600062, WholeWindow:0x8600061, Zombie=False, Parent:[Hwnd, Mapped:True ClientWindow:0x8600060, WholeWindow:0x860005F, Zombie=False, Parent:[<null>]]
Control: System.Windows.Forms.PictureBox, SizeMode: StretchImage at System.Environment.get_StackTrace () [0x00000] in /build/mono/src/mono/mcs/class/corlib/System/Environment.cs:316
Control: System.Windows.Forms.PictureBox, SizeMode: StretchImage at System.Environment.get_StackTrace () [0x00000] in /build/mono/src/mono/mcs/class/corlib/System/Environment.cs:316
at System.Windows.Forms.XplatUIX11.HandleError (System.IntPtr display, System.Windows.Forms.XErrorEvent& error_event) [0x00067] in /build/mono/src/mono/mcs/class/System.Windows.Forms/System.Windows.Forms/XplatUIX11.cs:2120
at XSharp.XWindow.XFetchName (System.IntPtr , System.IntPtr , System.IntPtr& ) [0x00000] in <af09c9b5837947a8b2263cd8aa794ae6>:0
at XSharp.XWindow.get_Name () [0x00007] in /run/media/jesuszilla/Roll/dev/xsharp/xsharp/xsharp.cs:1687
at SwissArmyKnifeForMugen.MugenWindow.LoadMugen_UNIX (System.Int32 profileNo) [0x001df] in /run/media/jesuszilla/Roll/dev/SAKnifeWM/SwissArmyKnifeForMugen/MugenWindow_Native.cs:75
是什么原因导致BadMatch,如何克服它才能完成此任务?