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

x
?
Solved

Convert VB6 ActiveX exe to C#

Posted on 2004-08-25
14
Medium Priority
?
985 Views
Last Modified: 2012-06-21
I am a VB6 programmer.  I had several VB6 programs that run on users computers which needed to use a database connection.  With over 300 users, this was not reasonable to have each program that each user started create a new connection.

So....

I created an ActiveX exe that would only let one instance of itself start and it created and held the ado connection object.  Any program the user would start would get the same reference to the connection ActiveX exe.

I need to recreate this in C#.  I would also like to convert a VB6 project that is basically a DAO pattern implementation that programs can use to get objects from.

How can I recreate the ActiveX exe environment in C# where I can pass references to public classes from out of process programs?

Can anyone help???

Thanks!!
0
Comment
Question by:afpcos
[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
  • 4
  • 3
  • 2
  • +3
14 Comments
 
LVL 3

Expert Comment

by:gillgates
ID: 11898615
You shouldn't need to recreate it.  Try just adding your existing activex component to your C# project and using it.
0
 
LVL 2

Author Comment

by:afpcos
ID: 11901437
I have to recreate it.  My boss wants everything converted to C# so we can move off of VB6.
0
 
LVL 6

Expert Comment

by:DominicCronin
ID: 11917548
I think what you need is the pattern usually referred to as singleton. The idea is that you can't "new" an instance of it; rather a static member is used to provide you with the means of getting the single instance. If you ask for an instance a second time, you get the same one. Here's some code to illustrate the point.

      sealed class ThereCanBeOnlyOne
      {
            private ThereCanBeOnlyOne() { }
            // Initialising this is the only time the object is ever created.
            public static readonly ThereCanBeOnlyOne ItsThisOne = new ThereCanBeOnlyOne();
            public void DoOneishStuff()
            {
                  System.Console.WriteLine("I am one! Hash:" + this.GetHashCode());
            }
      }

      class Test
      {

            static void Main()
            {
                  ThereCanBeOnlyOne one = ThereCanBeOnlyOne.ItsThisOne;
                  ThereCanBeOnlyOne two = ThereCanBeOnlyOne.ItsThisOne;

                  one.DoOneishStuff();
                  two.DoOneishStuff();

                  if (one == two)
                  {
                        System.Console.WriteLine("one == two");
                  }
                  else
                  {
                        System.Console.WriteLine("one != two");
                  }

                  return;
            }
      }

You can easily imagine how a singleton class like this could be used as a broker to hand out and manage connections etc. On the other hand, you should probably also look at ADO.NET and similar technologies, as there are connection pooling implementations that you can just use instead of having to write them yourself.
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 5

Expert Comment

by:Kelmen
ID: 12005077
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpatterns/html/ImpSingletonInCsharp.asp

refer the sample

I also attempted the VB ActiveX EXE option in C#, but turns out .NET is different beast. In short, there's no direct converting of this. You probably need to rewrite the portion of this component.

As you mentioned you worked out that ActiveXExe to cater multi-clients, you may as well worked out either a Web Service, or ASP.NET.

My last work turned out a C# COM+ (ServicedComponent) and expose to COM for VB client to call, using the Singleton approach.

PS. done a stress test later, using native VB COM is much faster than .NET COM. Unless we going to revamp the whole sys using .NET.
0
 
LVL 4

Expert Comment

by:thedude112286
ID: 12011809
[ClassInterface(ClassInterfaceType.AutoDual)] // the key to exposing a C# app as a ActiveX object
public class Singleton {
      public static readonly Instance = new Singleton();

      //put all of your other methods, etc down here
}

Good info can be found at http://www.devhood.com/messages/message_view-2.aspx?thread_id=16569.
0
 
LVL 6

Expert Comment

by:DominicCronin
ID: 12019264
thedude - the point of the singleton is that the only way to instantiate one is to ask singleton to do it. For that your constructor should be private. Kelman's pointer takes you to an interesting article which details a few variations on the theme. My understanding from apfcos's question was that he *doesn't* need to interop between VB6 and dotnet. Otherwise, as you point out Kelmen, your performance will depend a lot on how you implement your interop.
0
 
LVL 2

Author Comment

by:afpcos
ID: 12021458
Sorry if I have not been very active on this question.  I am dealing with hurricanes in florida.

I do not need to interop between VB6 and dotnet.  I completely understand the singleton pattern.  However, from what I understand of Dlls that will not help me.  I understand that DLLs are an "in process" program. If I have two seperate programs that reference the same DLL and run at the same time using the singleton pattern, they will each still get a new instance because of the inprocess issue. ???
0
 
LVL 5

Expert Comment

by:Kelmen
ID: 12042032
The singleton is a private static class.

I developed a COM+ (ServicedComponent, also exposed to VB through COM) that utilize this singleton.
The COM+ is server-actived, enable object-pooling, min = 1. Max >= 1

This idea is from one of my colleague, and I found some posting suggesting this approach (from some MVP, dunno the URL liao, somewhere from Google newsgroup).

Theoritically + initially, I don't believe it work. As after the COM+ back to pooling, I assumed the singletion will ceased as well. However, when testing, it worked as expected. I dunno the inner trick of it.

The singleton only ceased when the COM+ app/package is shutdown, idle-timeout
HTH
0
 
LVL 6

Expert Comment

by:DominicCronin
ID: 12046610
Of course, a COM+ app/package is just a process (assuming it's registered for server rather than library). How about something that will keep a reference at a system level?   Could you run a service simply to host the singleton?
0
 
LVL 5

Expert Comment

by:Kelmen
ID: 12050830
I "guess" the COM+ pooling is the host here. As the private would ceased only if the host/caller (the COM+ component) been GC. Since its in the pool, its not yet queue into the GC, hence the singleton hosting. By using server-activated (performance BIG penalty), there's no concern of in-process, as it only run in out-of-process.

Similar as with the ActiveX EXE in a way. (Frankly, VB ActiveX EXE is run in STA, but the stuff we got is probably in MTA, so far so good...)

Since you mentioned no need Interlop, VB6 overhaul -> C#, may as well redesign the sys, using remoting (can tune as singleton) / web service, which probably can provide the feature as you need.

PS: We adopt the web service at 1st development, but as we need the Interlop, and to utilize ADO + performance, we go for the trick. ADO Recordset can't be serialize unless we work up the xml, stream, and/or serialization stuff, which hinder our timeline and  performance.
0
 
LVL 6

Expert Comment

by:DominicCronin
ID: 12279152
Some good answers have been given. Deletion is not appropriate.
0
 
LVL 1

Accepted Solution

by:
GhostMod earned 0 total points
ID: 12313140
PAQed - no points refunded (of 500)

GhostMod
Community Support Moderator
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

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