Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2003-03-05
9
Medium Priority
?
493 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
  • 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
Industry Leaders: 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!

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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 user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

571 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