473,396 Members | 1,815 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.

Doubt in Activator.CreateInstance

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(which is in C#) with out Addeing it in
Reference. ie i want to load it dynamically with the help of
Activator.CreateInstance. Then i want to access those method. How to Do
that?

onject inst;
Type myType1= Type.GetTypeFromProgID("CustomTesting.CallbackImpl .1");
inst = Activator.CreateInstance(myType1);

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 1607

"Baskar RajaSekharan" <rb*@srasys.co.in> wrote in message
news:eg**************@tk2msftngp13.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(which is in C#) with out Addeing it in
Reference. ie i want to load it dynamically with the help of
Activator.CreateInstance. Then i want to access those method. How to Do
that?

onject inst;
Type myType1= Type.GetTypeFromProgID("CustomTesting.CallbackImpl .1");
inst = Activator.CreateInstance(myType1);

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.CreateInstance 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**************@TK2MSFTNGP10.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
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...
1
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...
0
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...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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...

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.