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

CreateObject in C#

pa
What's the C# equivalent to the VB 'CreateObject' function.
I know there's a Server.CreateObject but I need to do this
from a windows app that doesn't use the web.

Here's the VB code I want to convert.

Dim obj as Object
obj = CreateObject("Some.Application")

Thanks for your help
pa
Nov 15 '05 #1
3 96216
Here's the VB code I want to convert.

Dim obj as Object
obj = CreateObject("Some.Application")


object obj =
Activator.CreateInstance(Type.GetTypeFromProgID("S ome.Application"));

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 15 '05 #2
pa
Mattias,
Thanks for the quick response. However, when i run the
code i get an error trying to call one of the objects
methods:

//this compiles fine
object objPB = Activator.CreateInstance
(Type.GetTypeFromProgID("Powerbuilder.Application" ));

//below produces the following errors:
//'object' does not contain a definition for 'LibraryList'
objPB.LibraryList = "c:\\web\\medsrg08.pbd";
objPB.MachineCode = False;

thanks
pa
-----Original Message-----
Here's the VB code I want to convert.

Dim obj as Object
obj = CreateObject("Some.Application")
object obj =
Activator.CreateInstance(Type.GetTypeFromProgID

("Some.Application"));
Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
.

Nov 15 '05 #3
That's because you have only an object reference, not a strongly
typed reference to the COM object.

This is basic stuff, I suggest you take some online tutorials
as basics for object-oriented programming and strong-typed
languages such as .NET/C#. VB is not a strong-typed language
(well, not very strong typed, it has a little), so this is
probably new to you.

The way Mattias mentioned is the quick and dirty way.
You don't have a strong-typed reference, so if you wish
to call the LibraryList property on the object, you'll
have to use reflection to get an handle to the
PropertyInfo for that object, etc.

The preferred way is to import the typelib for the COM
object and let .NET create a .NET wrapper around the COM
object for you.

If you're using VS.NET, just simple add a reference to
the COM object by Project->Add Reference and select the
COM tab and find your COM library.

If you're not using VS.NET, use the tlbimp.exe utility
and give it the DLL that hosts the COM object you want
like:

tlbimp PowerBuilder.dll.

-c
"pa" <pv*****@yahoo.com> wrote in message
news:03****************************@phx.gbl...
Mattias,
Thanks for the quick response. However, when i run the
code i get an error trying to call one of the objects
methods:

//this compiles fine
object objPB = Activator.CreateInstance
(Type.GetTypeFromProgID("Powerbuilder.Application" ));

//below produces the following errors:
//'object' does not contain a definition for 'LibraryList'
objPB.LibraryList = "c:\\web\\medsrg08.pbd";
objPB.MachineCode = False;

thanks
pa
-----Original Message-----
Here's the VB code I want to convert.

Dim obj as Object
obj = CreateObject("Some.Application")
object obj =
Activator.CreateInstance(Type.GetTypeFromProgID

("Some.Application"));
Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
.

Nov 15 '05 #4

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

Similar topics

0
by: Roland Johann | last post by:
On my Windows Server 2003 Web Edition I have installed an application which offers some OLE Automation Objects. On my local system (W2k Prof) it works fine but on my server 2003 I have a big...
14
by: wk6pack | last post by:
Hi, I'm getting this error on my asp page intermittently. One day it is fine, another day, it crashes a lot. I have searched the web and microsoft on this and they say it is a recordset...
6
by: MacKenzie | last post by:
The statement in an asp page: dim objShell Set objShell = WScript.CreateObject("WScript.Shell") now gives this error: VB err= 424,Object required If I use...
1
by: Raúl Martín | last post by:
I´ve a function in asp that run correctly but If I tried to change it forasp.net in asp: xmlHTTP = CreateObject("Microsoft.XMLHTTP") And I thought to use this sentence for asp.net but the...
12
by: karen | last post by:
Hi all : this is going to be a long post. So i apologize in advance :) i am converting a java program in VB right now. I am a java programmer by trade. so i am no expert in this department. I...
2
by: C Williams | last post by:
Hi, I am having some problems with CreateObject and Powerpoint. I'm working from VB.NET with Powerpoint 2003. The code below is only ever called when powerpoint is already open. It's called...
7
by: dlasusa | last post by:
Sorry if this is the wrong group...I THINK I got to the right place...(oh...and I'm a newbie programmer...so please be gentle) Anyway I have a program that works fine when I run it from within...
0
by: quintesv | last post by:
hi all, Running VS.2003 , framework 1.1. I have a COM object written in Delphi which im trying to call through ASP.NET. The COM object connects to a folder on another machine and opens a...
1
by: Lynn Zou | last post by:
In our system , we use an ASP page to upload files but sometimes it doesnot work as it suppose to do and we found error log in Application Error as: Event Type: Error Event Source: Active...
3
by: Sagar | last post by:
I am working on a project where Server.CreateObject is replaced with CreateObject all over the project. Though I know that this will improve performance in terms of Memory overlhead because of how...
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: 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)...
1
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.