473,511 Members | 15,630 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 96252
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
2260
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
11086
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
15604
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
6556
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
2037
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
2279
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
6824
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
1815
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
3687
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
7024
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
7242
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
7138
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...
0
7353
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7418
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...
1
7075
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...
1
5063
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4737
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...
0
3222
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
781
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.