Solved

VC++ statements equivalent to VB.

Posted on 2003-10-29
9
248 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
Independent Software Vendors: 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!

 

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

Independent Software Vendors: 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

Suggested Solutions

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

713 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