Q. About OCX Parameter
Robert -- donovanr@webworks.ca Friday, June 28, 1996 Hello, Environment: Windows 95 Visual C++ 4.0 I have an OCX control that Returns an event: void COpenFTP::OnListItemFtp(LPDISPATCH Item) { } 'Item' should contain a filename, size, type etc. How do I get this data into a CString or some such. Thanks in advance for your help, Donovan ERROR:Invalid or missing REALITY.COM Universe halted!
David McGaffin -- dmcgaffi@mail1.videoserver.com Wednesday, July 03, 1996 My guess - without any knowledge of your OCX - would be that DISPATCH is a struct with filename, size, type members. Probably the easiest way to put, say, the filename into a CString is by calling CString's LPCSTR constructor. Thus: void COpenFTP::OnListItemFtp(LPDISPATCH Item) { CString FileName(Item->filename); } - David McGaffin ---------- From: mfc-l[SMTP:mfc-l@netcom.com] Sent: Wednesday, July 03, 1996 2:46 PM To: mfc-l Subject: Q. About OCX Parameter Hello, Environment: Windows 95 Visual C++ 4.0 I have an OCX control that Returns an event: void COpenFTP::OnListItemFtp(LPDISPATCH Item) { } 'Item' should contain a filename, size, type etc. How do I get this data into a CString or some such. Thanks in advance for your help, Donovan ERROR:Invalid or missing REALITY.COM Universe halted!
Perri Nelson -- pnelson@microsoft.com Friday, July 05, 1996 [Mini-digest: 2 responses] LPDISPATCH is a pointer to an IDISPATCH interface, typically used in OLE automation and OCXs. You'll need to determine the properties of the object being automated and do a property get in order to get your data into a CString. Check the documentation for the OCX and the event being fired for more information. -----From: "John Elsbree"Donovan - Item is a pointer to an IDispatch interface. You will probably need to call IDispatch::Invoke to access the properties of the item. To find out which properties you can access, consult your control's documentation. Look up IDispatch::Invoke in your Visual C++ Books Online for its signature and information on how to call it. To obtain the DISPID values you'll need to pass to Invoke, you may need to call IDispatch::GetIDsOfNames. Once you know the DISPID values, you can save yourself the headache of calling IDispatch::Invoke directly, by using MFC's COleDispatchDriver class instead. This class is documented in the Books Online. Here's how your code might look: void COpenFTP::OnListItemFtp(LPDISPATCH Item) { COleDispatchDriver dispDriver(Item, FALSE); CString strFilename; dispDriver.GetProperty(0x00000001, VT_BSTR, &strFilename); } The exact DISPID (0x00000001) will depend on what the documentation or GetIDsOfNames tells you. Also note that this approach is not type-safe (the third parameter has type void*), so make sure that you match the type tag (VT_BSTR) and the type of pointer you pass. The documentation for COleDispatchDriver includes a table of type tags and the corresponding parameter types. If the author of your control was kind enough to include type information for this Item object in the control's type library, you might be able to use ClassWizard to create a "wrapper" class for it. This will make accessing its properties even easier. Invoke ClassWizard, and choose Add Class | From OLE Typelib. When prompted for the file containing the type library, find the .OCX file that contains the control. Next, you'll get a list of the available type information in that type library. If you see a name in that list that seems to be related to items, choose it and let ClassWizard generate a class for you. Once this has been done, you should be able to access the properties as follows: void COpenFTP::OnListItemFtp(LPDISPATCH Item) { CItem itemWrapper(Item, FALSE); CString strFilename = itemWrapper.GetFilename(); } The exact class name (CItem), method name (GetFilename), and return type (CString) will depend on what ClassWizard finds in the control's type library. Good luck with it. John ("not speaking for Microsoft") Elsbree
| Вернуться в корень Архива |