Solved

C# ActiveX DLL

Posted on 2004-09-08
11
1,115 Views
Last Modified: 2008-01-09
Could someone please help me with some example source code on how to write an ActiveX DLL in C#. I have an existing DLL written in VB 6.0 and I have a decent understanding of COM and COM+.

This DLL will only be called from classic ASP pages and it will be run on two dedicated COM+ servers.

All I need is a working sample with one or two methods.

The first method should make a connection to a MS SQL Server, run a simple select statement and write the results to the calling ASP page by using Response.Write.

In the VB DLL I use the ASPTypeLibrary Class to get access to the ASP Request, Response, Session, Server and Application objects. Is it possible to do the same in C#?
0
Comment
Question by:hans_larson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
11 Comments
 
LVL 2

Expert Comment

by:netjkus
ID: 12009503
I am not sure if you wanted to write an Active X component? I think you are trying to use C# code in asp.

But, basically in .NET - MS recommends to re-write the ActiveX code using C# components. Just handling a Connection to SQLServer need not be an activeX at all. You can create a standard Library to do this job.

to create a DLL , try this :
http://www.c-sharpcorner.com/2/pr12.asp

you can get most of the part done using the regular DLL. Unless you want to use some components that are done in Active X and you want to keep using them in C#, like Imaging etc., you donot need ActiveX in .net. You can write Unmanaged code if you are planning to use in non - .net applications. This will not help you use any of the .net features.
0
 
LVL 3

Author Comment

by:hans_larson
ID: 12009788
netjkus:

My current environment is Classic ASP and the reason for wanting to move to C# is because the VB 6.0 ActiveX DLL is single-threaded and I need a multi-threaded DLL and figured I can do this is C#.

I know a little more about C# than I do about C++ so that's the motivation to use C# right there.

Look at:  http://www.codeproject.com/csharp/estransactions.asp

Esentialy this is what I need to do, but I also need to be able to access the ASP intrinsic objects from within C#. So an example of using the component described in the above URL that writes the recordset using the ASP Response object is what I need.

0
 
LVL 4

Expert Comment

by:thedude112286
ID: 12020530
Just compile this as a dll.

[ClassInterface(ClassInterfaceType.AutoDual)] // the key to exposing a C# app as a ActiveX object
public class YourClass{
      // all your methods and stuff go here
}

Good info can be found at http://www.devhood.com/messages/message_view-2.aspx?thread_id=16569.
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 3

Author Comment

by:hans_larson
ID: 12023333
thanks, now how to I use the ASP intrinsic objects in C#?

Example: How do I use Response.Write instead of using return?
0
 
LVL 4

Expert Comment

by:thedude112286
ID: 12029944
Why not try this:

[ClassInterface(ClassInterfaceType.AutoDual)] // the key to exposing a C# app as a ActiveX object
public class YourClass{
      public string GetMsg() { return "Hello World"; }
}

And in asp:
Response.Write(YourClassObject.GetMsg())

Or is this not what you are talking about?
0
 
LVL 3

Author Comment

by:hans_larson
ID: 12030953
That will work to just write the output for a single line of text. I could also get away with concatenating a really long string, but that will just kill performance.

I need to be able to access the ASP objects to use the Request and Session objects also.
0
 
LVL 4

Expert Comment

by:thedude112286
ID: 12060187
[ClassInterface(ClassInterfaceType.AutoDual)] // the key to exposing a C# app as a ActiveX object
public class YourClass{
      HttpResponse Response;
      HttpRequest Request;
      HttpSessionState Session;

      public YourClass(HttpResponse response, HttpRequest request, HttpSessionState session) {
            Response = response;
            Request = request;
            Session = session;
      }

      public void GetMsg() {
            Response.Write("Hello World");
      }
}

See if this works
0
 
LVL 4

Accepted Solution

by:
thedude112286 earned 125 total points
ID: 12060190
You would call the class in my last post like this:

YourClass c = new YourClass(Response, Request, Session);
c.GetMsg();
0
 
LVL 3

Author Comment

by:hans_larson
ID: 12060196
Thanks. I will try this and let you know if it works. Why do I need to call the class?

Can't I just call it from ASP using Server.CreateObject ?
0
 
LVL 4

Expert Comment

by:thedude112286
ID: 12060961
That should work.  Treat it just as you would a normal COM object.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question