PC Review


Reply
Thread Tools Rate Thread

ActiveX Dll in Csharp

 
 
Avi
Guest
Posts: n/a
 
      4th May 2009
Hi,

Can someone please let me know if it is possible to create ActiveX dll
(COM component) in Csharp. If Yes, Can you please provide me some
pointer how to create it.

My objective is to create a function for impersonation that i will be
further using in my testing tool.

Thanks in advance,
Avinash.
 
Reply With Quote
 
 
 
 
Pavel Minaev
Guest
Posts: n/a
 
      4th May 2009
On May 3, 9:03*pm, Avi <avi.i...@gmail.com> wrote:
> Hi,
>
> Can someone please let me know if it is possible to create ActiveX dll
> (COM component) in Csharp. If Yes, Can you please provide me some
> pointer how to create it.
>
> My objective is to create a function for impersonation that i will be
> further using in my testing tool.


If you want to create a COM component in C#, then, yes, that is
possible. You might want to start with a sample here, and explore the
links in it:

http://msdn.microsoft.com/en-us/library/c3fd4a20.aspx

If you need an ActiveX _control_, then, to the best of my knowledge,
you can't make a properly working one using WinForms.

 
Reply With Quote
 
Avi
Guest
Posts: n/a
 
      4th May 2009
Thanks Pavel I will look into the link provided.

On May 4, 12:45*pm, Pavel Minaev <int...@gmail.com> wrote:
> On May 3, 9:03*pm, Avi <avi.i...@gmail.com> wrote:
>
> > Hi,

>
> > Can someone please let me know if it is possible to create ActiveX dll
> > (COM component) in Csharp. If Yes, Can you please provide me some
> > pointer how to create it.

>
> > My objective is to create a function for impersonation that i will be
> > further using in my testing tool.

>
> If you want to create a COM component in C#, then, yes, that is
> possible. You might want to start with a sample here, and explore the
> links in it:
>
> http://msdn.microsoft.com/en-us/library/c3fd4a20.aspx
>
> If you need an ActiveX _control_, then, to the best of my knowledge,
> you can't make a properly working one using WinForms.


 
Reply With Quote
 
Avi
Guest
Posts: n/a
 
      16th May 2009
Finally I found the way out. Process seems to be little confusing, so,
listing down the steps or the benefit of others.

1) create a class file myCOMobj.cs (you can use notepad to do that)
2) Add the Sample Code below

//
********************************************************************************************************//
using System;
using System.Text;
using System.Runtime.InteropServices;

namespace myCOMobj
{
public interface ImyCOMobj
{
string sayHello();
}
[ClassInterface(ClassInterfaceType.AutoDual)]
[Guid("2F3357F5-2AB4-4d24-81C1-B54A915CAEF0")]
public class myCOM: ImyCOMobj
{
public myCOM()
{
//
// TODO: Add constructor logic here
//
}
public string sayHello()
{
return "Hello From C#";
}
}
}
//
********************************************************************************************************//

3) Create a strong Key Name using the below command
c:\Temp>sn.exe -k MyKey.snk
* you will see the message "Key pair written to MyKey.snk" and a
file will be created

4) Compile the original .cs file to make a dll using this strong key.
Use the command below achieve this.
C:\Temp>csc /keyfile:"c:\temp\myKey.snk" /target:library myCOM.cs
*this will create a dll file named myCOM.dll in c:\temp directory

5) Convert the .dll to type using command
C:\Temp>regasm myCom.dll /tlb myCom.tlb

6) Add the assembly into GAC cache using command
C:\Temp>gacutil -i myCOM.dll

Testing of Component:
Component should be visible to any application on that machine having
ability to use COM objects. For verification you can test this using
Excel.
1) Open Excel, Press ALT+F11 -> VBA editor will open
2) Tools > References > MyCOM should be listed in the Available
resources. Select that and Click ok.
3) Insert a module (Insert > Module)
4) Type the Code Below

Sub Test()
Dim objMyCOM As myCOM.myCOM
Set objMyCOM = New myCOM.myCOM
MsgBox objMyCOM.sayHello
End Sub

*Message Box "Hello From C#" should be displayed. If Everything goes
fine.

Regards,
Avinash



On May 4, 10:50*pm, Avi <avi.i...@gmail.com> wrote:
> Thanks Pavel I will look into the link provided.
>
> On May 4, 12:45*pm, Pavel Minaev <int...@gmail.com> wrote:
>
> > On May 3, 9:03*pm, Avi <avi.i...@gmail.com> wrote:

>
> > > Hi,

>
> > > Can someone please let me know if it is possible to create ActiveX dll
> > > (COM component) in Csharp. If Yes, Can you please provide me some
> > > pointer how to create it.

>
> > > My objective is to create a function for impersonation that i will be
> > > further using in my testing tool.

>
> > If you want to create a COM component in C#, then, yes, that is
> > possible. You might want to start with a sample here, and explore the
> > links in it:

>
> >http://msdn.microsoft.com/en-us/library/c3fd4a20.aspx

>
> > If you need an ActiveX _control_, then, to the best of my knowledge,
> > you can't make a properly working one using WinForms.


 
Reply With Quote
 
Avi
Guest
Posts: n/a
 
      16th May 2009
Finally I found the way out. Process seems to be little confusing, so,
listing down the steps or the benefit of others.

1) create a class file myCOMobj.cs (you can use notepad to do that)
2) Add the Sample Code below

//
********************************************************************************************************//
using System;
using System.Text;
using System.Runtime.InteropServices;

namespace myCOMobj
{
public interface ImyCOMobj
{
string sayHello();
}
[ClassInterface(ClassInterfaceType.AutoDual)]
[Guid("2F3357F5-2AB4-4d24-81C1-B54A915CAEF0")]
public class myCOM: ImyCOMobj
{
public myCOM()
{
//
// TODO: Add constructor logic here
//
}
public string sayHello()
{
return "Hello From C#";
}
}
}
//
********************************************************************************************************//

3) Create a strong Key Name using the below command
c:\Temp>sn.exe -k MyKey.snk
* you will see the message "Key pair written to MyKey.snk" and a
file will be created

4) Compile the original .cs file to make a dll using this strong key.
Use the command below achieve this.
C:\Temp>csc /keyfile:"c:\temp\myKey.snk" /target:library myCOM.cs
*this will create a dll file named myCOM.dll in c:\temp directory

5) Convert the .dll to type using command
C:\Temp>regasm myCom.dll /tlb myCom.tlb

6) Add the assembly into GAC cache using command
C:\Temp>gacutil -i myCOM.dll

Testing of Component:
Component should be visible to any application on that machine having
ability to use COM objects. For verification you can test this using
Excel.
1) Open Excel, Press ALT+F11 -> VBA editor will open
2) Tools > References > MyCOM should be listed in the Available
resources. Select that and Click ok.
3) Insert a module (Insert > Module)
4) Type the Code Below

Sub Test()
Dim objMyCOM As myCOM.myCOM
Set objMyCOM = New myCOM.myCOM
MsgBox objMyCOM.sayHello
End Sub

*Message Box "Hello From C#" should be displayed. If Everything goes
fine.

Regards,
Avinash



On May 4, 10:50*pm, Avi <avi.i...@gmail.com> wrote:
> Thanks Pavel I will look into the link provided.
>
> On May 4, 12:45*pm, Pavel Minaev <int...@gmail.com> wrote:
>
> > On May 3, 9:03*pm, Avi <avi.i...@gmail.com> wrote:

>
> > > Hi,

>
> > > Can someone please let me know if it is possible to create ActiveX dll
> > > (COM component) in Csharp. If Yes, Can you please provide me some
> > > pointer how to create it.

>
> > > My objective is to create a function for impersonation that i will be
> > > further using in my testing tool.

>
> > If you want to create a COM component in C#, then, yes, that is
> > possible. You might want to start with a sample here, and explore the
> > links in it:

>
> >http://msdn.microsoft.com/en-us/library/c3fd4a20.aspx

>
> > If you need an ActiveX _control_, then, to the best of my knowledge,
> > you can't make a properly working one using WinForms.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
help VC++ Activex into Csharp hari_Newsgroups Microsoft Dot NET Framework Forms 1 19th Jan 2007 11:43 AM
CSharp inside an ActiveX dll within IE Jim Mcduggan Microsoft C# .NET 3 15th Feb 2006 07:16 PM
How to write an ActiveX or COM .NET Object to be used in Internet Explorer (IE) in csharp (C#) Daniel Roth Microsoft Dot NET Framework 1 4th Apr 2005 04:42 PM
ActiveX control developed in CSharp Yeghia Microsoft C# .NET 0 13th Sep 2004 09:57 PM
How do I use CSharp to create ActiveX Objects? =?Utf-8?B?UmFzaGFkIFJpdmVyYQ==?= Microsoft C# .NET 2 19th Nov 2003 09:37 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:13 PM.