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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cfobject to load a dll - asp vs cfm 1

Status
Not open for further replies.

mjarredondo

Programmer
Dec 14, 1999
8
FR
In ASP I use the following code to get the ado to enable absolutepage:

<!-- METADATA TYPE=&quot;TypeLib&quot; FILE=&quot;C:\Program Files\Common Files\System\ado\msado15.dll&quot; -->


I tried to use:

<cfobject type=&quot;COM&quot; action=&quot;Connect&quot; class=&quot;C:\Program Files\Common Files\System\ado\msado15.dll&quot; name=&quot;Mydll&quot;>

I also tried:

<cfobject type=&quot;COM&quot; action=&quot;Connect&quot; class=&quot;msado15.dll&quot; name=&quot;Mydll&quot;>


But I get the following error:
COM error 0x8007000E

What can I use?
 
A couple of things:

The action attribute should be &quot;create&quot; and not &quot;connect&quot;. Connect is used when you already have an instance of the COM object instantiated.

Also, and I'm not sure if the dll file needs to be registered in the first instance (the ASP line), but for CF to use it, it'll have to be. You can do this using the regsvr32.exe program. Just type regsvr32 at a command prompt to see the attributes it takes.

-Tek
 
I tried the connect also and it doesn't work:
<cfobject action=&quot;CONNECT&quot; class=&quot;msado15.dll&quot; name=&quot;adodll&quot;>


Error trying to connect to object.

COM error 0x800401F3. Invalid class string
 
I said to use &quot;create&quot;, not &quot;connect&quot;. Also check to see if the COM object is registered, using the method I wrote in my last post.

-Tek
 
I made sure the dll was registered, and did fix the code to Create and still nothing:

<cfobject action=&quot;create&quot; class=&quot;msado15.dll&quot; name=&quot;MyDll&quot;>

Error trying to create object specified in the tag.

COM error 0x800401F3. Invalid class string
 
In the class attribute, you need to use the ClassName of the COM object, not the name of the .dll source. There's more than one ADO object, so you might need to create instances of the &quot;ADODB.Connection&quot;, &quot;ADODB.Recordset&quot;, &quot;ADODB.Command&quot;, or other classes pertaining to ADO.

Here are some articles with examples that might help:

And this is the MS reference I use for ADO:

-pcorreia
Did I Help? Vote!
 
I am finding this post very helpful in trying to understand how to reference COM objects in ColdFusion. One thing that I am still finding confusing is how to ascertain the ClassName of a particular Object? How is that accomplished?
Thanks,
RR [yingyang]
 
This is a lengthy topic, so I posted the answer off-forum on my own blog. Here's a synopsis:

[ol]
[li]Search the HKEY_CLASSES_ROOT\CLSID key in the registry for a key containing a key named InProcServer32 whose default value is a path to the DLL in question.[/li]
[li]Take the name of that key (the CLSID of the object provided by the DLL in question) and search under HKCR for a key containing a key named CLSID with a default value of that name.[/li]
[li]The name of that key is the class name of the COM object.[/li]
[/ol]

For more detailed instructions, read the post on my blog.
 
It's also important to note that a single DLL can have multiple Classes, each with its own ClassName. If you didn't write the DLL, you need to make sure you know what it's supposed to do.

Also, there is a better way the instantiate your COM objects. It looks more readable, seems faster, and you can now explicitly get rid of the object when your done with it.

Code:
<!--- Now call the Class' Import routine --->
<cfscript>
	//'FMSuite.FundingDoc_ImportExport' is the ClassName
	objImport = CreateObject("COM",
		"FMSuite.FundingDoc_ImportExport");
	
	objImport.UID = "#WEB_USERNAME#";
	objImport.PWD = "#WEB_PASSWORD#";
	objImport.DSN = "#dsource#";
	objImport.Filename = "#cffile.ServerDirectory#\#cffile.serverfile#";
	
	Import_Error = objImport.Import_FundingDoc("fdoc_id", "localCommand");

	// get some status variables
	NumRows = objImport.NumRows;
	NumErrors = objImport.NumErrors;

	ReleaseCOMObject(objImport);
</cfscript>
 
Thanks for that information, thedrider. I didn't know about the ReleaseCOMObject() function (it's documented here). Even if you don't use that function, the JVM will release the object during garbage collection, but on a heavily-loaded server, freeing up the memory earlier could be a real benefit.

As for the difference between <cfobject> and CreateObject(), I haven't seen any difference in performance. Macromedia documentation seems to treat them as different syntaxes for the same functionality, and I suspect that they're just different names for the same code "under the hood". Others have said the same thing. That said, I do prefer the CreateObject() syntax for brevity's sake.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top