473,666 Members | 2,713 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Doubt in Activator.Creat eInstance

Hi I have one doubt in C#.

I created one component called CustomTesting in VC7. The DLL
contains Two Method called Execute and SetOCxInterface . I want to Load the
Dll
from my Sample application(whi ch is in C#) with out Addeing it in
Reference. ie i want to load it dynamically with the help of
Activator.Creat eInstance. Then i want to access those method. How to Do
that?

onject inst;
Type myType1= Type.GetTypeFro mProgID("Custom Testing.Callbac kImpl.1");
inst = Activator.Creat eInstance(myTyp e1);

When i say inst . the intellicence is not showing the above Two methods
(Execute and SEtOCxInterface ). For that i have to cast to the Default
interface .. correct?
TO cast it i hve to include it in a Namespace list. Since it is a
dynamically loaded dll , how can i added into namespace list dyna,ically?
Plese send a solution and give me the dample code.

Note I am herewith sending the VC& Code(which the component is created).
Regards,
R.Baskar


Nov 15 '05 #1
2 1632

"Baskar RajaSekharan" <rb*@srasys.co. in> wrote in message
news:eg******** ******@tk2msftn gp13.phx.gbl...
Hi I have one doubt in C#.

I created one component called CustomTesting in VC7. The DLL
contains Two Method called Execute and SetOCxInterface . I want to Load the Dll
from my Sample application(whi ch is in C#) with out Addeing it in
Reference. ie i want to load it dynamically with the help of
Activator.Creat eInstance. Then i want to access those method. How to Do
that?

onject inst;
Type myType1= Type.GetTypeFro mProgID("Custom Testing.Callbac kImpl.1");
inst = Activator.Creat eInstance(myTyp e1);

When i say inst . the intellicence is not showing the above Two methods
(Execute and SEtOCxInterface ). For that i have to cast to the Default
interface .. correct?
TO cast it i hve to include it in a Namespace list. Since it is a
dynamically loaded dll , how can i added into namespace list dyna,ically?
Plese send a solution and give me the dample code.

Note I am herewith sending the VC& Code(which the component is created).
Regards,
R.Baskar


Activator.Creat eInstance returns an "Object", so it has no (useful)
properties/methods.
You need to cast it into something you can use.

The way this usually works (correct me if I'm wrong) is that you have a
base-class
or interface that you know how to work with. All created instances can be
cast to that
specific class (or interface), so then you (and Intellisense) know what
properties/methods
are available.

Using reflection it is probably possible to use any method, but this is more
complicated
(read: I don't know (yet) how to do it :-)
Hans Kesting
Nov 15 '05 #2

"Hans Kesting" <ne***********@ spamgourmet.com > wrote in message
news:uC******** ******@TK2MSFTN GP10.phx.gbl...
Using reflection it is probably possible to use any method, but this is more complicated
(read: I don't know (yet) how to do it :-)


No, it is not, practically.

For any sort of "add in mechanism" to work, the using class (loading the add
in) has to KNOW how the add in will look and behave.

Like a contract.

So, while reflection would help to find all methods, you still could only
use the ones which you expect.

And then, an interface or base class is just way more convenient to use.

Simply because basically the only thing you can do with all the other
methods is - ignore them.

Thomas Tomiczek
THONA Software & Consulting Ltd.
(Microsoft MVP C#/.NET)
Nov 15 '05 #3

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

Similar topics

7
12025
by: hazz | last post by:
this is a repost with more concise code (well, for me) and better questions (I hope....) . given the following two classes, my intent is to use either Activator.CreateInstance or InvokeMember pass a token into the instantiated class DBPassword and return a string; ************************************** namespace DBPasswordProvider public class DBPassword {
1
11519
by: Johnny R | last post by:
Hello, I'm loading a Class from Assemly DLL using Activator.CreateInstance. That loaded Class is executed in a worker Thread with no loop. What actually happends when class is loaded using Activator.CreateInstance? If I create same class using Activator.CreateInstance many times will there be multiple instances of that same class created by Activator.CreateInstance?
0
1430
by: Jon Skeet [C# MVP] | last post by:
On Apr 11, 8:40 am, Andrew <And...@discussions.microsoft.comwrote: Okay, that means you've either not given the full classname (including namespace) or it's not in mscorlib or the currently executing assembly, in which case you need to give assembly details as well. The line with testType2 is explicitly trying to find a class called "name". The string "name" and the variable called name are completely independent things.
0
1293
by: =?Utf-8?B?QW5kcmV3?= | last post by:
Found it. string name = Properties.Settings.Default.ClassName.ToString(); //"myproject.myclass, myassembly" format. //name = "ABC.MyClass, Assem" ; Type t = Type.GetType(name); Object obj = Activator.CreateInstance(t); string result = t.InvokeMember("methodName",
0
8438
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8348
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8549
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8636
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7376
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5660
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4356
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2765
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2004
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.