Solved

Custom Browser Issue

Posted on 2006-11-20
17
335 Views
Last Modified: 2013-11-20
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!
0
Comment
Question by:Cyber-Drugs
  • 9
  • 5
17 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 17982680
Have you added the method declaration to 'CustomBrowserDlg.h' also?
0
 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 17982738
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
 
LVL 86

Expert Comment

by:jkr
ID: 17982825
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
 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 17982910
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
 
LVL 86

Expert Comment

by:jkr
ID: 17983060
Sorry, make that

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

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

     return;
}
0
 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 17983118
Now getting:

C:\Documents and Settings\Administrator\Desktop\Browser\CustomBrowser\CustomBrowser\CustomBrowserDlg.cpp(1565) : error C2065: 'strVal' : undeclared identifier
0
 
LVL 86

Expert Comment

by:jkr
ID: 17983167
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 17983641
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
 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 17983661
I also just noticed, you got rid of my array, why? I need to be able to send an array...
0
 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 17983855
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
 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 17984157
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
 
LVL 86

Expert Comment

by:jkr
ID: 17984498
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
 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 17987236
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
 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 17997748
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 18473171
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now