Link to home
Start Free TrialLog in
Avatar of deadlyfluvirus
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,&lngAccessType);

     UpdateData(FALSE);
}

When I try and execute the program, it gives me an error of:
C:\My Documents\nussch01\c++\Inet_Test\Inet_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
ASKER CERTIFIED SOLUTION
Avatar of SteveGTR
SteveGTR
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jkr
As the 1st arg indeed is a VARIANT, you have to provide one:

#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,&lngAccessType);

    UpdateData(FALSE);
}
Avatar of deadlyfluvirus
deadlyfluvirus

ASKER

OK, the function calling now looks like:
m_Inet1.OpenURL(COleVariant(strURL,VT_BSTRT),COleVariant(lngAccessType,VT_BSTRT));

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\Inet_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
>>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?
jkr,
 when I tried yours, i got the following error:

C:\C++\Inet_Test\Inet_TestDlg.cpp(103) : error C2065: '__bstr_t' : undeclared identifier

I included that file also...

Thanks, Christian
Try this:

m_Inet1.OpenURL(COleVariant(strURL,VT_BSTRT), COleVariant(lngAccessType, VT_I4));

Or, it looks like you could just say:

m_Inet1.OpenURL(COleVariant(strURL), COleVariant(lngAccessType, VT_I4));

Good Luck,
Steve
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
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(COleVariant(strURL,VT_BSTRT), COleVariant(lngAccessType, VT_I4));

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