home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 1999 April / APC443.iso / features / grpware / coldfus / coldfusi.exe / data1.cab / Documentation / snippets / cfobjectcom.cfm < prev    next >
Encoding:
Text File  |  1998-10-08  |  3.8 KB  |  157 lines

  1. <HTML>
  2. <HEAD>
  3. <TITLE>CFOBJECT (COM) Example</TITLE>
  4. </HEAD>
  5.  
  6. <BODY>
  7. <H3>CFOBJECT (COM) Example</H3>
  8. <!---
  9. Create a COM object as an inproc server (DLL).
  10. (CLASS= prog-id). Uses DocEx1.DLL, which may need
  11. to be registered on the CF Server machine.
  12. --->
  13. <!--- Check for platform. COM doesn't run under UNIX. --->
  14. <CFIF Server.OS.Name EQ "Windows NT">
  15. <CFOBJECT TYPE="COM"
  16.     ACTION="Create"
  17.     CLASS="Allaire.DocEx1.1"
  18.     NAME="obj"> 
  19.  
  20. <!---
  21. Call a method.
  22. Note that methods that expect no arguments should 
  23. be called using empty parenthesis.
  24. --->
  25. <CFSET obj.Init()>
  26.  
  27. <!---
  28. This object is a collection object, and should 
  29. support at a minimum:
  30. Property : Count
  31. Method : Item(inarg, outarg)
  32. and a special property called _NewEnum 
  33. --->
  34. <CFOUTPUT>
  35.   This object has #obj.Count# items.
  36.   <BR>
  37.   <HR>
  38. </CFOUTPUT>
  39.  
  40.  
  41. <!---
  42. Get the 3rd object in the collection.
  43. --->
  44. <CFSET emp = obj.Item(3)>
  45. <CFOUTPUT>
  46.   The last name in the third item is #emp.lastname#.
  47.   <BR>
  48.   <HR>
  49. </CFOUTPUT>
  50.  
  51. <!---
  52. Loop over all the objects in the collection.
  53. --->
  54. <P>Looping through all items in the collection:
  55. <BR>
  56. <CFLOOP COLLECTION=#obj# ITEM=file2>
  57.   <CFOUTPUT>
  58.     Last name: #file2.lastname# <BR>
  59.   </CFOUTPUT>
  60. </CFLOOP>
  61.  
  62. <CFELSE>
  63. <H4>COM supported is limited to the Windows/NT platform.</H4>
  64. </cfif>
  65.  
  66. <!-----
  67. IDL for the object
  68. **** Important Note ***********************************
  69. The Item() method takes a VARIANT as an [in] argument. ColdFusion
  70. cannot determine the type and simply sends a BSTR. IF THE OBJECT
  71. does not corece it to the right type (which it does in this case)
  72. using the following :
  73.  
  74.       HRESULT hr;
  75.  
  76.    // Check to see if a number has been passed
  77.    if (Index.vt != VT_I4)
  78.    {
  79.        hr = VariantChangeType(&Index, &Index, 0, VT_I4);
  80.    }
  81.  
  82. then an error will be reported. To avoid these type of problems,
  83. object developers should specify the type directly in the IDL.
  84.  
  85. For example, if the IDL had been coded :
  86.  
  87. HRESULT Item([in] long index, [out,retval] LPVARIANT pItem);
  88.  
  89. **** Important Note ***********************************
  90. import "oaidl.idl";
  91. import "ocidl.idl";
  92.  
  93.     [
  94.         object,
  95.         uuid(3607722F-3B5A-11D2-BEBB-00C04FA35D22),
  96.         dual,
  97.         helpstring("IEmployeeCollection Interface"),
  98.         pointer_default(unique)
  99.     ]
  100.     interface IEmployeeCollection : IDispatch
  101.     {
  102.         [propget, id(1), helpstring("property Count")] 
  103.         HRESULT Count([out, retval] long *pVal);
  104.         [id(2), helpstring("method Item")] 
  105.         HRESULT Item([in] VARIANT index, [out,retval] LPVARIANT pItem);
  106.         [id(3), helpstring("method Init")] HRESULT Init();
  107.         [propget, id(-4), helpstring("property _NewEnum"), restricted] 
  108.         HRESULT _NewEnum([out, retval] LPUNKNOWN *pVal);
  109.     };
  110.     [
  111.         object,
  112.         uuid(36077231-3B5A-11D2-BEBB-00C04FA35D22),
  113.         dual,
  114.         helpstring("IEmployee Interface"),
  115.         pointer_default(unique)
  116.     ]
  117.     interface IEmployee : IDispatch
  118.     {
  119.         [propget, id(1), helpstring("property EmployeeID")] 
  120.         HRESULT EmployeeID([out, retval] long *pVal);
  121.         [propput, id(1), helpstring("property EmployeeID")] 
  122.         HRESULT EmployeeID([in] long newVal);
  123.         [propget, id(2), helpstring("property LastName")] HRESULT LastName([out, retval] BSTR *pVal);
  124.         [propput, id(2), helpstring("property LastName")] HRESULT LastName([in] BSTR newVal);
  125.     };
  126. [
  127.     uuid(36077222-3B5A-11D2-BEBB-00C04FA35D22),
  128.     version(1.0),
  129.     helpstring("DocEx1 1.0 Type Library")
  130. ]
  131. library DOCEX1Lib
  132. {
  133.     importlib("stdole32.tlb");
  134.     importlib("stdole2.tlb");
  135.  
  136.     [
  137.         uuid(36077230-3B5A-11D2-BEBB-00C04FA35D22),
  138.         helpstring("EmployeeCollection Class")
  139.     ]
  140.     coclass EmployeeCollection
  141.     {
  142.         [default] interface IEmployeeCollection;
  143.     };
  144.     [
  145.         uuid(36077232-3B5A-11D2-BEBB-00C04FA35D22),
  146.         helpstring("Employee Class")
  147.     ]
  148.     coclass Employee
  149.     {
  150.         [default] interface IEmployee;
  151.     };
  152. };
  153. --->
  154.  
  155. </BODY>
  156. </HTML>
  157.