473,396 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Make .NET methods visible to COM

Hello,

I followed the instructions on
http://msdn.microsoft.com/library/de...llnetfrcom.asp
to call .NET class methods from the ActiveX Test Container
(tstcon32.exe) and I can load my control, but there aren't any methods
I can invoke.

However, in ActiveXplorer I can view the methods on the component
(screenshot:
http://idaho.cybernited.be/upload/te...veXplorer.JPG), but this
tool doesn't support invoking them.

Am I forgetting somehting ?

Any help appreciated.

Here's my code:

the interface:

using System;
using System.Collections.Generic;
using System.Text;

namespace COMVisibleMethods
{
public interface ICOMCallable
{
int SumOfTwo(int a, int b);
string GetCurrentDateTime();
}
}

the code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Reflection;
using Microsoft.Win32;

namespace COMVisibleMethods
{
public partial class Math : UserControl, ICOMCallable
{
public Math()
{
InitializeComponent();
}

public string GetCurrentDateTime()
{
return DateTime.Now.ToLongDateString() + " " +
DateTime.Now.ToLongTimeString();
}

public int SumOfTwo(int a, int b)
{
return a + b;
}

[ComRegisterFunction()]
public static void RegisterClass(string key)
{
// Strip off HKEY_CLASSES_ROOT\ from the passed key as I
don't need it
StringBuilder sb = new StringBuilder(key);
sb.Replace(@"HKEY_CLASSES_ROOT\", "");

// Open the CLSID\{guid} key for write access
RegistryKey k =
Registry.ClassesRoot.OpenSubKey(sb.ToString(), true);

// And create the 'Control' key - this allows it to show
up in
// the ActiveX control container
RegistryKey ctrl = k.CreateSubKey("Control");
ctrl.Close();

// Next create the CodeBase entry - needed if not string
named and GACced.
RegistryKey inprocServer32 =
k.OpenSubKey("InprocServer32", true);
inprocServer32.SetValue("CodeBase",
Assembly.GetExecutingAssembly().CodeBase);
inprocServer32.Close();

// Finally close the main key
k.Close();
}

[ComUnregisterFunction()]
public static void UnregisterClass(string key)
{
StringBuilder sb = new StringBuilder(key);
sb.Replace(@"HKEY_CLASSES_ROOT\", "");

// Open HKCR\CLSID\{guid} for write access
RegistryKey k =
Registry.ClassesRoot.OpenSubKey(sb.ToString(), true);

// Delete the 'Control' key, but don't throw an exception
if it does not exist
k.DeleteSubKey("Control", false);

// Next open up InprocServer32
RegistryKey inprocServer32 =
k.OpenSubKey("InprocServer32", true);

// And delete the CodeBase key, again not throwing if
missing
k.DeleteSubKey("CodeBase", false);

// Finally close the main key
k.Close();
}
}
}
-
JB

Aug 28 '06 #1
1 3731
Hi,

Usually I decorate my COM's visible classes with:
[ClassInterface(ClassInterfaceType.None)]

[Guid("A0F6A88F-F20E-445f-8F80-95EA780AAB52")]
Not sure if this is what you are missing though.
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Janiek Buysrogge" <J.*********@Televic.comwrote in message
news:f8********************************@4ax.com...
Hello,

I followed the instructions on
http://msdn.microsoft.com/library/de...llnetfrcom.asp
to call .NET class methods from the ActiveX Test Container
(tstcon32.exe) and I can load my control, but there aren't any methods
I can invoke.

However, in ActiveXplorer I can view the methods on the component
(screenshot:
http://idaho.cybernited.be/upload/te...veXplorer.JPG), but this
tool doesn't support invoking them.

Am I forgetting somehting ?

Any help appreciated.

Here's my code:

the interface:

using System;
using System.Collections.Generic;
using System.Text;

namespace COMVisibleMethods
{
public interface ICOMCallable
{
int SumOfTwo(int a, int b);
string GetCurrentDateTime();
}
}

the code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Reflection;
using Microsoft.Win32;

namespace COMVisibleMethods
{
public partial class Math : UserControl, ICOMCallable
{
public Math()
{
InitializeComponent();
}

public string GetCurrentDateTime()
{
return DateTime.Now.ToLongDateString() + " " +
DateTime.Now.ToLongTimeString();
}

public int SumOfTwo(int a, int b)
{
return a + b;
}

[ComRegisterFunction()]
public static void RegisterClass(string key)
{
// Strip off HKEY_CLASSES_ROOT\ from the passed key as I
don't need it
StringBuilder sb = new StringBuilder(key);
sb.Replace(@"HKEY_CLASSES_ROOT\", "");

// Open the CLSID\{guid} key for write access
RegistryKey k =
Registry.ClassesRoot.OpenSubKey(sb.ToString(), true);

// And create the 'Control' key - this allows it to show
up in
// the ActiveX control container
RegistryKey ctrl = k.CreateSubKey("Control");
ctrl.Close();

// Next create the CodeBase entry - needed if not string
named and GACced.
RegistryKey inprocServer32 =
k.OpenSubKey("InprocServer32", true);
inprocServer32.SetValue("CodeBase",
Assembly.GetExecutingAssembly().CodeBase);
inprocServer32.Close();

// Finally close the main key
k.Close();
}

[ComUnregisterFunction()]
public static void UnregisterClass(string key)
{
StringBuilder sb = new StringBuilder(key);
sb.Replace(@"HKEY_CLASSES_ROOT\", "");

// Open HKCR\CLSID\{guid} for write access
RegistryKey k =
Registry.ClassesRoot.OpenSubKey(sb.ToString(), true);

// Delete the 'Control' key, but don't throw an exception
if it does not exist
k.DeleteSubKey("Control", false);

// Next open up InprocServer32
RegistryKey inprocServer32 =
k.OpenSubKey("InprocServer32", true);

// And delete the CodeBase key, again not throwing if
missing
k.DeleteSubKey("CodeBase", false);

// Finally close the main key
k.Close();
}
}
}
-
JB

Aug 28 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: torbs | last post by:
I am trying to use the methods in quicktimes plugin, but IE generetes an error. I have tried to use the "document.all" instead of getElementById but the results remain the same. It won't recognise...
1
by: PCB | last post by:
Hi all, Not sure if this is possible, but can I change the controls of a command button on a per record bases in a subform. In my case, I would like to make a command button visible only if...
3
by: Susan Bricker | last post by:
Greetings. I have three forms that are open at the same time. They are related and cascading. The first form (frmEventAdd) is the anchor. Each event can have many Trials. The second form is...
2
by: Blue Ocean | last post by:
In standard C, what is the effect of declaring a method extern. In what cases should I use this? Programs that I've compiled with more than one source files and multiple headers still seem to...
16
by: Miguel Dias Moura | last post by:
Hello, i have 5 panels in an ASP.net / VB page. The panel 1 is visible the other 4 are NOT visible. I also have 5 images: image 1, image 2, ..., image5. When i click one of the images,...
7
by: Nader | last post by:
It's easy to make the last row in a datagrid (filled with a table) invisible: datagridObject.Rows.Visible = false BUT if 'i' is not the last row then things go wrong. I even tried: for...
6
by: beginner | last post by:
Hi Everyone, Is there any equivalent version of C's static function in Python. I know I can make a class function private by starting a function name with two underscores, but it does not work...
0
by: Subodh | last post by:
Hi All, I am creating a C++/CLI project which will be consumber by C# application. I have added comments for my properties/Methods in my C++/CLI project using .net XML tags, but when i...
3
by: jasonmwilkerson | last post by:
Can you access properties (Text, Visible, etc...) on server controls (i.e. TextBox, Label, etc...) from javascript? I am trying to toggle the visibility of a Label clientside. <script...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.