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

Using InvokeHelper Method of COleDispatchDriver

Status
Not open for further replies.

craigsboyd

IS-IT--Management
Nov 9, 2002
2,839
US
Can anyone tell me how to find the DISPID for the ComputeControlSize Method of the Monthview control. Or more specifically how to modify the code given at ...to do the following:

I am using Visual C++ to create a DLL to work around a bug in another language. I will be sending a Microsoft MonthView control object to the VC++ DLL and then calling the ComputeControlSize method from within the DLL. What I would like to return is the width and height (parameters 3 and 4 of the ComputeControlSize) from the DLL. I can send the MonthView object and two variables in by reference from Visual Foxpro and I would like these two variables to then hold the values from the ComputeControlSize call in VC++ DLL. For those wondering, I would do it from the Visual Foxpro except there is an undocumented bug preventing this. I have VC++ 6 and think I have a fair handle on most of the code given at the link above, using the MonthView object rather than the Word Application object obviously, however the line that throws me is:

disp.InvokeHelper(0x17, DISPATCH_PROPERTYPUT, VT_EMPTY,
NULL, parms, FALSE);

I am not sure what the DISPID (first parameter) would be or even what should be sent for the remaining paramters. Never done this before. I know I need to use InvokeHelper to make a call to ComputeControlSize for the MonthView object I sent in to the DLL method talkToObject. Any help or direction would be greatly appreciated.

Slighthaze = NULL
craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
I used the OLE/COM object browser and appeared to find the DISPID for ComputeControlSize by looking at the Microsoft MonthView control. I have also taken a stab at successfully converting the code (see below). It is still not returning the height and width, but I am getting the dispatch pointer and believe that I am on the right track. Is there anyone that could look over the code as I have modified it and tell me what I am still doing wrong?

Code:
      // Helper message function...
      void ShowMsg(char *msg, HRESULT hr) {
            char buf[1024];
            if((long)hr) {
               sprintf(buf, "%s, HRESULT = %08lx", msg, (long)hr);
            }
            else {
               sprintf(buf, "%s", msg);
            }
            ::MessageBox(NULL, buf, "C/C++ DLL message",
                         MB_SETFOREGROUND | MB_OK);
      }

      // The exported function, called from Microsoft Visual FoxPro
Code:
      void _stdcall talkToObject(IUnknown *pUnk, short *pHei, short *pWid) {
            // QueryInterface for a IDispatch pointer...
            IDispatch *pDisp;
			float *pHeight = 0;
			float *pWidth = 0;

            HRESULT hr = pUnk->QueryInterface(IID_IDispatch,
                                             (void **)&pDisp);
            if(FAILED(hr)) {
               ShowMsg("QueryInterface() failed", hr);
            }
            else {
               ShowMsg("We got the dispatch pointer!!!", hr);

               // Attach dispatch to a COleDispatchDriver class.
               COleDispatchDriver disp(pDisp); // Uses constructor

               static BYTE parms[] = VTS_I2 VTS_I2 VTS_R4 VTS_R4;
               disp.InvokeHelper(0x0000001c, DISPATCH_METHOD, VT_EMPTY,
                                 NULL, parms, 1, 1, pWidth, pHeight);
				
			   *pWid = (short)pWidth;
			   *pHei = (short)pHeight;
         }
      }

Slighthaze = NULL
craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
Should

*pWid = (short)pWidth;
*pHei = (short)pHeight;


Read

*pWid = (short)&pWidth;
*pHei = (short)&pHeight;


...if I make this change then I receive some data back, however it looks more like a location in memory than the width and height I was expecting.

Slighthaze = NULL
craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
Gone a little further with it...problem is still that pHeight and pWidth are not being changed by the call to InvokeHelper. InvokeHelper is indeed working with ComputeControlSize and the 3rd and 4th parameters are expected to be passed by reference. But for whatever reason pHeight and pWidth remain unchanged. Anyone have any ideas?

Code:
      // The exported function, called from Microsoft Visual FoxPro
      void _stdcall talkToObject(IUnknown *pUnk, short &pHei, short &pWid) {
            // QueryInterface for a IDispatch pointer...
            IDispatch *pDisp;
			float pHeight;
			float pWidth;

            HRESULT hr = pUnk->QueryInterface(IID_IDispatch,
                                             (void **)&pDisp);
            if(FAILED(hr)) {
               ShowMsg("QueryInterface() failed", hr);
            }
            else {
               ShowMsg("We got the dispatch pointer!!!", hr);

               // Attach dispatch to a COleDispatchDriver class.
               COleDispatchDriver disp(pDisp); // Uses constructor

               static BYTE parms[] = VTS_I2 VTS_I2 VTS_R4 VTS_R4;
               disp.InvokeHelper(0x0000001c, DISPATCH_METHOD, VT_EMPTY,
                                 NULL, parms, 1, 1, &pWidth, &pHeight);
				
			   pWid = (short)pWidth;
			   pHei = (short)pHeight;
         }
      }

Slighthaze = NULL
craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
I had a good friend of mine look this over and he pointed out that the VTS_R4's needed to be changed to VTS_PR4's because a pointer was expected...for whatever it is worth, here's the correct code, it works now...though the problem was pretty specific, I think that perhaps the use of InvokeHelper on an OLE object sent in and the utilization of the OLE/COM OBJECT VIEWER maybe of some use to someone at some point:

Code:
      void _stdcall talkToObject(IUnknown *pUnk, short &pHei, short &pWid) {
            // QueryInterface for a IDispatch pointer...
            IDispatch *pDisp;
			float pHeight;
			float pWidth;

            HRESULT hr = pUnk->QueryInterface(IID_IDispatch,
                                             (void **)&pDisp);
            if(FAILED(hr)) {
               //QueryInterface() failed
            }
            else {
               //We got the dispatch pointer!

               // Attach dispatch to a COleDispatchDriver class.
               COleDispatchDriver disp(pDisp); // Uses constructor

               static BYTE parms[] = VTS_I2 VTS_I2 VTS_PR4 VTS_PR4;
               disp.InvokeHelper(0x0000001c, DISPATCH_METHOD, VT_EMPTY,
                                 NULL, parms, 1, 1, &pWidth, &pHeight);
				
			   pWid = (short)pWidth;
			   pHei = (short)pHeight;
         }
      }

Slighthaze = NULL
craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top