Cyber-Drugs
asked on
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_Atta chTemplate (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!
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_Atta
{
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!
Have you added the method declaration to 'CustomBrowserDlg.h' also?
ASKER
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...
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...
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_CustomFunctionWithPa rams = "CB_CustomFunctionWithPara ms";
CString cszCB_OpenWindow = "CB_OpenWindow";
CString cszCB_ShowModalDialog = "CB_ShowModalDialog";
CString cszCB_ShowModelessDialog = "CB_ShowModelessDialog";
CString cszCB_AttachTemplate ="CB_AttachTemplate";
#define DISPID_CB_IsOurCustomBrows er 1
#define DISPID_CB_Close 2
#define DISPID_CB_CustomFunction 3
#define DISPID_CB_CustomFunctionWi thParams 4
#define DISPID_CB_OpenWindow 5
#define DISPID_CB_ShowModalDialog 6
#define DISPID_CB_ShowModelessDial og 7
#define DISPID_CB_AttachTemplate 8
/*
* CImpIDispatch::CImpIDispat ch
* CImpIDispatch::~CImpIDispa tch
*
* Parameters (Constructor):
* pSite PCSite of the site we're in.
* pUnkOuter LPUNKNOWN to which we delegate.
*/
CImpIDispatch::CImpIDispat ch( void )
{
m_cRef = 0;
}
CImpIDispatch::~CImpIDispa tch( void )
{
ASSERT( m_cRef == 0 );
}
/*
* CImpIDispatch::QueryInterf ace
* CImpIDispatch::AddRef
* CImpIDispatch::Release
*
* Purpose:
* IUnknown members for CImpIDispatch object.
*/
STDMETHODIMP CImpIDispatch::QueryInterf ace( 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(voi d)
{
return --m_cRef;
}
//IDispatch
STDMETHODIMP CImpIDispatch::GetTypeInfo Count(UINT * /*pctinfo*/)
{
return E_NOTIMPL;
}
STDMETHODIMP CImpIDispatch::GetTypeInfo (
/* [in] */ UINT /*iTInfo*/,
/* [in] */ LCID /*lcid*/,
/* [out] */ ITypeInfo** /*ppTInfo*/)
{
return E_NOTIMPL;
}
STDMETHODIMP CImpIDispatch::GetIDsOfNam es(
/* [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_IsOurCustomBrows er;
}
else if(cszName == cszCB_Close)
{
rgDispId[i] = DISPID_CB_Close;
}
else if(cszName == cszCB_CustomFunction)
{
rgDispId[i] = DISPID_CB_CustomFunction;
}
else if(cszName == cszCB_CustomFunctionWithPa rams)
{
rgDispId[i] = DISPID_CB_CustomFunctionWi thParams;
}
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_ShowModelessDial og;
}
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_UNK NOWNNAME);
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_IsOurCustomBrows er)
{
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_IsOurCustomBrowse r();
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_CustomFunctionWi thParams)
{
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].bst rVal; // in case you want a CString copy
int nArg2= pDispParams->rgvarg[0].int Val;
pDlg->CB_CustomFunctionWit hParams(cs zArg1, 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].bst rVal; // in case you want a CString copy
int nArg2= pDispParams->rgvarg[4].int Val;
int nArg3= pDispParams->rgvarg[3].int Val;
int nArg4= pDispParams->rgvarg[2].int Val;
int nArg5= pDispParams->rgvarg[1].int Val;
int nArg6 = pDispParams->rgvarg[0].int Val;
pDlg->CB_OpenWindow(cszArg 1, nArg2, nArg3, nArg4, nArg5, nArg6);
}
}
if(dispIdMember == DISPID_CB_ShowModelessDial og)
{
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].bst rVal; // in case you want a CString copy
int nArg2= pDispParams->rgvarg[3].int Val;
int nArg3= pDispParams->rgvarg[2].int Val;
int nArg4= pDispParams->rgvarg[1].int Val;
int nArg5= pDispParams->rgvarg[0].int Val;
pDlg->CB_ShowModelessDialo g(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].bst rVal; // in case you want a CString copy
int nArg2= pDispParams->rgvarg[3].int Val;
int nArg3= pDispParams->rgvarg[2].int Val;
int nArg4= pDispParams->rgvarg[1].int Val;
int nArg5= pDispParams->rgvarg[0].int Val;
pDlg->CB_ShowModalDialog(c szArg1, 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].bst rVal; // in case you want a CString copy
int nArg2= pDispParams->rgvarg[0].int Val;
pDlg->CB_AttachTemplate(cs zArg1, nArg2);
}
}
return S_OK;
}
NOTE that the function then is
void CCustomBrowserDlg::CB_Atta chTemplate (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_CustomFunctionWithPara ms()'
/*
* 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_CustomFunctionWithPa
CString cszCB_OpenWindow = "CB_OpenWindow";
CString cszCB_ShowModalDialog = "CB_ShowModalDialog";
CString cszCB_ShowModelessDialog = "CB_ShowModelessDialog";
CString cszCB_AttachTemplate ="CB_AttachTemplate";
#define DISPID_CB_IsOurCustomBrows
#define DISPID_CB_Close 2
#define DISPID_CB_CustomFunction 3
#define DISPID_CB_CustomFunctionWi
#define DISPID_CB_OpenWindow 5
#define DISPID_CB_ShowModalDialog 6
#define DISPID_CB_ShowModelessDial
#define DISPID_CB_AttachTemplate 8
/*
* CImpIDispatch::CImpIDispat
* CImpIDispatch::~CImpIDispa
*
* Parameters (Constructor):
* pSite PCSite of the site we're in.
* pUnkOuter LPUNKNOWN to which we delegate.
*/
CImpIDispatch::CImpIDispat
{
m_cRef = 0;
}
CImpIDispatch::~CImpIDispa
{
ASSERT( m_cRef == 0 );
}
/*
* CImpIDispatch::QueryInterf
* CImpIDispatch::AddRef
* CImpIDispatch::Release
*
* Purpose:
* IUnknown members for CImpIDispatch object.
*/
STDMETHODIMP CImpIDispatch::QueryInterf
{
*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(voi
{
return --m_cRef;
}
//IDispatch
STDMETHODIMP CImpIDispatch::GetTypeInfo
{
return E_NOTIMPL;
}
STDMETHODIMP CImpIDispatch::GetTypeInfo
/* [in] */ UINT /*iTInfo*/,
/* [in] */ LCID /*lcid*/,
/* [out] */ ITypeInfo** /*ppTInfo*/)
{
return E_NOTIMPL;
}
STDMETHODIMP CImpIDispatch::GetIDsOfNam
/* [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_IsOurCustomBrows
}
else if(cszName == cszCB_Close)
{
rgDispId[i] = DISPID_CB_Close;
}
else if(cszName == cszCB_CustomFunction)
{
rgDispId[i] = DISPID_CB_CustomFunction;
}
else if(cszName == cszCB_CustomFunctionWithPa
{
rgDispId[i] = DISPID_CB_CustomFunctionWi
}
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_ShowModelessDial
}
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_UNK
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_IsOurCustomBrows
{
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_IsOurCustomBrowse
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_CustomFunctionWi
{
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].bst
int nArg2= pDispParams->rgvarg[0].int
pDlg->CB_CustomFunctionWit
}
}
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].bst
int nArg2= pDispParams->rgvarg[4].int
int nArg3= pDispParams->rgvarg[3].int
int nArg4= pDispParams->rgvarg[2].int
int nArg5= pDispParams->rgvarg[1].int
int nArg6 = pDispParams->rgvarg[0].int
pDlg->CB_OpenWindow(cszArg
}
}
if(dispIdMember == DISPID_CB_ShowModelessDial
{
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].bst
int nArg2= pDispParams->rgvarg[3].int
int nArg3= pDispParams->rgvarg[2].int
int nArg4= pDispParams->rgvarg[1].int
int nArg5= pDispParams->rgvarg[0].int
pDlg->CB_ShowModelessDialo
}
}
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].bst
int nArg2= pDispParams->rgvarg[3].int
int nArg3= pDispParams->rgvarg[2].int
int nArg4= pDispParams->rgvarg[1].int
int nArg5= pDispParams->rgvarg[0].int
pDlg->CB_ShowModalDialog(c
}
}
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].bst
int nArg2= pDispParams->rgvarg[0].int
pDlg->CB_AttachTemplate(cs
}
}
return S_OK;
}
NOTE that the function then is
void CCustomBrowserDlg::CB_Atta
{
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_CustomFunctionWithPara
ASKER
I tried that, and then got this compile error:
C:\Documents and Settings\Administrator\Des ktop\Brows er\CustomB rowser\Cus tomBrowser \Idispimp. cpp(382) : error C2664: 'CB_AttachTemplate' : cannot convert parameter 1 from 'class CString' to 'char *'
C:\Documents and Settings\Administrator\Des
Sorry, make that
void CCustomBrowserDlg::CB_Atta chTemplate (CString TargetPath, int nVal)
{
CFileOperation fo;
fo.Delete(TargetPath);
CopyFile(strVal, TargetPath, true);
return;
}
void CCustomBrowserDlg::CB_Atta
{
CFileOperation fo;
fo.Delete(TargetPath);
CopyFile(strVal, TargetPath, true);
return;
}
ASKER
Now getting:
C:\Documents and Settings\Administrator\Des ktop\Brows er\CustomB rowser\Cus tomBrowser \CustomBro wserDlg.cp p(1565) : error C2065: 'strVal' : undeclared identifier
C:\Documents and Settings\Administrator\Des
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].bst rVal; // in case you want a CString copy
CString cszArg2= pDispParams->rgvarg[0].bst rVal; // in case you want a CString copy
pDlg->CB_AttachTemplate(cs zArg1, cszArg2);
}
}
//...
void CCustomBrowserDlg::CB_Atta chTemplate (CString SourcePath, CString TargetPath)
{
CFileOperation fo;
fo.Delete(TargetPath);
CopyFile(SourcePath, TargetPath, true);
return;
}
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].bst
CString cszArg2= pDispParams->rgvarg[0].bst
pDlg->CB_AttachTemplate(cs
}
}
//...
void CCustomBrowserDlg::CB_Atta
{
CFileOperation fo;
fo.Delete(TargetPath);
CopyFile(SourcePath, TargetPath, true);
return;
}
ASKER
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?
The instruction at "0x10217c5f" referenced memory at "0x00000007". The memory could not be "read".
Any ideas?
ASKER
I also just noticed, you got rid of my array, why? I need to be able to send an array...
ASKER
I need to be able to keep the function like this:
void CCustomBrowserDlg::CB_Atta chTemplate (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)
?
void CCustomBrowserDlg::CB_Atta
{
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)
?
ASKER
Is there maybe a way to convert this:
CString cszArg2= pDispParams->rgvarg[0].bst rVal; // 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.
CString cszArg2= pDispParams->rgvarg[0].bst
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.
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...
Regarding the array: That functionality is is a lot more complex than it seems at first glance - let me see...
ASKER
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].int Val;
//
//string aEndArray[nArg2];
// arguments come in reverse order
// for some reason
CComPtr<IDispatchEx> pDispEx;
HRESULT hr=pDispParams->rgvarg[1]. pdispVal-> QueryInter face(IID_I DispatchEx ,(void**)& pDispEx);
DISPID dispid;
// get the DISPID of the first item.
hr = pDispEx->GetNextDispID(fde xEnumAll, DISPID_STARTENUM, &dispid);
while (hr == NOERROR)
{
// get the item name
CComBSTR bstrName;
hr = pDispEx->GetMemberName(dis pid, &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(fde xEnumAll, dispid, &dispid);
}
struct tagSAFEARRAY *cszArg1= pDispParams->rgvarg[1].par ray; // in case you want a CString copy
// call the end function
pDlg->CB_AttachTemplate(nA rg2, cszArg1);
}
}
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].int
//
//string aEndArray[nArg2];
// arguments come in reverse order
// for some reason
CComPtr<IDispatchEx> pDispEx;
HRESULT hr=pDispParams->rgvarg[1].
DISPID dispid;
// get the DISPID of the first item.
hr = pDispEx->GetNextDispID(fde
while (hr == NOERROR)
{
// get the item name
CComBSTR bstrName;
hr = pDispEx->GetMemberName(dis
// 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(fde
}
struct tagSAFEARRAY *cszArg1= pDispParams->rgvarg[1].par
// call the end function
pDlg->CB_AttachTemplate(nA
}
}
ASKER
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.