Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 26th, 2008, 02:01 PM
Authorized User
 
Join Date: Nov 2006
Location: Valparaiso, IN, USA.
Posts: 93
Thanks: 0
Thanked 1 Time in 1 Post
Default 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
__________________
What you don\'t know can hurt you!
  #2 (permalink)  
Old December 29th, 2008, 08:08 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

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
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================
  #3 (permalink)  
Old December 30th, 2008, 10:38 AM
Authorized User
 
Join Date: Nov 2006
Location: Valparaiso, IN, USA.
Posts: 93
Thanks: 0
Thanked 1 Time in 1 Post
Default

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.
__________________
What you don\'t know can hurt you!
  #4 (permalink)  
Old December 30th, 2008, 10:48 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

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
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================
  #5 (permalink)  
Old December 30th, 2008, 12:39 PM
Authorized User
 
Join Date: Nov 2006
Location: Valparaiso, IN, USA.
Posts: 93
Thanks: 0
Thanked 1 Time in 1 Post
Default

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.
__________________
What you don\'t know can hurt you!
  #6 (permalink)  
Old December 30th, 2008, 01:00 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

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
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================
  #7 (permalink)  
Old January 13th, 2009, 03:48 PM
Authorized User
 
Join Date: Nov 2006
Location: Valparaiso, IN, USA.
Posts: 93
Thanks: 0
Thanked 1 Time in 1 Post
Default

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.
__________________
What you don\'t know can hurt you!
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling managed code from un-managed code David_0223 C# 7 August 21st, 2007 09:32 AM
Usercontrols yveerabhadrarao ADO.NET 1 August 3rd, 2007 06:57 AM
Managed & Unmanaged Code? code_lover General .NET 0 January 4th, 2007 10:08 AM
Unmanaged to managed code blemos C# 0 December 21st, 2006 08:34 AM
Linking UserControls dhanyavnair Pro VB 6 2 December 1st, 2004 02:41 PM



All times are GMT -4. The time now is 06:34 PM.


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