Skip to main content
gamedev.net
🔒 Locked

Compiling C# ActiveX

Started by FeverGames 16 replies 2.7k views
Original Post
FeverGames
FeverGames
Hey guys, i have been following a few tutorials to try to make an ActiveX control. The code is as following:

using System;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.Collections.Generic;
using System.Text;

namespace ActiveXcontrol
{
    public class HelloWorld : System.Windows.Forms.UserControl
    {
        //Game game;

        public HelloWorld():base()
        {
            System.Windows.Forms.MessageBox.Show("hallo test!!");
            //game = new Game();
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
 
            }
            base.Dispose(disposing);
        }
    }
}



And compiled it the normal way. I embedded it as following:

<html>
  <body>
   <center>
     <object id="HelloWorld1" height="472" width="488"
         classid="http://127.0.0.1/ActiveXcontrol.dll#ActiveXcontrol.HelloWorld">
     </object>
<object id="HelloWorld1" name="HelloWorld1" classid="ActiveXcontrol.dll#ActiveXcontrol.HelloWorld">
</object>
   </center>
  </body>
</html>


does anyone have any idea why this doesn't work?
ApochPiQ
ApochPiQ
Can you provide some information about what exactly "doesn't work"? It's kind of hard to offer advice when we don't even know what the problem is....
FeverGames
FeverGames
Ok sorry for that then. There actually does not show anything up. There's actually nothing showing up. I run Apache (XAMP) in a localmachine. I have put everything in the same directory (DLL and HTML file)

for the following image i set the width and height of the second object to 100px so it "appears"



It is supposed to give a messageBox if i understand it right, but all it does is (what i believe) a "not found" or "not compatible" image. please tell me if anyone needs more information
ernow
ernow
Your code is C#.
The comilation result is a .NET class in .NET dll with probably a COM interface (depending on how the comiler settings were configured)

Your platform is Linux which, by default, does not understand .NET dll's

Are you aiming at MONO?

Do you know what you are doing?


FeverGames
FeverGames
Quote:
Original post by ernow
Your code is C#.
The comilation result is a .NET class in .NET dll with probably a COM interface (depending on how the comiler settings were configured)

Your platform is Linux which, by default, does not understand .NET dll's

Are you aiming at MONO?

Do you know what you are doing?


Sorry my platform at this point is Windows. And no, I just started of by testing some things in ActiveX.

I do however know C#.
Cygon
Cygon
First, you need to make your control COM visible (COM = the technology behind ActiveX). That means giving your control a class id

Second, as far as I know, .NET 2.0 and later do not support the creation of ActiveX controls. You can hack something together (I did this once) by using some attribute to get a callback when regasm.exe registers the control class and inject a "Control" key into appropriate location in the windows registry (that's all you need to make a COM class implementing appear as a control to ActiveX-capable applications), and it seems to work fine as far as I can tell.

If you're interesting, I can hunt for some of my old code that implements an ActiveX "hello world" control in .NET 2.0.



On the other hand, may I suggest simply using Microsoft Silverlight?

It's got a very small redistributable package (that doesn't require the .NET framework to be installed at all) and it works well in Firefox (in contrast to ActiveX controls).
Professional C++ and .NET developer trying to break into indie game development.
Follow my progress: http://blog.nuclex-games.com/ or Twitter - Topics: Ogre3D, Blender, game architecture tips & code snippets.
ernow
ernow
Ah, yes I was thrown off balance by the Apache/XAMP thing.

Sorry.


FeverGames
FeverGames
Quote:
Original post by Cygon
First, you need to make your control COM visible (COM = the technology behind ActiveX). That means giving your control a class id

Second, as far as I know, .NET 2.0 and later do not support the creation of ActiveX controls. You can hack something together (I did this once) by using some attribute to get a callback when regasm.exe registers the control class and inject a "Control" key into appropriate location in the windows registry (that's all you need to make a COM class implementing appear as a control to ActiveX-capable applications), and it seems to work fine as far as I can tell.

If you're interesting, I can hunt for some of my old code that implements an ActiveX "hello world" control in .NET 2.0.



On the other hand, may I suggest simply using Microsoft Silverlight?

It's got a very small redistributable package (that doesn't require the .NET framework to be installed at all) and it works well in Firefox (in contrast to ActiveX controls).


The problem is, and yes i know about security and so forth, that i want to be able to eventually display DirectX or XNA code in the activeX. As I understand it shouldn't be to hard, and it gives a nice and easy impression of our work as first impression.

As far as I understand SilverLight does not support these things, does it?

Thanks btw!
ernow
ernow
Why would you want to do that in a browser?

If it is deployment you might consider ClickOnce Deployment.

If it is the security sandbox from the browser: again look at ClickOnce Deployment and code access security.
FeverGames
FeverGames
Quote:
Original post by ernow
Why would you want to do that in a browser?

If it is deployment you might consider ClickOnce Deployment.

If it is the security sandbox from the browser: again look at ClickOnce Deployment and code access security.


Well it is a good way to install my program for the webservice, but for now i want to experiment on trying to let others play a DirectX game in a webbrowser. It is not for downloading or whatsoever, but showing DirectX output in a webbrowser.

Thanks though for thinking along
ernow
ernow
I am not quite sure what you mean by "Well it is a good way to install my program for the webservice"

Check out this as well

I still think that a web page linking to a click once manifest allows the same ease of install as running in a webbrowser without the hassle of building the activex control.
Cygon
Cygon
Quote:
Original post by FeverGames
Quote:
Original post by Cygon
On the other hand, may I suggest simply using Microsoft Silverlight?

The problem is, and yes i know about security and so forth, that i want to be able to eventually display DirectX or XNA code in the activeX. As I understand it shouldn't be to hard, and it gives a nice and easy impression of our work as first impression.

As far as I understand SilverLight does not support these things, does it?

Thanks btw!


You will not be able to use XNA or SlimDX in Silverlight, but Silverlight has its own API for 3D rendering (it's a trimmed down variant of WPF, after all).

ActiveX is pretty much deprecated, only Internet Explorer really supports it, but unless you sign your control (no idea how, probably costs money), the user experience will be troubled with lots of warnings.


But if you want to give it a try anyway, I've dug out my old code. Here's a minimal project for Visual C# 2008 Express SP1 that produces an ActiveX control that can be displayed in Internet Explorer: ActiveX.zip

Basically, to turn a UserControl class into an ActiveX control you need to make it ComVisible, give it a GUID and add this:
[ComRegisterFunction]public static void RegisterClass(string key) {  using(RegistryKey classKey = openClassKey(key)) {    using(RegistryKey controlKey = classKey.CreateSubKey("Control")) { }  }}[ComUnregisterFunction]public static void UnregisterClass(string key) {  using(RegistryKey classKey = openClassKey(key)) {    classKey.DeleteSubKey("Control", false);  }}private static RegistryKey openClassKey(string key) {  string registryLocation = key.Replace(@"HKEY_CLASSES_ROOT\", string.Empty);  return Registry.ClassesRoot.OpenSubKey(registryLocation, true);}


Good luck!
Professional C++ and .NET developer trying to break into indie game development.
Follow my progress: http://blog.nuclex-games.com/ or Twitter - Topics: Ogre3D, Blender, game architecture tips & code snippets.
FeverGames
FeverGames
do you have any idea how for example quake live and unity3D are doing this? They provide an installable package to run and all the sudden the plugin works. I thought they offered an installable ActiveX.
Antheus
Antheus
Quote:
Original post by FeverGames
do you have any idea how for example quake live and unity3D are doing this? They provide an installable package to run and all the sudden the plugin works. I thought they offered an installable ActiveX.


They provide specific browser plug-ins. It might use ActiveX for IE, but it cannot for Firefox or Safari or iPhone.

One of authors seems to be someone from Adobe who has dealt with this problem for a long time and stated that browser support is one of their top issues, and they're using experience gained from Shockwave and similar products.

The technical solution seems to be quite mundane - simply write browser-specific support for each platform/browser.

If it were as simple as putting an ActiveX control, there would be tons of FOSS equivalents - simply expose the OGL API.


But perhaps most importantly, these types of plug-ins are about market penetration and ubiquitous support. Use Unity3D, Adobe Air, Flash, Java or Silverlight. Writing your own is futile. Not only will it require excessive amounts of testing (much more than a single person can realistically provide), but users will need to use a custom plug-in (see WildTangent, and why it failed).

Leverage adopted technilogy and simply use Unity or its equivalent.
FeverGames
FeverGames
Quote:
Original post by Antheus
Quote:
Original post by FeverGames
do you have any idea how for example quake live and unity3D are doing this? They provide an installable package to run and all the sudden the plugin works. I thought they offered an installable ActiveX.


They provide specific browser plug-ins. It might use ActiveX for IE, but it cannot for Firefox or Safari or iPhone.

One of authors seems to be someone from Adobe who has dealt with this problem for a long time and stated that browser support is one of their top issues, and they're using experience gained from Shockwave and similar products.

The technical solution seems to be quite mundane - simply write browser-specific support for each platform/browser.

If it were as simple as putting an ActiveX control, there would be tons of FOSS equivalents - simply expose the OGL API.


But perhaps most importantly, these types of plug-ins are about market penetration and ubiquitous support. Use Unity3D, Adobe Air, Flash, Java or Silverlight. Writing your own is futile. Not only will it require excessive amounts of testing (much more than a single person can realistically provide), but users will need to use a custom plug-in (see WildTangent, and why it failed).

Leverage adopted technilogy and simply use Unity or its equivalent.


I get your point and it makes lots of sence, but the examples you mentioned do not provide a way to expose my own application on the web. Unity3D is specific for it's own engine and software, Java is a whole different language and SilverLight is not capable of exposing the 3D engine either, although as i read it has a 3D rendering possibility in it, which i would like to know more about.

All the stuff mentioned above has a lot of downsides that are not compatible in any way with what we try to create. As I said unity3D is specifically for their own purpose, Silverlight is probably not allowing CLI wrapped dll's, Adobe Air is just to slow, Java is a different language and Flash doesn't have 3D hardware support (yet) as far as I know, and i doubt it will support C# code.

nice discussion though, i'd love to get kicked down in my statements :D
Antheus
Antheus
Quote:
Original post by FeverGames

nice discussion though, i'd love to get kicked down in my statements :D


My point was merely that there is no easy and elegant way to do it. If you feel this is the way to go, choose the platforms and browsers you will support, and provide your own virtual machine using its native plug-in API.

But consider this over long-term. It's highly likely that this year 3D will break into browsers. Aside from all notable vendors now being players in this arena, 3D hardware is, by any and all criteria, ubiquitous. Even cell phones have it.

In addition, last year was the year of javascript revolution. JS engines have reached the level of being among the fastest interpreted languages.

With both hardware and software platforms being more than adequate, unified 3D in browser is simply a matter of time.

For this reason, inventing something on your own right now isn't viable. One would need to support all browsers and all platforms natively, making it very expensive/time-consuming project with next to no business model - final penetration will be determined by big players (Adobe or Microsoft).

If you need something right here and right now, Unity3D seems like a good choice. Otherwise, wait a year, and it's highly likely that browsers will support 3D with same degree of adoption as they support Flash today.

Quote:

All the stuff mentioned above has a lot of downsides that are not compatible in any way with what we try to create. As I said unity3D is specifically for their own purpose, Silverlight is probably not allowing CLI wrapped dll's, Adobe Air is just to slow, Java is a different language and Flash doesn't have 3D hardware support (yet) as far as I know, and i doubt it will support C# code.


IMHO, the days of "doesn't support language X" are over and gone. Getting a coder to work port/develop in language X is a non-issue these days. If anything, code itself is completely worthless.

Whatever you're trying to do will depend on content and assets, and those are portable. Twitter runs on Ruby, and is apparently being ported to Scala - how's that for exotic.

Languages simply don't matter anymore. Especially right now, when coders are dime-a-dozen and you get two free on top of that. Sad state of economy, but the way things are no less.
FeverGames
FeverGames
Quote:
Original post by Antheus
Quote:
Original post by FeverGames

nice discussion though, i'd love to get kicked down in my statements :D


My point was merely that there is no easy and elegant way to do it. If you feel this is the way to go, choose the platforms and browsers you will support, and provide your own virtual machine using its native plug-in API.

But consider this over long-term. It's highly likely that this year 3D will break into browsers. Aside from all notable vendors now being players in this arena, 3D hardware is, by any and all criteria, ubiquitous. Even cell phones have it.

In addition, last year was the year of javascript revolution. JS engines have reached the level of being among the fastest interpreted languages.

With both hardware and software platforms being more than adequate, unified 3D in browser is simply a matter of time.

For this reason, inventing something on your own right now isn't viable. One would need to support all browsers and all platforms natively, making it very expensive/time-consuming project with next to no business model - final penetration will be determined by big players (Adobe or Microsoft).

If you need something right here and right now, Unity3D seems like a good choice. Otherwise, wait a year, and it's highly likely that browsers will support 3D with same degree of adoption as they support Flash today.

Quote:

All the stuff mentioned above has a lot of downsides that are not compatible in any way with what we try to create. As I said unity3D is specifically for their own purpose, Silverlight is probably not allowing CLI wrapped dll's, Adobe Air is just to slow, Java is a different language and Flash doesn't have 3D hardware support (yet) as far as I know, and i doubt it will support C# code.


IMHO, the days of "doesn't support language X" are over and gone. Getting a coder to work port/develop in language X is a non-issue these days. If anything, code itself is completely worthless.

Whatever you're trying to do will depend on content and assets, and those are portable. Twitter runs on Ruby, and is apparently being ported to Scala - how's that for exotic.

Languages simply don't matter anymore. Especially right now, when coders are dime-a-dozen and you get two free on top of that. Sad state of economy, but the way things are no less.


With that you make a very good point. I just hope this feature will be in the form of all sorts of languages, instead of only C++ or java. That way existing engines etc can simply create a different output stream to their engine to support webbrowser gaming, instead of having to rewrite a bunch just to support java or whatever.
FeverGames
FeverGames
Quote:
Original post by Antheus
IMHO, the days of "doesn't support language X" are over and gone. Getting a coder to work port/develop in language X is a non-issue these days. If anything, code itself is completely worthless.

Whatever you're trying to do will depend on content and assets, and those are portable. Twitter runs on Ruby, and is apparently being ported to Scala - how's that for exotic.

Languages simply don't matter anymore. Especially right now, when coders are dime-a-dozen and you get two free on top of that. Sad state of economy, but the way things are no less.


none the less, i think this is a simple waste of everyone's time. Instead of investing money and manpower in innovation we have to write all sorts of ports and maintain them, just to be able to support different platforms, browsers, consoles and so forth. The fact that changing some core features will result into a ton of ports that need this adjustment to.

and the economy will adjust itself, and man power will get more expensive again.
That results into more money going to all sorts of work you don't even want happening in your company.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.