Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

asp and active x dll's 1

Status
Not open for further replies.

agentwalker

Programmer
Jun 10, 2007
31
GB
just having a play with these and got a problem i'm not sure how to fix.

i've create two Active X dll's (below)

This in Component Services is listed as "myApps.Names" and the method as you can see is DisplayNames()
Code:

Function displayName() As String
Dim myName As String
myName = "John Doe"
displayName = myName
End Function



In my asp code I can create an instance of this class and call the method and it displays the string "John Doe" fine.

Now what i'm trying to do is create another COM which references this existing COM, calls the method displayName() and makes an alteration to it. The code for this is below.
Listed in the Component services as makeNames.adjust and method adjustNames
Code:

Function adjustNames() As String
Dim namesObject As New myApps.Names
Set namesObject = System.CreateObject("myApps.Names")
Dim alterNames As String alterNames = namesObject.DisplayName()
namesObject = Nothing
adjustNames = alterNames
End Function



In my asp code i'm doing exactly the same as before creating an instance of this new COM using server.createObject() then calling the adjustNames() method which should display the string "John Doe" again as i'm making no changes to the string at the moment.

heres the asp code
Code:

Dim changeNamesObject
Set changeNamesObject = server.CreateObject("makeNames.adjust")
response.Write(changeNamesObject.adjustNames())



However at the moment i'm getting an error message reading

Error Type:
makeNames (0x800A01A8)
Object required

ANy ideas what I could be doing wrong ?
 
It looks like you have 2 separate DLLS.

The first one is named myApps and has a public creatable class which is named "Names"

The second DLL is named makeNames and has a pulic createable class named "adjust"

Since you are able to create an instance of "Names" then it must be either registered with the OS using regsvr32 or it is was registered using COM+

So was the second DLL also registered?

Lets assume it is... change the code in the "adjust" class to be as follows:
[tt]
Function adjustNames() As String
Dim namesObject As New myApps.Names
Dim alterNames As String

alterNames = namesObject.DisplayName()
SET namesObject = Nothing
adjustNames = alterNames
End Function
[/tt]
 
Thanks for the response.

Yep your right, two com objects and i've registered both via Com+, but also tried regsvr32 with not change

I've tried applying your change but still get the problem.
i've tried commenting out various bits and I believe its something to do with this line
Dim namesObject As New myApps.Names

i've tried changing the line to
Dim namesObject As myApps.Names - without the New

But still the same.

Is there a special thing you have to set when you make use of another registered COM ?

in VB6 it seems to see the created object ok as it gives me inteli sense on it (showing its methods)

 
Is there a special thing you have to set when you make use of another registered COM ?

Yes! How could I forget?!? If you wish to use early binding and refer to the object by name then you must create a Reference.

To do this, open the 2nd DLL up in the development environment and click "Project" on the menu bar across the top... then choose "References" from the drop-down menu. Find the name of the 1st DLL in the list of registered components and click the checkbox next to its name.

Now you have to recompile it. If binary compatibility is turned on then you are good to go, if not you might need to re-register the object. If it tells you "permission denied" when attempting to recompile the problem is it is referenced by some program that is still running. Many times if this happens you can fix it by restarting the COM+ package in the Component Services admin tool.
 
You could also do late binding and skip the reference. It is a bit slower and you don't get Intillisense within the project but it is easier since you don't need to make the reference and worry about binary compatibility.
[tt]
Function adjustNames() As String
Dim namesObject As Object
Dim alterNames As String

'create late-bound object here:
Set namesObject = CreateObject("myApps.Names")

alterNames = namesObject.DisplayName()
SET namesObject = Nothing
adjustNames = alterNames
End Function[/tt]
 
Thanks, forgot to mention in my previous post that i've already got the 1st COM referenced in your reply. Without this reference Visual Studio wouldn't give me the inteli sense on the created object.

 
Sorry to dig up an old thread but just got round to trying this again and i've tried the late biding method by Sheco and thats working fine now.

Whats makes that particular bit of code 'late biding' as the only real difference I can see is
Dim namesObject As Object

By this late biding do you mean you set namesObject as just a generic object then you create the binding later where as in my original code it didn't create the generic object just created the object direct.
 
With early binding, the Globally Unique ID of the object you wish to use is compiled into the project. The compiler knows exactly the name and datatype of every input parameter, and also the datatype of any return values. If any of these things change, a new GUID will be issued and binary compatibility will be broken.

With late binding, these all of these things have to be "looked up" in the registry at runtime. This is slower but more flexible.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top