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

Implementing ActiveX COM object in Coldfusion template 1

Status
Not open for further replies.

NewFromMattel

Programmer
Jun 24, 2003
41
US
I am treading new waters here, and would like to get some helpful info on using ActiveX in CF.

I have an ActiveX tag installed on our (installed correctly I'm sure). And have an example on how to call it in Visual Basic. But need to call it in CF. Can someone tell me how to do it? Here is my example:

Private Sub Command1_Click()
Dim pdf As Object
Set pdf = CreateObject("TextPDF.TextPDFClass")
pdf.License = "xxxx-xxxxx-xxxx-xxxx"
pdf.StartPDF outputfile:="c:\output.pdf"
pdf.PrintPDF "c:\test1.txt"
pdf.PrintPDF "c:\test2.txt"
pdf.PrintPDF "c:\test3.txt"
pdf.EndPDF
Set pdf = Nothing
End Sub

Now, here's how I've tried to implement it in CF:

<cfobject type=&quot;COM&quot; name=&quot;pdf&quot; class=&quot;TextPDF.TextPDFClass&quot; action=&quot;CREATE&quot;>
<cfset pdf.License = &quot;xxxx-xxxxx-xxxx-xxxx&quot;>
<cfset pdf.StartPDF = &quot;outputfile:='c:\output.pdf'&quot;>
<cfset pdf.PrintPDF = &quot;c:\test1.txt&quot;>
<cfset pdf.PrintPDF = &quot;c:\test2.txt&quot;>
<cfset pdf.PrintPDF = &quot;c:\test3.txt&quot;>
<cfset pdf.EndPDF>
<cfset pdf = &quot;Nothing&quot;>

Didn't work. I got the following error.
Arguments expected by object does not match arguments specified in the tag.

Error building an argument list for: STARTPDF


But I rather clueless here. I'd appreciate any help.
 
try like this:

<cfobject type=&quot;COM&quot; name=&quot;pdf&quot; class=&quot;TextPDF.TextPDFClass&quot; action=&quot;CREATE&quot;>
<!--- not sure about this, you might want to try
<cfset temp = pdf.setLicense(&quot;xxxx-xxxxx-xxxx-xxxx&quot;)>
--->
<cfset pdf.License = &quot;xxxx-xxxxx-xxxx-xxxx&quot;>
<cfset temp = pdf.StartPDF(&quot;c:\output.pdf&quot;)>
<cfset temp = pdf.PrintPDF(&quot;c:\test1.txt&quot;)>
<cfset temp = pdf.PrintPDF(&quot;c:\test2.txt&quot;)>
<cfset temp = pdf.PrintPDF(&quot;c:\test3.txt&quot;)>
<cfset temp = pdf.EndPDF()>

remember you can always CFDUMP an object to see the methods etc...
 
Yep, rhys is pretty much right on that. Here's the way VB is working:

In...

Private Sub Command1_Click()
Dim pdf As Object
Set pdf = CreateObject(&quot;TextPDF.TextPDFClass&quot;)
pdf.License = &quot;xxxx-xxxxx-xxxx-xxxx&quot;
pdf.StartPDF outputfile:=&quot;c:\output.pdf&quot;
pdf.PrintPDF &quot;c:\test1.txt&quot;
pdf.PrintPDF &quot;c:\test2.txt&quot;
pdf.PrintPDF &quot;c:\test3.txt&quot;
pdf.EndPDF
Set pdf = Nothing
End Sub

The code [pdf.License = &quot;xxxx-xxxxx-xxxx-xxxx&quot;] is setting a member variable (License) of the class &quot;TextPDF.TextPDFClass&quot;.

The code [pdf.StartPDF outputfile:=&quot;c:\output.pdf&quot;] calls a method (StartPDF) of the class and is passing a string paramter. Change that to remove the &quot;outputfile:=&quot; portion of the parameter. Then you will call it like the subsequent &quot;PrintPDF&quot; lines (see below).

Each of the code lines [pdf.PrintPDF &quot;c:\test<whatever>.txt&quot;] is calling a method (PrintPDF) of that same class and passing it a string parameter.

The code [pdf.EndPDF] is also calling a method of that class, and rhys is exactly right that in the CF call you have to specify the empty parentheses at the end, though in VB they're not required.

The only thing I'd say that is different from rhys is that you don't necessarily set a value from each of those methods - you'd have to check the documentation for that. That's not to say it wouldn't work as he's written it, because it might - I've never tried assigning a function that doesn't return a value to a variable. If you know that it doesn't return a value, however, you can just call the method like this:

<cfset pdf.EndPDF()>

Hopefully this helps.
 
I really appreciate all the info I've been given on this. I now see how to use this. However, I'm still getting this error:

Arguments expected by object does not match arguments specified in the tag.
Error building an argument list for: STARTPDF

I've contacted the author of the activeX object, and I really think I'm doing this right. He sent back a (difficult to read) vb explanation. I then whipped up an ASP page to call it (similar syntax sort of) and got it to almost work. It just hangs actually. But anyway, I think you guys are right on it. And I think I am doing it correctly now. But it just seems to not be working.

One note, I can't do a dump of the object, I get an error. That is a good way to do it. I also downloaded a dll viewer from MS, and was able to view the STARTPDF method, I am supplying the only required parameter.

Anyway, if anyone still sees something I'm doing wrong, let me know. But I think I've been given good guidance from this forum.

Thanks
 
Yep, that's one thing I've noticed about ColdFusion - it doesn't handle the optional parameters the same way VB does. It wants you to specify a value for them (so I guess they are no longer really &quot;optional&quot; when you call them from ColdFusion). Just find out their default values and go ahead and explicitly pass those in for those parameters.
 
Really! Ok, we may be onto something....
Here is what I get when I view the STARTPDF() method:

void StartPDF(
[in, out] BSTR* outputfile,
[in, out, optional] BSTR* TextAuthor,
[in, out, optional] BSTR* TextCreator,
[in, out, optional] BSTR* TextKeywords,
[in, out, optional] BSTR* TextSubject,
[in, out, optional] BSTR* TextTitle,
[in, out, optional, defaultvalue(&quot;Courier&quot;)] BSTR* FontName,
[in, out, optional, defaultvalue(10)] short* FontSize,
[in, out, optional] short* Rotation,
[in, out, optional, defaultvalue(8.5)] single* pwidth,
[in, out, optional, defaultvalue(11)] single* pheight,
[in, out, optional, defaultvalue(0.5)] single* Margin,
[in, out, optional, defaultvalue(0)] short* ForeColorIndex,
[in, out, optional, defaultvalue(7)] short* BackColorIndex,
[in, out, optional, defaultvalue(-1)] VARIANT_BOOL* ShowPageNum,
[in, out, optional, defaultvalue(-1)] VARIANT_BOOL* UseLineFormating,
[in, out, optional, defaultvalue(0)] short* TransitionMode,
[in, out, optional] VARIANT_BOOL* FullScreen,
[in, out, optional, defaultvalue(0.5)] single* TopMargin);


Now, I tried putting this in my CF string:
<cfset temp = pdf.StartPDF(&quot;c:\output.pdf&quot;, &quot;Marvin Hoffman&quot;, &quot;Marvin&quot;, &quot;PDFCreator&quot;, &quot;PDFCreator&quot;,&quot;DynamicPDF&quot;,&quot;Courier&quot;, 10, &quot;&quot;, 8.5, 11, 0.5, 0, 7, &quot;-1&quot;, &quot;-1&quot;, 0, &quot;&quot;, 0.5)>

This caused the error: Cannot convert to integer. So, I remove all the quotes from the integers, and put in 1's for the &quot;&quot; values, and I get:
COM error 0x80020005. Type mismatch.

So, basically, I need to match some values with the types the object is expecting. But I'm not sure what VARIANT_BOOL should be, and what is a SHORT type?

We may just get this to work!

Thanks
 
I pulled this from my MSDN doc:

VariantBool 2-byte OLE defined Boolean value ( true = -1, false = 0).

So I'd try specifying 0 as the value for
[in, out, optional] VARIANT_BOOL* FullScreen
since I'd guess that's how it's being initialized. That would also explain the &quot;type mismatch&quot; error if the only valid values are 0 and -1 and you specified a value of 1.

Short should be a &quot;short integer&quot; data type. I'd stick with specifying 0 for that one too.

Let me know if that does the trick.
 
Still no luck. I've gone through and put in -1, or 0 for the boolean values. And I found a description of the STARTPDF() method in a text file with the dll.

Here is what I've done in CF:
<cfset temp = pdf.StartPDF(&quot;c:\output.pdf&quot;, &quot;Marvin Hoffman&quot;, &quot;Marvin&quot;, &quot;PDFCreator&quot;, &quot;PDFCreator&quot;,&quot;DynamicPDF&quot;,&quot;Courier&quot;, &quot;10&quot;, &quot;0&quot;, &quot;8.5&quot;, &quot;11&quot;, &quot;0.5&quot;, &quot;0&quot;, &quot;7&quot;, &quot;-1&quot;, &quot;-1&quot;, &quot;0&quot;, &quot;0&quot;, &quot;0.5&quot;)>

I've tried it with and without the &quot;&quot;. I still get the type mismatch error. Arrrgh. Frustrating.

Here is what was in the text file:


Public Sub StartPDF(outputfile As String, _
Optional TextAuthor As String, Optional TextCreator As String, Optional TextKeywords As String, _
Optional TextSubject As String, Optional TextTitle As String, _
Optional FontName As String = &quot;Courier&quot;, Optional FontSize As Integer = 10, Optional Rotation As Integer, _
Optional pwidth As Single = 8.5, Optional pheight As Single = 11, Optional Margin As Single = 0.5, _
Optional ForeColorIndex As Integer = 0, Optional BackColorIndex As Integer = 7, _
Optional ShowPageNum As Boolean = True, Optional UseLineFormating As Boolean = True, _
Optional TransitionMode As Integer = 0, Optional FullScreen As Boolean, Optional TopMargin As Single = 0.5)

I appreciate your help.
 
I'm going through now and putting &quot;&quot; in for the int values. I'm then getting errors that tell me what the type (in the dll) of that particular param is. So far all are showing up as number, integer, and boolean. What is the difference between number and integer?

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top