Custom Browser Issue

Hi guys,

I am using this project:

http://www.codeproject.com/internet/CustomBrowser.asp

added my own function, which when called returns this error:

object doesn't support this property or method


Here is my function:

void CCustomBrowserDlg::CB_AttachTemplate(int argc, char **argv)
{
      char TargetPath[500];

      CFileOperation fo;

      sprintf(TargetPath, "%s%s\\T\\%s\\%s.%s", ROOT, argv[1], argv[2], argv[3], argv[6]);
      fo.Delete(TargetPath);
      CopyFile(argv[4], TargetPath, true);

      return;
}


any idea why it's not working?

Cheers guys 'n gals!
LVL 4
Cyber-DrugsAsked:
Who is Participating?
 
Computer101Connect With a Mentor Commented:
PAQed with points refunded (500)

Computer101
EE Admin
0
 
jkrCommented:
Have you added the method declaration to 'CustomBrowserDlg.h' also?
0
 
Cyber-DrugsAuthor Commented:
jkr,

That's correct, and it seems now that I've sort of found the problem, but can't find the solution...

I've found out that I need to add the function into this file:

Idispimp.h

But I don't understand the structure of the file too well, could you kindly show me what I am supposed to do please? Once I see how one is done, I should be able to do the rest, no problems...
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
jkrCommented:
No, you'll have to add that to 'Idispimp.cpp' like

/*
 * idispimp.CPP
 * IDispatch for Extending Dynamic HTML Object Model
 *
 * Copyright (c)1995-1999 Microsoft Corporation, All Rights Reserved
 */

#include "stdafx.h"
#include "idispimp.h"

#include "CustomBrowser.h"
#include "CustomBrowserDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


CString cszCB_IsOurCustomBrowser = "CB_IsOurCustomBrowser";
CString cszCB_Close = "CB_Close";
CString cszCB_CustomFunction = "CB_CustomFunction";
CString cszCB_CustomFunctionWithParams = "CB_CustomFunctionWithParams";
CString cszCB_OpenWindow = "CB_OpenWindow";
CString cszCB_ShowModalDialog = "CB_ShowModalDialog";
CString cszCB_ShowModelessDialog = "CB_ShowModelessDialog";
CString cszCB_AttachTemplate ="CB_AttachTemplate";

#define DISPID_CB_IsOurCustomBrowser 1
#define DISPID_CB_Close 2
#define DISPID_CB_CustomFunction 3
#define DISPID_CB_CustomFunctionWithParams 4
#define DISPID_CB_OpenWindow 5
#define DISPID_CB_ShowModalDialog 6
#define DISPID_CB_ShowModelessDialog 7
#define DISPID_CB_AttachTemplate 8



/*
 * CImpIDispatch::CImpIDispatch
 * CImpIDispatch::~CImpIDispatch
 *
 * Parameters (Constructor):
 *  pSite           PCSite of the site we're in.
 *  pUnkOuter       LPUNKNOWN to which we delegate.
 */

CImpIDispatch::CImpIDispatch( void )
{
    m_cRef = 0;
}

CImpIDispatch::~CImpIDispatch( void )
{
      ASSERT( m_cRef == 0 );
}


/*
 * CImpIDispatch::QueryInterface
 * CImpIDispatch::AddRef
 * CImpIDispatch::Release
 *
 * Purpose:
 *  IUnknown members for CImpIDispatch object.
 */

STDMETHODIMP CImpIDispatch::QueryInterface( REFIID riid, void **ppv )
{
    *ppv = NULL;


    if ( IID_IDispatch == riid )
      {
        *ppv = this;
      }
      
      if ( NULL != *ppv )
    {
        ((LPUNKNOWN)*ppv)->AddRef();
        return NOERROR;
    }

      return E_NOINTERFACE;
}


STDMETHODIMP_(ULONG) CImpIDispatch::AddRef(void)
{
    return ++m_cRef;
}

STDMETHODIMP_(ULONG) CImpIDispatch::Release(void)
{
    return --m_cRef;
}


//IDispatch
STDMETHODIMP CImpIDispatch::GetTypeInfoCount(UINT* /*pctinfo*/)
{
      return E_NOTIMPL;
}

STDMETHODIMP CImpIDispatch::GetTypeInfo(
                  /* [in] */ UINT /*iTInfo*/,
            /* [in] */ LCID /*lcid*/,
            /* [out] */ ITypeInfo** /*ppTInfo*/)
{
      return E_NOTIMPL;
}

STDMETHODIMP CImpIDispatch::GetIDsOfNames(
                  /* [in] */ REFIID riid,
            /* [size_is][in] */ OLECHAR** rgszNames,
            /* [in] */ UINT cNames,
            /* [in] */ LCID lcid,
            /* [size_is][out] */ DISPID* rgDispId)
{
      HRESULT hr;
      UINT      i;

      // Assume some degree of success
      hr = NOERROR;


            for ( i=0; i < cNames; i++) {
            CString cszName  = rgszNames[i];

            if(cszName == cszCB_IsOurCustomBrowser)
            {
                  rgDispId[i] = DISPID_CB_IsOurCustomBrowser;
            }
            else if(cszName == cszCB_Close)
            {
                  rgDispId[i] = DISPID_CB_Close;
            }
            else if(cszName == cszCB_CustomFunction)
            {
                  rgDispId[i] = DISPID_CB_CustomFunction;
            }
            else if(cszName == cszCB_CustomFunctionWithParams)
            {
                  rgDispId[i] = DISPID_CB_CustomFunctionWithParams;
            }      
            else if(cszName == cszCB_OpenWindow)
            {
                  rgDispId[i] = DISPID_CB_OpenWindow;
            }
            else if(cszName == cszCB_ShowModalDialog)
            {
                  rgDispId[i] = DISPID_CB_ShowModalDialog;
            }
            else if(cszName == cszCB_ShowModelessDialog)
            {
                  rgDispId[i] = DISPID_CB_ShowModelessDialog;
            }
            else if(cszName == cszCB_AttachTemplate)
            {
                  rgDispId[i] = DISPID_CB_AttachTemplate;
            }
            else {
                  // One or more are unknown so set the return code accordingly
                  hr = ResultFromScode(DISP_E_UNKNOWNNAME);
                  rgDispId[i] = DISPID_UNKNOWN;
            }

      }
      return hr;
}

STDMETHODIMP CImpIDispatch::Invoke(
            /* [in] */ DISPID dispIdMember,
            /* [in] */ REFIID /*riid*/,
            /* [in] */ LCID /*lcid*/,
            /* [in] */ WORD wFlags,
            /* [out][in] */ DISPPARAMS* pDispParams,
            /* [out] */ VARIANT* pVarResult,
            /* [out] */ EXCEPINFO* /*pExcepInfo*/,
            /* [out] */ UINT* puArgErr)
{

      CCustomBrowserDlg* pDlg = (CCustomBrowserDlg*) AfxGetMainWnd();
      
      if(dispIdMember == DISPID_CB_IsOurCustomBrowser)
      {
            if(wFlags & DISPATCH_PROPERTYGET)
            {
                  if(pVarResult != NULL)
                  {
                        VariantInit(pVarResult);
                        V_VT(pVarResult)=VT_BOOL;
                        V_BOOL(pVarResult) = true;
                  }
            }
            
            if ( wFlags & DISPATCH_METHOD )
            {
                  bool bResult = pDlg->CB_IsOurCustomBrowser();
                  
                  VariantInit(pVarResult);
                  V_VT(pVarResult)=VT_BOOL;
                  V_BOOL(pVarResult) = bResult;
            }
            
      }
      
      if(dispIdMember == DISPID_CB_Close)
      {
            if(wFlags & DISPATCH_PROPERTYGET)
            {
                  if(pVarResult != NULL)
                  {      
                        VariantInit(pVarResult);
                        V_VT(pVarResult)=VT_BOOL;
                        V_BOOL(pVarResult) = true;
                  }
            }
            
            if ( wFlags & DISPATCH_METHOD )
            {
                  
                  pDlg->CB_Close();
            }
            
      }
      
      
      if(dispIdMember == DISPID_CB_CustomFunction)
      {
            if(wFlags & DISPATCH_PROPERTYGET)
            {
                  if(pVarResult != NULL)
                  {
                        VariantInit(pVarResult);
                        V_VT(pVarResult)=VT_BOOL;
                        V_BOOL(pVarResult) = true;
                  }
            }
            
            if ( wFlags & DISPATCH_METHOD )
            {
                  pDlg->CB_CustomFunction();
            }
       
            
      }
      
      if(dispIdMember == DISPID_CB_CustomFunctionWithParams)
      {
            if(wFlags & DISPATCH_PROPERTYGET)
            {
                  if(pVarResult != NULL)
                  {
                        
                        VariantInit(pVarResult);
                        V_VT(pVarResult)=VT_BOOL;
                        V_BOOL(pVarResult) = true;
                  }
            }
            
            if ( wFlags & DISPATCH_METHOD )
            {
                  //arguments come in reverse order
                  //for some reason
                  CString cszArg1= pDispParams->rgvarg[1].bstrVal; // in case you want a CString copy
                  int nArg2= pDispParams->rgvarg[0].intVal;
                  
                  pDlg->CB_CustomFunctionWithParams(cszArg1, nArg2);
            }
            
      }

      if(dispIdMember == DISPID_CB_OpenWindow)
      {
            if(wFlags & DISPATCH_PROPERTYGET)
            {
                  if(pVarResult != NULL)
                  {
                        
                        VariantInit(pVarResult);
                        V_VT(pVarResult)=VT_BOOL;
                        V_BOOL(pVarResult) = true;
                  }
            }
            
            if ( wFlags & DISPATCH_METHOD )
            {
                  //arguments come in reverse order
                  //for some reason
                  CString cszArg1= pDispParams->rgvarg[5].bstrVal; // in case you want a CString copy
                  int nArg2= pDispParams->rgvarg[4].intVal;
                  int nArg3= pDispParams->rgvarg[3].intVal;
                  int nArg4= pDispParams->rgvarg[2].intVal;
                  int nArg5= pDispParams->rgvarg[1].intVal;
                  int nArg6 = pDispParams->rgvarg[0].intVal;
                  
                  pDlg->CB_OpenWindow(cszArg1, nArg2, nArg3, nArg4, nArg5, nArg6);
            }
            
      }
      
      if(dispIdMember == DISPID_CB_ShowModelessDialog)
      {
            if(wFlags & DISPATCH_PROPERTYGET)
            {
                  if(pVarResult != NULL)
                  {
                        
                        VariantInit(pVarResult);
                        V_VT(pVarResult)=VT_BOOL;
                        V_BOOL(pVarResult) = true;
                  }
            }
            
            if ( wFlags & DISPATCH_METHOD )
            {
                  //arguments come in reverse order
                  //for some reason
                  CString cszArg1= pDispParams->rgvarg[4].bstrVal; // in case you want a CString copy
                  int nArg2= pDispParams->rgvarg[3].intVal;
                  int nArg3= pDispParams->rgvarg[2].intVal;
                  int nArg4= pDispParams->rgvarg[1].intVal;
                  int nArg5= pDispParams->rgvarg[0].intVal;
                  
                  pDlg->CB_ShowModelessDialog(cszArg1, nArg2, nArg3, nArg4, nArg5);
            }
            
      }
      
      if(dispIdMember == DISPID_CB_ShowModalDialog)
      {
            if(wFlags & DISPATCH_PROPERTYGET)
            {
                  if(pVarResult != NULL)
                  {
                        
                        VariantInit(pVarResult);
                        V_VT(pVarResult)=VT_BOOL;
                        V_BOOL(pVarResult) = true;
                  }
            }
            
            if ( wFlags & DISPATCH_METHOD )
            {
                  //arguments come in reverse order
                  //for some reason
                  CString cszArg1= pDispParams->rgvarg[4].bstrVal; // in case you want a CString copy
                  int nArg2= pDispParams->rgvarg[3].intVal;
                  int nArg3= pDispParams->rgvarg[2].intVal;
                  int nArg4= pDispParams->rgvarg[1].intVal;
                  int nArg5= pDispParams->rgvarg[0].intVal;
                  
                  pDlg->CB_ShowModalDialog(cszArg1, nArg2, nArg3, nArg4, nArg5);
            }
            
      }

      
      if(dispIdMember == DISPID_CB_AttachTemplate)
      {
            if(wFlags & DISPATCH_PROPERTYGET)
            {
                  if(pVarResult != NULL)
                  {
                        
                        VariantInit(pVarResult);
                        V_VT(pVarResult)=VT_BOOL;
                        V_BOOL(pVarResult) = true;
                  }
            }
            
            if ( wFlags & DISPATCH_METHOD )
            {
                  //arguments come in reverse order
                  //for some reason
                  CString cszArg1= pDispParams->rgvarg[1].bstrVal; // in case you want a CString copy
                  int nArg2= pDispParams->rgvarg[0].intVal;
                  
                  pDlg->CB_AttachTemplate(cszArg1, nArg2);
            }
            
      }

      return S_OK;
}


NOTE that the function then is

void CCustomBrowserDlg::CB_AttachTemplate(char *strVal, int nVal)
{
     char TargetPath[500];

     CFileOperation fo;

     sprintf(TargetPath, "%s%s\\T\\%s\\%s.%s", ROOT, argv[1], argv[2], argv[3], argv[6]);
     fo.Delete(TargetPath);
     CopyFile(strVal, TargetPath, true);

     return;
}

modeled after 'CB_CustomFunctionWithParams()'
0
 
Cyber-DrugsAuthor Commented:
I tried that, and then got this compile error:

C:\Documents and Settings\Administrator\Desktop\Browser\CustomBrowser\CustomBrowser\Idispimp.cpp(382) : error C2664: 'CB_AttachTemplate' : cannot convert parameter 1 from 'class CString' to 'char *'
0
 
jkrCommented:
Sorry, make that

void CCustomBrowserDlg::CB_AttachTemplate(CString TargetPath, int nVal)
{
     CFileOperation fo;

     fo.Delete(TargetPath);
     CopyFile(strVal, TargetPath, true);

     return;
}
0
 
Cyber-DrugsAuthor Commented:
Now getting:

C:\Documents and Settings\Administrator\Desktop\Browser\CustomBrowser\CustomBrowser\CustomBrowserDlg.cpp(1565) : error C2065: 'strVal' : undeclared identifier
0
 
jkrCommented:
Hm, forgot the other parameter - then, we'll have to extend that to


     if(dispIdMember == DISPID_CB_AttachTemplate)
     {
          if(wFlags & DISPATCH_PROPERTYGET)
          {
               if(pVarResult != NULL)
               {
                   
                    VariantInit(pVarResult);
                    V_VT(pVarResult)=VT_BOOL;
                    V_BOOL(pVarResult) = true;
               }
          }
         
          if ( wFlags & DISPATCH_METHOD )
          {
               //arguments come in reverse order
               //for some reason
               CString cszArg1= pDispParams->rgvarg[1].bstrVal; // in case you want a CString copy
               CString cszArg2= pDispParams->rgvarg[0].bstrVal; // in case you want a CString copy
               
               pDlg->CB_AttachTemplate(cszArg1, cszArg2);
          }
         
     }


//...

void CCustomBrowserDlg::CB_AttachTemplate(CString SourcePath, CString TargetPath)
{
     CFileOperation fo;

     fo.Delete(TargetPath);
     CopyFile(SourcePath, TargetPath, true);

     return;
}
0
 
Cyber-DrugsAuthor Commented:
OK, it compiled this time, but when it came to calling the function, it waited 5 seconds and then displayed this:


The instruction at "0x10217c5f" referenced memory at "0x00000007". The memory could not be "read".



Any ideas?
0
 
Cyber-DrugsAuthor Commented:
I also just noticed, you got rid of my array, why? I need to be able to send an array...
0
 
Cyber-DrugsAuthor Commented:
I need to be able to keep the function like this:

void CCustomBrowserDlg::CB_AttachTemplate(int argc, char **argv)
{
     char TargetPath[500];

     CFileOperation fo;

     sprintf(TargetPath, "%s%s\\T\\%s\\%s.%s", ROOT, argv[1], argv[2], argv[3], argv[6]);
     fo.Delete(TargetPath);
     CopyFile(argv[4], TargetPath, true);

     return;
}

So what changes are required in:

if(dispIdMember == DISPID_CB_AttachTemplate)


?
0
 
Cyber-DrugsAuthor Commented:
Is there maybe a way to convert this:

CString cszArg2= pDispParams->rgvarg[0].bstrVal; // in case you want a CString copy

to make use of

CStringArray

and get the results like that? Or is there a lot of work required to make this work? I seriously need to get this working, and am starting to consider offering this question on CodeLance... Will leave it open for a few more hours before I do that though.
0
 
jkrCommented:
The function call needs an equivalent on the calling side.

Regarding the array: That functionality is is a lot more complex than it seems at first glance - let me see...
0
 
Cyber-DrugsAuthor Commented:
jkr,

I found a way of reading the values in as an array, but could use some help tidying it up so that it stores it as an actual array, and then parses the end result to my function. Would you mind taking a look at the code, and helping me finish it off?



if(dispIdMember == DISPID_CB_AttachTemplate)
      {
            if(wFlags & DISPATCH_PROPERTYGET)
            {
                  if(pVarResult != NULL)
                  {
                        
                        VariantInit(pVarResult);
                        V_VT(pVarResult)=VT_BOOL;
                        V_BOOL(pVarResult) = true;
                  }
            }
            
            if ( wFlags & DISPATCH_METHOD )
            {
                  // length of array
                  int nArg2= pDispParams->rgvarg[0].intVal;
                  //
                  //string aEndArray[nArg2];
                  // arguments come in reverse order
                  // for some reason
                  CComPtr<IDispatchEx> pDispEx;
                  HRESULT hr=pDispParams->rgvarg[1].pdispVal->QueryInterface(IID_IDispatchEx,(void**)&pDispEx);
                  DISPID dispid;
                  // get the DISPID of the first item.  
                  hr = pDispEx->GetNextDispID(fdexEnumAll, DISPID_STARTENUM, &dispid);
                  while (hr == NOERROR)
                  {
                        // get the item name
                        CComBSTR bstrName;
                        hr = pDispEx->GetMemberName(dispid, &bstrName);

                        // get the item value
                        CComVariant vValue;
                        DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
                        hr = pDispEx->InvokeEx(dispid, LOCALE_USER_DEFAULT,
                              DISPATCH_PROPERTYGET, &dispparamsNoArgs,
                              &vValue, NULL, NULL);

                        switch (vValue.vt)
                        {
                        case 'VT_I4':
                              // value is integer
                              char buf[5];
                              itoa(vValue.iVal, buf, 10);
                              break;
                        case 'VT_BSTR':
                              // value is string
                              buf = vValue.bstrVal;
                              break;
                        }

                        //get the DISPID of the next item.  
                        hr = pDispEx->GetNextDispID(fdexEnumAll, dispid, &dispid);
                  }                  
                  struct tagSAFEARRAY *cszArg1= pDispParams->rgvarg[1].parray; // in case you want a CString copy
                  // call the end function
                  pDlg->CB_AttachTemplate(nArg2, cszArg1);
            }
            
      }
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.