Re: ActiveX Dll in Csharp



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...@xxxxxxxxx> wrote:
Thanks Pavel I will look into the link provided.

On May 4, 12:45 pm, Pavel Minaev <int...@xxxxxxxxx> wrote:

On May 3, 9:03 pm, Avi <avi.i...@xxxxxxxxx> 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.

.



Relevant Pages

  • Re: LogonUser / CreateProcessAsUser - Behaves differently from different calling applications
    ... >CreateProcessAsUser to execute the command. ... Calling the DLL from another win32 ... > * This object maintains data for the Authentication and Process ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Calling Legacy C function from Managed C++
    ... If I make the DLL ... an Application, with the simulation model passed in the command line, ... passed to other functions called within OPNET ESA API. ... Esa_Init (argc, argv, options, esa_state_pptr) ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Error Signature
    ... Quote ... use the following command syntax: ... command 'regsvr32 /u GAMsys.dll' without quotes. ... >This DLL adds into Internet Explorer as a Browser Helper ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: Including modified SNTP component in the Release
    ... A few possibilities - if you're in command line build you need WINCEREL=1 ... This posting is provided "AS IS" with no warranties, and confers no rights. ... I have modified a file used to build the timesvc DLL. ...
    (microsoft.public.windowsce.embedded)
  • Re: Windows Update download window hangs
    ... I implemented Mark Brown's solution re error 0x00000485, ... Gives "Bad command or file name". ... For example, the DLL Help Database ... >> registered in either Internet Explorer or Windows Explorer. ...
    (microsoft.public.windowsupdate)

Loading