ActiveX initialization: AxHost.State object

6.7k views Asked by At

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?

3

There are 3 answers

0
Felix K. On BEST ANSWER

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);
1
user1158953 On

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".

0
nibiironokane On

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.