473,585 Members | 2,552 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.CreateOb ject 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("S ome.Application ")

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

Dim obj as Object
obj = CreateObject("S ome.Application ")


object obj =
Activator.Creat eInstance(Type. GetTypeFromProg ID("Some.Applic ation"));

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.Creat eInstance
(Type.GetTypeFr omProgID("Power builder.Applica tion"));

//below produces the following errors:
//'object' does not contain a definition for 'LibraryList'
objPB.LibraryLi st = "c:\\web\\medsr g08.pbd";
objPB.MachineCo de = False;

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

Dim obj as Object
obj = CreateObject("S ome.Application ")
object obj =
Activator.Crea teInstance(Type .GetTypeFromPro gID

("Some.Applicat ion"));
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.dl l.

-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.Creat eInstance
(Type.GetTypeFr omProgID("Power builder.Applica tion"));

//below produces the following errors:
//'object' does not contain a definition for 'LibraryList'
objPB.LibraryLi st = "c:\\web\\medsr g08.pbd";
objPB.MachineCo de = False;

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

Dim obj as Object
obj = CreateObject("S ome.Application ")
object obj =
Activator.Crea teInstance(Type .GetTypeFromPro gID

("Some.Applicat ion"));
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
2264
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 problem with the access right. I configured the IIS so that for this site E:\Websites\myASPSite the ASP application (regular old ASP, no ASP.NET code!)...
14
11105
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 assigned to a session variable. I dont assign any record sets to session variables in my code. I assign values to the session variables though. The...
6
15621
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 setobjShell=Server.CreateObject("WScript.Shell"), I get the error VB err= 5,Invalid procedure call or argument
1
6565
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 server don´t response right. xmlHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")
12
2054
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 have written the following three class: 1.icoCORE_test 2.icoMINDB_test
2
2287
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 when the user excecutes an action on a smart tag. Almost always, GetObject fails, which causes CreateObject to be called. At that point, PPT locks...
7
6828
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 VS2005 (no errors and does exactly what it should) BUT if I build it and then try to run the .exe on the same computer it fails with: "Unhandled...
0
1820
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 connection to a foxpro database in that folder. I have a problem with even accessing that path through SYSTEM.IO.File.EXists and Peter Bromberg...
1
3691
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 Server Pages Event Category: None Event ID: 5 Date: 11/27/2006 Time: 9:17:08 AM
3
7032
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 the object creation happens with Server.CreateObject, I would like to create 'visible scenarios' that i create with code to show people that...
0
7836
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...
0
8336
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7950
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...
1
5710
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3835
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2343
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
1
1447
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1175
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.