?
Solved

Getting errors when trying to call a Class Function...

Posted on 2003-03-05
9
Medium Priority
?
471 Views
Last Modified: 2010-10-05
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
0
Comment
Question by:deadlyfluvirus
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 30

Accepted Solution

by:
SteveGTR earned 400 total points
ID: 8072570
You could try using the MFC class COleVariant:

m_strHTML = m_Inet1.OpenURL(COleVariant(strURL, VT_BSTRT), &lngAccessType);

Good Luck,
Steve
0
 
LVL 86

Expert Comment

by:jkr
ID: 8072594
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);
}
0
 

Author Comment

by:deadlyfluvirus
ID: 8073699
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
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 86

Expert Comment

by:jkr
ID: 8073747
>>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?
0
 

Author Comment

by:deadlyfluvirus
ID: 8073831
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
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 8074189
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
0
 

Author Comment

by:deadlyfluvirus
ID: 8074279
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
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 8074544
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;
0
 
LVL 11

Expert Comment

by:bcladd
ID: 9888289
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 (http://www.experts-exchange.com/help.jsp#hi73).

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

-bcl (bcladd)
EE Cleanup Volunteer
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

765 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