473,320 Members | 1,902 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,320 software developers and data experts.

System.Activator.CreateComInstanceFrom

Hello to all and hope everyone on holiday is enjoying themselves!!

I am studying this namespace and method. In the docs it says:

"Creates an instance of the COM object whose name is specified, using the
named assembly file and the constructor that best matches the specified
parameters."

The syntax is:

Public Overloads Shared Function CreateComInstanceFrom( _
ByVal assemblyName As String, _
ByVal typeName As String _
) As ObjectHandle
End Function

Is my understanding correct to say we could create an instance of say EXCEL
without add a reference in the project? Probably not but here is what I
tried to do. And yes I know it is easier to add a reference than to do it
this way. I am just the curious type.

CreateComInstanceFrom("EXCEL.EXE", "Microsoft.Office.Core")

No instance of EXCEL appeared in my Task List though. Any thoughts on this
method?
Nov 20 '05 #1
5 3920
What you really want is:

Dim xApp As Object = Microsoft.VisualBasic.CreateObject("Excel.Applicat ion")

And while this will indeed create an instance without adding a reference,
you will have to operate on the object completely through late-bound
techniques, whether you use VB's native late-bound access (with Option
Strict Off) or Reflection. In either case, you'll get no intellisense and
lose all type safety.

-Rob Teixeira [MVP]
"scorpion53061" <sc************@nospamhereeveryahoo.com> wrote in message
news:Ob**************@TK2MSFTNGP11.phx.gbl...
Hello to all and hope everyone on holiday is enjoying themselves!!

I am studying this namespace and method. In the docs it says:

"Creates an instance of the COM object whose name is specified, using the
named assembly file and the constructor that best matches the specified
parameters."

The syntax is:

Public Overloads Shared Function CreateComInstanceFrom( _
ByVal assemblyName As String, _
ByVal typeName As String _
) As ObjectHandle
End Function

Is my understanding correct to say we could create an instance of say EXCEL without add a reference in the project? Probably not but here is what I
tried to do. And yes I know it is easier to add a reference than to do it
this way. I am just the curious type.

CreateComInstanceFrom("EXCEL.EXE", "Microsoft.Office.Core")

No instance of EXCEL appeared in my Task List though. Any thoughts on this
method?

Nov 20 '05 #2
I know about late binding.

What is the purpose of System.Activator.CreateComInstanceFrom method? Do you
know of a code sample or can you devise one that uses it?
Nov 20 '05 #3
It's sort of the same thing I showed you, but it assumes you have a runtime
callable wrapper assembly.
You should be able to use this, for example, with the Office PIAs. But that
being the case, you're better off referencing the PIAs directly.

-Rob Teixeira [MVP]

"scorpion53061" <sc************@nospamhereeveryahoo.com> wrote in message
news:uF**************@TK2MSFTNGP09.phx.gbl...
I know about late binding.

What is the purpose of System.Activator.CreateComInstanceFrom method? Do you know of a code sample or can you devise one that uses it?

Nov 20 '05 #4
Sure but indulge me for a second.....

If I were to use this could you show me how it would be written?

CreateComInstanceFrom("Excel.dll", "C:\Documents and Settings\Kelly
Martens\My Documents\Visual Studio
Projects\XMLSettingsDemo\obj\Interop.Excel.dll")

When I do this no instance shows in my task manager demonstrating that an
Excel instance is alive...Why or how did I write this wrong?
"Rob Teixeira [MVP]" <RobTeixeira@@msn.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
It's sort of the same thing I showed you, but it assumes you have a runtime callable wrapper assembly.
You should be able to use this, for example, with the Office PIAs. But that being the case, you're better off referencing the PIAs directly.

-Rob Teixeira [MVP]

"scorpion53061" <sc************@nospamhereeveryahoo.com> wrote in message
news:uF**************@TK2MSFTNGP09.phx.gbl...
I know about late binding.

What is the purpose of System.Activator.CreateComInstanceFrom method? Do

you
know of a code sample or can you devise one that uses it?


Nov 20 '05 #5
You should be getting an error.
The arguments are (assembly, typeName), which in this case would be the full
path to the DLL, followed by the type name, which has to be an exported type
that has a constructor (IOW, a class where the underlying COM object can be
instantiated from CoCreateInstance - for example, "Excel.ApplicationClass").
If you use this type name, you will see an instance of Excel.exe on the
running process list. However, this method gives you an object handle
instance, which is fine for dealing with cross-app-domain object
indirection, but stick to the Microsoft.VisualBasic.CreateObject method if
you want to directly call methods from this using late-bound calls or
reflection.

-Rob Teixeira [MVP]

"scorpion53061" <sc************@nospamhereeveryahoo.com> wrote in message
news:eZ**************@TK2MSFTNGP09.phx.gbl...
Sure but indulge me for a second.....

If I were to use this could you show me how it would be written?

CreateComInstanceFrom("Excel.dll", "C:\Documents and Settings\Kelly
Martens\My Documents\Visual Studio
Projects\XMLSettingsDemo\obj\Interop.Excel.dll")

When I do this no instance shows in my task manager demonstrating that an
Excel instance is alive...Why or how did I write this wrong?

Nov 20 '05 #6

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

Similar topics

3
by: Guy | last post by:
im running some code to instantiate a form, based on the name selected at runtime. Im using System.Activator.CreateInstance to load a form by its fully typed name, here is the code.... string...
1
by: John Jenkins | last post by:
Hi, I have a fairly simeple question. What are the differences between Assembly.CreateInstance and System.Activator.CreateInstance? I had read that one maps to the other, however when I use...
3
by: System.Reflection Activator | last post by:
************************************** //Load the Assembly Assembly a = Assembly.LoadFrom(sAssembly); //Get Types so we can Identify the Interface. Type mytypes = a.GetTypes(); BindingFlags...
2
by: aallee83 | last post by:
i'm new in asp.net after develop my solution i copied it on the server where I want it to run but something cares... WHAT?!?! thank you in advance File or assembly name System, or one of its...
1
by: Rui Macdonald | last post by:
I trying some asp from angGoGo PhotoControl and when I star it on my computer always gives the following message, Can you please help me? :-( ------------------------------------------- ...
2
by: Doug | last post by:
I've installed ASP.NET onto our web server (Win2k/unsure of IIS version) this morning. I created a simple ASPX page in Notepad that writes out an asp:Label control to the page and dynamically...
0
by: Junoti | last post by:
I've read several posts out there that state that setting typeFilterLevel="Full" on the client and/or server will correct this issue, however I'm still unable to get around it. I can successfully...
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...
7
by: WTH | last post by:
I am now aware (I am primarily a C++ developer) that in C# if you reference the same interface from the same file in two different projects the types are actually incompatible. I found this out...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

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.