Solved

Server.CreateObject parameters problem

Posted on 2003-11-21
8
1,045 Views
Last Modified: 2012-05-04
Why does this work:
Set DBObj = Server.CreateObject("BuyersFund.SimpleTest.ClassTest")

but this doesn't work:
Set DBObj = Server.CreateObject("BuyersFund.SimpleTest","ClassTest")

???

Here is the C# DLL source code:

using System;

namespace BuyersFund
{
      namespace SimpleTest
      {
            /// <summary>
            /// Summary description for Class1.
            /// </summary>
            public class ClassTest
            {
                  public ClassTest()
                  {
                        //
                        // TODO: Add constructor logic here
                        //
                  }

                  public string Speak()
                  {
                        return "Buyers Fund Simple Test";
                  }
            }
      }
}
0
Comment
Question by:knowlton
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 12

Expert Comment

by:kingsfan76
ID: 9800962
because ClassTest is a method of SimpleTest,
in Object Oriented language you invoke the method by "Object.Method", you cannot invoke by "Object, method".  If you sepereate the ClassTest method from SimpleTest, the system wouldn't know where to look for method ClassTest().  in a word, object and sub-object and their functions are link by a dot "."

hope i'm making some sense   :-)
0
 
LVL 5

Author Comment

by:knowlton
ID: 9800972
Some....


So

Set DBObj = Server.CreateObject("BuyersFund.SimpleTest.ClassTest")

and

Set DBObj = Server.CreateObject("BuyersFund.SimpleTest","ClassTest")


are not two ways to say the same thing?
0
 
LVL 5

Author Comment

by:knowlton
ID: 9800974
How many different versions of CreateObject(  )  are there?  It seems to accept either one param or two params?
0
 
LVL 12

Expert Comment

by:kingsfan76
ID: 9801102
actually that's an interesting question.  I don't think how many version there are, I know there's "Server.CreateObject()" and "CreateObject()", they are slightly different.  but i don't think that is relavent here.

Here's some interesting things i found.
This is what is described in MSDN:

Server.CreateObject( progID)
Parameters:
progID
Specifies the type of object to create. The format for progID is [Vendor.]Component[. Version].

From another source:

Server.CreateObject (ProgID [,ProgID Constructor parameter list])

so it seems you can use more than one params, but the other params must be constructor parameter list.  In your case, "ClassTest" is not a constructor parameter, it's an instance.

For example, if you "ClassTest" takes parameter,
for instance, something like this   ClassTest(String inStr) { .....}
then you might be able to use

Server.CreateObject ("BuyersFund.SimpleTest.ClassTest","something")

in this case, the string "something" will pass into the ClassTest() as constructor parameter for the method.
But then I haven't tested these codes, so I can't be sure this is how it works.  but hope it helps.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 12

Accepted Solution

by:
kingsfan76 earned 200 total points
ID: 9801213
here's the reference web site:

http://www.stryon.com/createobject.asp#ServerCreateObject1

the example in there is a java object.  But I don't think the language matters with DLLs.  Assuming that they are correct, with your code:

Set DBObj = Server.CreateObject("BuyersFund.SimpleTest","ClassTest")

"ClassTest" will be treated as a string input for .SimpleTest, but .SimpleTest does not have any input params, so it throws an exception.
0
 
LVL 28

Expert Comment

by:sybe
ID: 9802592
>> How many different versions of CreateObject(  )  are there?  It seems to accept either one param or two params?

The second parameter of Server.CreateObject is optional and is being used to indicate on which server the component is registered.

Set MyObject = Server.CreateObject("myobjectreference", "servername")

Of course the server should be accessible from the machine on which the script is running, and there should be sufficient rights on the server to create the object.

"servername" can also be an ip-number
0
 
LVL 28

Assisted Solution

by:sybe
sybe earned 150 total points
ID: 9802596
From the Help file:

Visual Basic Scripting Edition  
CreateObject Function
Creates and returns a reference to an Automation object.

CreateObject(servername.typename [, location])
Arguments
servername
Required. The name of the application providing the object.
typename
Required. The type or class of the object to create.
location
Optional. The name of the network server where the object is to be created.
0
 
LVL 21

Assisted Solution

by:ap_sajith
ap_sajith earned 150 total points
ID: 9805228
FUNCTION:  CreateObject( )

--------------------------------------------------------------------------------
CreateObject(ServerName.TypeName, RemoteServerName)
 
The CreateObject function is used to create an object of the type specified in the argument.
 
The Set statement assigns the object reference to a variable or property. The keyword Nothing is used to unassign the object reference from the variable or property. Good programming techniques require that you unassign all objects before you exit the program.
 
There one mandatory and one optional argument.
 
ServerName.TypeName
 
ServerName is the name of the application that provides the object. TypeName is the type (class) of object to be created.
 
RemoteServerName
 
The optional RemoteServerName argument was added in verson 5.0 and is used to create an object on a remote server. It is the name of the remote server. To use this argument, the internet security must be turned off.
 
In this first example, we create an instance of Microsoft Word.
 
Code:
<%
Set objWrd = CreateObject("Word.Application")
...
' Place any code you desire here
...
Set objWrd = Nothing
%>
 
In this second example, we create an object on a remote site.
 
Code:
<%
Set objFarAway = CreateObject("Word.Application", "FarAwayServerName")
...
' Place any code you desire here
...
Set objFarAway = Nothing

Creating an object on a remote server can only be accomplished when Internet security is turned off. You can create an object on a remote networked computer by passing the name of the computer to the servername argument of CreateObject. That name is the same as the machine name portion of a sharename. For a network share named "\\myserver\public", the servername is "myserver". In addition, you can specify servername using DNS format or an IP address.
The following code returns the version number of an instance of Excel running on a remote network computer named "myserver":


Function GetVersion
Dim XLApp
Set XLApp = CreateObject("Excel.Application", "MyServer")
GetVersion = XLApp.Version
End Function
An error occurs if the specified remote server does not exist or cannot be found.
%>

Basically, the syntax differs for Inprocess components and  DCOM components..
eg:

DCOM : Set object = Server.CreateObject("ProgId", "computername")
 
In-process : Set object = Server.CreateObject("ProgId")

Again, For Remote Data Services, the create object syntax could be like...


HTTP : Set object = DataSpace.CreateObject("ProgId", "http://awebsrvr")
 
HTTPS : Set object = DataSpace.CreateObject("ProgId", "https://awebsrvr")
 
DCOM : Set object = DataSpace.CreateObject("ProgId", "computername")
 
In-process : Set object = DataSpace.CreateObject("ProgId", "")

I know i'm repeating some of the things what the other guys mentioned.. how ever, i feel that this is a much more detailed description than those provided..

Cheers!!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Translate a cURL request to Classic ASP 4 415
replace quotes with UTF-8 character 38 83
Forcing form refresh - classic ASP 7 59
INNER JOIN ? 8 41
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now