ActiveX initialization: AxHost.State object

一笑奈何 提交于 2019-12-10 10:11:27

问题


I'm trying to embed a Unity3D-ActiveX control into a WPF-Form by using a WinFormsHost-Control.

Actually it works well when setting the path in the property window of VS, but when setting it in my code file it does not load anything. This is a known issue of the control but i thought i can simply copy the creation code of the forms-designer and initialize it manually.

When looking at the code of the initialization i noticed that there is no src property in the code, but the property is used in the property window. Setting the property manually does not work ( throws a error ).

After some test's i decided to check the hole assembly for the src property, but the src property is never set and i can't even find the string of the path.

Final thoughts

I noticed that there can be only one place where the src-path is located: The resource generated by the window forms designer, which is a object of the AxHost.State-type.

Question

How do i create a valid AxHost.State object to initialize the Unity3D-ActiveX control which should load a Unity3D-file specified by me?


回答1:


This is the solution which works but is a little bit slow( Note: You need to initialize the Control once in the Forms Designer and copy the OcxState object into the assembly resources ):

// Create a ocx state object with the correct path
_Unity = new AxUnityWebPlayerAXLib.AxUnityWebPlayer();
((System.ComponentModel.ISupportInitialize)(_Unity)).BeginInit();
_Unity.OcxState = (AxHost.State)(Resources.Unity3DOcx);
_Unity.TabIndex = 0;
Controls.Add(_Unity);
((System.ComponentModel.ISupportInitialize)(_Unity)).EndInit();
_Unity.src = _File;
AxHost.State state = _Unity.OcxState;
_Unity.Dispose();

// Create the unity web player object
_Unity = new AxUnityWebPlayerAXLib.AxUnityWebPlayer();
((System.ComponentModel.ISupportInitialize)(_Unity)).BeginInit();
this.SuspendLayout();
_Unity.Dock = DockStyle.Fill;
_Unity.Name = "Unity";
_Unity.OcxState = state;
_Unity.TabIndex = 0;
Controls.Add(_Unity);
((System.ComponentModel.ISupportInitialize)(_Unity)).EndInit();
this.ResumeLayout(false);



回答2:


If you want to set a parameter into disableContextMenu property in ActiveX Unity Web player, you need to prepare IPropertyBag.Read Method in your program.

I made a sample C++ program (Visual Studio 2010) which set "true" parameter into disableContextMenu property. See http://www.nibiirosoft.com/download/UnityActiveXSample.zip

And using that codes, I made a player for .unity3d files (http://www.nibiirosoft.com/Product/UniPlayer.html).

I hope it will be helpful to you.




回答3:


Decompiling the dll "AxUnityWebPlayerAXLib" and adding the src parameter directly in the code solves the problem.

Everything works fine, but I still have a problem with "disableContextMenu".



来源:https://stackoverflow.com/questions/8735616/activex-initialization-axhost-state-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!