Solved

VC++ statements equivalent to VB.

Posted on 2003-10-29
9
243 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
 

Author Comment

by:geethaes
ID: 9656523
Thanks  a lot it worked out fine.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now