Solved

VC++ statements equivalent to VB.

Posted on 2003-10-29
9
246 Views
Last Modified: 2010-04-01
Hello,
I have the following statements in VB.I have a ActiveXcontrol in my form PopXCtl1.
Folder is another COM component which I am using.
Dim InboxFolder As Folder
Set InboxFolder = PopXCtl1.Inbox

Can anyone suggest me how to convert these statements to VC++.
I have used COM component for PopXCtl like given below:
 hresult=CoCreateInstance(__uuidof(PopX),NULL,CLSCTX_ALL,__uuidof(IPopX),(LPVOID *) &popx);
and I am using popx->GetInBox method.
I want to get a statement like in VB
Set InboxFolder = PopXCtl1.Inbox.
I want to use a simlar statement in VC++ for popx->GetInBox ,I want to set the result of this statement to an object of another COM component Folder.
Can anyone help me.
0
Comment
Question by:geethaes
  • 3
  • 3
  • 2
9 Comments
 
LVL 9

Expert Comment

by:_ys_
ID: 9648860
This will probably do what you want. It all depends on how you add a reference the the control.

_Folder *fld = 0; //** verify the type used for Folder **//
hresult = popx->GetInBox(&fld);
//... use it
fld->Release( ); //** mandatory **//
fld = 0;

Automation clients, such as VB, never show you the HRESULTs. The pseudo return value is actually a [retval] attributed parameter.
0
 

Author Comment

by:geethaes
ID: 9655371
I have given like you specified but I got hte error GetInbox function  doesnot take one parameter.
So I gave like this using get_Inbox() method,another method.
IFolder *folder = 0;
hresult= popx->get_Inbox((IDispatch **)folder);
Now I want to use the  GetCount method  of  this Folder.This GetCount method doesnot take any parameter,it returns long integer.
I have in VB
Dim InboxFolder As Folder
Dim n as long
Set InboxFolder = PopXCtl1.Inbox
n = InboxFolder.Count  ,
There are methods Count,GetCount() and get_count(long *pVal) which all has te same functionality of getting count .But I am not able to use these methods of Folder.
I tried to use get_count which takes a paremeter as long *pVal.
I have used as
long count =0;
hresult1 = folder->get_Count(&count);
But I am getting Unhandled exeception error.
Can you plese help me.
0
 
LVL 9

Accepted Solution

by:
_ys_ earned 50 total points
ID: 9656373
>> But I am getting Unhandled exeception error.
As I would expect from the code you provided, because ...

>> IFolder *folder = 0;
>> hresult= popx->get_Inbox((IDispatch **)folder);
inconsistent types specified - IFolder and IDispatch.


You've hinted that get_Inbox expectes an IDispatch interface. So:

IDispatch *pDisp = 0;
hresult = popx->get_Inbox (pDisp);

IFolder *folder = 0;
hresult = pDisp->QueryInterface (IID_IFolder, reinterpret_cast<void**>(&folder));

pDisp->Release ( );

// folder can be used here
// ...

folder->Release ( );


Alternatively, you may be able to get away with not using IDispatch at all. Try this:

IFolder *folder = 0;
hresult = popx->get_Inbox (&folder);

// folder can be used here
// ...

folder->Release ( );
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:geethaes
ID: 9656523
Thanks  a lot it worked out fine.
0
 
LVL 9

Expert Comment

by:_ys_
ID: 9656565
Out of interest, which one worked ... as both are viable.
0
 

Author Comment

by:geethaes
ID: 9656588
I used the first one .
For the second one I got some compiler error of type mismatch of the IFolder and IDispatch.
0
 
LVL 9

Expert Comment

by:tinchos
ID: 10546310
This question has been classified as abandoned.  I will make a recommendation to the moderators on its resolution in approximately one week.  I would appreciate any comments by the experts that would help me in making a recommendation.

It is assumed that any participant not responding to this request is no longer interested in its final deposition.

If the asker does not know how to close the question, the options are here:
http://www.experts-exchange.com/help.jsp#hs5

Tinchos
EE Cleanup Volunteer
0
 
LVL 9

Expert Comment

by:tinchos
ID: 10586367
No comment has been added lately, so it's time to clean up this question.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: _ys_ {http:#9656373}

Please leave any comments here within the next four days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Tinchos
EE Cleanup Volunteer
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

861 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