p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   C# 2005 (http://p2p.wrox.com/forumdisplay.php?f=138)
-   -   Using UserControls with Non-Managed Code (http://p2p.wrox.com/showthread.php?t=71965)

David_0223 December 26th, 2008 02:01 PM

Using UserControls with Non-Managed Code
 
Has anyone developed a custom user control in C# for use with a non-managed application?

I developed a dial indicator to use with a process data historian client tool. The tool is an ActiveX container but I am not able to find the control to add it to the container. The tool has VBA capability and I tried to register the indicator but I get the message that I can't add a reference to the file (the .dll generated by my code).

Any ideas on how to make a C# usercontrol available to unmanaged apps?

Thanks

dparsons December 29th, 2008 08:08 PM

Hmm. This may turn out to be more trouble then its worth. By saying user control that, to me, means a .ascx file with either a vb or cs code file that provides x functionality / logic.

This is trivial when you are talking about Web forms but the functionality that you are looking for here would be more of an API (Class library). While it might be possible (I have never tried) to emit some sort of UI elements back from the class library, it would most certainly be a cumbersome task.

What I would suggest is to scrap the UI portion via managed code and simply update your VBA application. Then create a new Class library project in VS and provide the functionality that you will need there. As far as the Interop goes it would probably be best if you took a look at this article http://msdn.microsoft.com/en-us/library/ms973872.aspx rather than me trying to spew it forth. ;]

hth
-Doug

David_0223 December 30th, 2008 10:38 AM

Thanks for the reply Doug.

In this case I cannot update the VB application. Actually it's probably written in C++, but either way I don't have access to the code. It is a comercial product that acts as an ActiveX container.

I want to build some custom graphical display controls to put in this container. As the application is a graphical user interface to a data historian, I want to be able to update my control with data from the application. The application has VBA programability so any COM compliant ActiveX control I put in there I should be able to affect provided I have exposed the necessary properties to the COM interface.

I have found a nifty post on doing this but I haven't been able to get it to work...

http://www.c-sharpcorner.com/UploadF...iveXInNet.aspx

So far I am just messing around with putting my control in an HTML document and opening it with IE. Since that didn't work I tried to follow the instructions exactly as the link indicates. It still doesn't work. I get a box on the page that is the correct shape according to the size specified in the OBJECT tag. The box has the red-X button indicating a broken object. I was concerned that the policies on my work pc might be causing the problem so I broght the control home along with the test document and checked it on my home pc. I got the same result.

Now I'm wondering if the assembly has to be added to the GAC?

Let me know if you find anything. I'll keep looking.

dparsons December 30th, 2008 10:48 AM

I only briefly looked over the link that you sent but it does not look like the author went into any detail on how to deploy the control. This can range from a setup file, a self extractor and so on it all just depends on what your requirements are.

Anywho, the fast and easy way for you to get this up and running is to open a command prompt, navigate to the directory where your assembly is, and run this command:

Code:

  regasm ActiveXLib.dll /tlb /codebase
This should allow you to make calls to your control via an object tag or JavaScript by using

javascript Code:
var obj = new ActiveXObject(Namespace.Class);

hth
-Doug

David_0223 December 30th, 2008 12:39 PM

I tried regasm and was still unable to display the object. I had already added it to the GAC and tried with no success. So I removed it from the GAC and re-registered (with regasm) and tried again. Still won't work.

I'm using the tag:

Code:

      <OBJECT id="myControl1" name="myControl1" classid="ActiveXDotNet.dll#ActiveXDotNet.myControl" width=288 height=72>
      </OBJECT>

Which is exactly what the other site said to use.

The object is registered with the windows registry in HKEY_CLASSES_ROOT.

Incidentially, you used the command:

Code:

regasm ActiveXLib.dll /tlb /codebase
But I assumed you ment "ActiveXLib.dll" to be the name of my library. So I used my library name.

dparsons December 30th, 2008 01:00 PM

Yes, when I put ActiveXLib.dll I meant for you to put the name of your assembly in there.

I can't really give you any other advice as ActiveX (COM/COM+) isn't my specialty but you might want to try this link: http://www.codeproject.com/KB/cs/Cre...veXDotNet.aspx

hth
-Doug

David_0223 January 13th, 2009 03:48 PM

I thought the CodeProject example was pretty disjointed. I downloaded the example code but couldn't get that to work. It doesn't appear to be addressed in the example on the webpage so it was hard to follow what he was trying to do. Also, I think this may be a .Net 1.1 example and I'm using VS2005.

I still haven't been able to find an example that works with IE. I have been able to create a UserControl that works with tstcon32.exe which I think is supposed to be an unmanaged code ActiveX container. I can find the object now (the registration worked) but when I try to load it in my other ActiveX container I get the message: "Unable to load control from file mscoree.dll. File not found."

This is an area in which there is very little knowledge I guess.


All times are GMT -4. The time now is 06:28 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.