Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

C# ActiveX DLL

Posted on 2004-09-08
11
Medium Priority
?
1,143 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 375 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

722 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