Solved

Trying to register a C# DLL as a COM object

Posted on 2006-07-19
3
225 Views
Last Modified: 2006-11-18
First off...much luck on the explanation that solves my problem. However, I know it is somehow possible. Anyway, I have the need to expose some C# objects to an application that works with COM objects. (QuickTest Professional to be exact). We have a lot of tests written in C#...and we want to avoid a rewrite to integrate them with Mercury. So...I have done this sample example that is very simple: Here it is:

Example (C#): Creating a Simple .NET Component
1.      Create a new ClassLibrary project called TestComponent.
2.      Add the following class to the project:
public class Class1
{
            public Class1()
            {
            }
            public int Sum(int num1, int num2)
            {
                  return num1 + num2;
            }
}
3.      In the project settings set the Register for COM Interop option to True
4.      Build the project.
5.      By default, the component ProgID is the <Project Name>.<ClassName>.
6.      In QuickTest, use this code to access the Class1 Sum method.
' Create a TestComponent.Class1 instance
Set oTestCom = CreateObject("TestComponent.Class1")
MsgBox oTestCom.Sum(5,7) 'opens a MessageBox with the number 12


I can tell you for a fact...it is far from that simple. Apparantly...my issue is with getting this DLL exposed for COM. For the love of everything good...how do I do that? My neck is hurting..my ego has been beaten into submission. HELP PLEASE! Thank you for any submissions.
0
Comment
Question by:SGyves
  • 2
3 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 17139708
The prog ID for a COM component is really Namespace.Class, not Project.Class.  It just happens that project name and namespace are the same by default.

You can control the ProgID of a class with the ProgID attribute:

[ProgID("TestComponent.Class1")]

Bob
0
 

Author Comment

by:SGyves
ID: 17140814
Compiler is not liking that statement. Do I need a specific "using" statement for that?
0
 

Author Comment

by:SGyves
ID: 17140825
Hey...but I used namespace.class....AND IT WORKED....headache gone. Thanks
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Entity Framework 7 43
Coding C# in Linux 8 71
Webform example, External Authentication Services, OAUTH, asp.net 4.6.2 1 34
Expression Evaluater 3 27
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

832 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