Link to home
Start Free TrialLog in
Avatar of OeilNoir
OeilNoir

asked on

CFOBJECT, Calling a DLL

Hello, Du to the complexity of a task i want my CFApplication to do, i had to make a part of the program into a DLL.

My Question is, how do i call the DLL from Coldfusion? i know the CFOBJECT Tag have something to do with it, but i realy don't know what to do and how the tag work. I need to call a specific function in the DLL and to pass it a value, the function will execute some stuff and put data in the datbase, which will now be available via my CFApps...

Can anyone help me out?
Avatar of bigbadb
bigbadb

You can use the custom tag CFX to call a dll.  I wrote a program to ping a mail server.  You need to setup the tag in the cold fusion admin then you will call the tag as such:

<cfx_name
Host = "#application.mailserver#">

for me host was the variable I was passing.  If you need to return a variable you can do that by simply adding that variable to the call and checking its value after the call.

This should work we have wrote a number of custom tags for this very thing.  Let me know if you need anymore help!!!
Good Luck
Avatar of OeilNoir

ASKER

Thanks for the Help, this may fix my problem and enable me to call the DLL, but so far my attempt to make it work failed... Maybe there is something i missed?

Ok

So here is what i've done :

I create an ActiveX DLL with Visual Basic. and added to it a Class Module called clsGenerateTeam. In the class module there is only one function (so far) and it's called: GenerateTeam
(the Class is set to global multi-use)

i went to the CFAdmin, in the CFX tag section, and gave a name to my Tag : CFX_GenerateTeam

i selected the right library, and finaly, i typed in the procedure name:
GenerateTeam
(i also tried clsGenerateTeam, clsGenerateTeam.GenerateTeam and etc...)

then in my coldfusion app, i called it using that Tag :
<cfx_GenerateTeam strLogin='test'>

it doesn't work, i keep getting the following message :

Error loading CFX custom tag library

The procedure associated with the custom tag CFX_GENERATETEAM (GenerateTeam) was not found in the library
 'c:\Inetpub\path\dll.dll'.

 Please check the ProcedureName entry for this tag in the custom tag database to verify that the procedure listed there is
 exported by the custom tag library.

What am i doing wrong?
Thanks for your help
That is not what he meant...  You created a normal ActiveX DLL, not a CFX Tag.  If your DLL is done properly, and functions correctly as an in-process COM server, and is regeistered on the system as a COM server, then you can use the CFOBJECT tag to call it like this:

Assuming your ProgID is "clsGenerateTeam"

<CFOBJECT ACTION="Create"
  TYPE="COM"
  CLASS="clsGenerateTeam"
  CONTEXT="InProc"
  NAME="GenTeam">
<!--This is a guess as to how you would call it, I dont know how you implemented anything-->
<CFSET GenTeam.GenerateTeam(test)>

If you want to make a CFX Tag, you need to either rewrite the DLL as a Tag or create a "wrapper" tag that calls your DLL for you.  Either way you need to use a language that supports CFX tag creation.  Allaire only supports C and C++, but there are libraries available to build tags in Borland Delphi also.

Heath
Ok, the CFOBJECT Things, the way you described it realy make sence... and i think i understand how it should work... but unfortunatly, it doesn't work :-( now, i get the following error :

Error trying to create object specified in the tag.
 COM error 0x800401F3. Invalid class string

ì'm not very familiar with COM objects, so my error could come from the way i created the DLL... though i don't think so.

i compiled the DLL directly on this computer, so it was automaticaly registered (and data about it can be found in the registry) so, obviously it class is registred correctly, do you have an idea why it wouldn't work?
honestly, I havent ever used a COM object in CF.  What I posted is about as much as I know...  I always make CFX Tags for stuff like this, as it is much more efficient in general.  Maybe someone else has more info.

Heath
I agree with heathprovost I have always used custom tags.  They work well and basically function the same as a DLL (ie reusable, compilied, etc....)
I've used CFOBJECT with some success, albeit it not total success,  One thing to remember, you must specify all arguments to a function or method, even if they are only optional.  CFOBJECT will fail elsewise.  Why don't you give an example of a time when you are getting the "invalid class string".  I'm assuming that you are not getting it at the CFOBJECT statement, but during a future CFSET.  If it is occurring at the CFOBJECT, make sure you entered the correct class string for your COM object.

:) dapperry
YES YES YES YES!!! YOU GIVE ME THE RIGHT HINT!!! hahah
i had this :
<CFOBJECT ACTION="Create" TYPE="COM" CLASS="clsGenerateTeam" CONTEXT="InProc" NAME="GenTeam">
<CFSET GenTeam.GenerateTeam("kenny365")>

but indeed, the class string wasn,t right, i had to specify the DLL so it could find it in the registry.

so i had to put it that way: (wbbb is the name of the dll (wbbb.dll)

<CFOBJECT ACTION="Create" TYPE="COM" CLASS="wbbb.clsGenerateTeam" CONTEXT="InProc" NAME="GenTeam">
<CFSET GenTeam.GenerateTeam("kenny365")>

GREAT =)))) it work now =)

who's going to take the points now? you all helped me a lot!
You can give the pts to others if you want.  If you want you can slip me a question on the side for partial pts.  Glad its working for you now.

:) dapperry
Well... someone post a question here to get the points =)
I think you can just click on one of our comments - where it says 'Accept Comment as Answer'

:) dapperry
Hey everyone,

I recently had the exact same problem as OeilNoir so I just wanted to add a little tip that may help with this sort of thing in the future. I know the problem is solved now, but better late than never, I guess. There's a utility called OLE COM Object Viewer that you'll find in C:\Program Files\Microsoft Visual Studio\Common\Tools\oleview.exe - or simply search for the filename if you don't have that path.

It gives you all kinds of information about the COM objects registered on your system, including their ProgIDs which map to the CLASS attribute of the <CFOBJECT> tag. If you expand the All Objects node and find the classes you're interested in using the (dllname.classname) naming convention you can view the info in the right-hand pane.

Hope this helps,
Rod
ASKER CERTIFIED SOLUTION
Avatar of dapperry
dapperry

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
oups i forgot about this question =) time for me to give the points =)