deadlyfluvirus
asked on
Getting errors when trying to call a Class Function...
I am trying to call a class function...That function is defined as:
VARIANT CInet::OpenURL(const VARIANT& URL, const VARIANT& DataType)
{
VARIANT result;
static BYTE parms[] =
VTS_VARIANT VTS_VARIANT;
InvokeHelper(0x16, DISPATCH_METHOD, VT_VARIANT, (void*)&result, parms,
&URL, &DataType);
return result;
}
I also have a button on my MFC form that will call the function.
Here is what the code that calls the function looks like:
void CInet_TestDlg::OnGethtml()
{
// TODO: Add your control notification handler code here
CString strURL="www.yahoo.com";
long lngAccessType = 0;
m_Inet1.SetProtocol(4);
m_strHTML = m_Inet1.OpenURL(&strURL,&l ngAccessTy pe);
UpdateData(FALSE);
}
When I try and execute the program, it gives me an error of:
C:\My Documents\nussch01\c++\Ine t_Test\Ine t_TestDlg. cpp(104) : error C2664: 'OpenURL' : cannot convert parameter 1 from 'class CString *' to 'const struct tagVARIANT &'
Reason: cannot convert from 'class CString *' to 'const struct tagVARIANT'
No constructor could take the source type, or constructor overload resolution was ambiguous
Could someone please help?? Thanks, Christian
VARIANT CInet::OpenURL(const VARIANT& URL, const VARIANT& DataType)
{
VARIANT result;
static BYTE parms[] =
VTS_VARIANT VTS_VARIANT;
InvokeHelper(0x16, DISPATCH_METHOD, VT_VARIANT, (void*)&result, parms,
&URL, &DataType);
return result;
}
I also have a button on my MFC form that will call the function.
Here is what the code that calls the function looks like:
void CInet_TestDlg::OnGethtml()
{
// TODO: Add your control notification handler code here
CString strURL="www.yahoo.com";
long lngAccessType = 0;
m_Inet1.SetProtocol(4);
m_strHTML = m_Inet1.OpenURL(&strURL,&l
UpdateData(FALSE);
}
When I try and execute the program, it gives me an error of:
C:\My Documents\nussch01\c++\Ine
Reason: cannot convert from 'class CString *' to 'const struct tagVARIANT'
No constructor could take the source type, or constructor overload resolution was ambiguous
Could someone please help?? Thanks, Christian
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
OK, the function calling now looks like:
m_Inet1.OpenURL(COleVarian t(strURL,V T_BSTRT),C OleVariant (lngAccess Type,VT_BS TRT));
The 2nd value was having the same fit.
There are now no compile-time errors. When I click the GetHTML button however, I get a run-time error:
Debug Assertion Failed!
Program: C:\C++\Inet_Test\Debug\Ine t_Test.exe
File: olevar.cpp
Line: 300
For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts.
(Press Retry to debug the application)
[Abort] [Retry] [Ignore]
What could be causing this?
Thanks, Christian
m_Inet1.OpenURL(COleVarian
The 2nd value was having the same fit.
There are now no compile-time errors. When I click the GetHTML button however, I get a run-time error:
Debug Assertion Failed!
Program: C:\C++\Inet_Test\Debug\Ine
File: olevar.cpp
Line: 300
For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts.
(Press Retry to debug the application)
[Abort] [Retry] [Ignore]
What could be causing this?
Thanks, Christian
>>What could be causing this?
Take a look at that line:
ASSERT(vtSrc == VT_I4 || vtSrc == VT_ERROR || vtSrc == VT_BOOL);
Have you tried my suggestion?
Take a look at that line:
ASSERT(vtSrc == VT_I4 || vtSrc == VT_ERROR || vtSrc == VT_BOOL);
Have you tried my suggestion?
ASKER
jkr,
when I tried yours, i got the following error:
C:\C++\Inet_Test\Inet_Test Dlg.cpp(10 3) : error C2065: '__bstr_t' : undeclared identifier
I included that file also...
Thanks, Christian
when I tried yours, i got the following error:
C:\C++\Inet_Test\Inet_Test
I included that file also...
Thanks, Christian
Try this:
m_Inet1.OpenURL(COleVarian t(strURL,V T_BSTRT), COleVariant(lngAccessType, VT_I4));
Or, it looks like you could just say:
m_Inet1.OpenURL(COleVarian t(strURL), COleVariant(lngAccessType, VT_I4));
Good Luck,
Steve
m_Inet1.OpenURL(COleVarian
Or, it looks like you could just say:
m_Inet1.OpenURL(COleVarian
Good Luck,
Steve
ASKER
SteveGTR,
It is calling the function properly.
One last thing, the OpenURL function returns a VARIANT result. How can I convert this into a string so I can display it in my edit box? The edit box's member variable is set up as a CString with a name of m_strHTML.
Thanks, Christian
It is calling the function properly.
One last thing, the OpenURL function returns a VARIANT result. How can I convert this into a string so I can display it in my edit box? The edit box's member variable is set up as a CString with a name of m_strHTML.
Thanks, Christian
What is the VARIANT result? Is it a long, bool, bstr?
If it's a bstr you might try this:
COleVariant var = m_Inet1.OpenURL(COleVarian t(strURL,V T_BSTRT), COleVariant(lngAccessType, VT_I4));
CString str = (LPCTSTR) var->bstrVal;
If it's a bstr you might try this:
COleVariant var = m_Inet1.OpenURL(COleVarian
CString str = (LPCTSTR) var->bstrVal;
No comment has been added lately, so it's time to clean up this TA. I will
leave a recommendation in the Cleanup topic area that this question is:
Answered: Points to SteveGTR: Grade A
Please leave any comments here within the next seven days.
Experts: Silence means you don't care. Grading recommendations are made in light
of the posted grading guidlines (https://www.experts-exchange.com/help.jsp#hi73).
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
-bcl (bcladd)
EE Cleanup Volunteer
leave a recommendation in the Cleanup topic area that this question is:
Answered: Points to SteveGTR: Grade A
Please leave any comments here within the next seven days.
Experts: Silence means you don't care. Grading recommendations are made in light
of the posted grading guidlines (https://www.experts-exchange.com/help.jsp#hi73).
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
-bcl (bcladd)
EE Cleanup Volunteer
#include <comdef.h>
void CInet_TestDlg::OnGethtml()
{
// TODO: Add your control notification handler code here
//CString strURL="www.yahoo.com";
VARIANT var;
__bstr_t bstr ( "www.yahoo.com");
var.vt = VT_BSTR;
var.bstrVal = bstr;
long lngAccessType = 0;
m_Inet1.SetProtocol(4);
m_strHTML = m_Inet1.OpenURL(var,&lngAc
UpdateData(FALSE);
}