Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple question

Status
Not open for further replies.

mangocinn

Programmer
Jul 26, 2001
66
US
I am new to C++... please help.

I am using Visual C++ (using MFC).

FunctionA looks like this.
FunctionA(Long* pVal)

I know I can call function A like so..
long bRet;
FunctionA(&bRet);

However if I want to pass the return value as a parameter of another function (FunctionB) call... how do I do that.
I tried
FunctionB(FunctionA())...and it is expecting a parameter. The parameter is just the output.

What is the trick?

Few additional questions:
How do I convert BSTR to std::string?
How do I convert Long to int?
 
Your call should look like this:

Code:
FunctionB(FunctionA(&bRet));

you still have to supply a parameter to FunctionA().

to convert long to int:

Code:
int nNum = (int) lNumber;

or 

int nNum = static_cast<int>(lNumber);

I think using static_cast will catch the error at compile time if you try to convert to a wrong type. also, remember that since a long has more bytes than the int, you could lose part of your number, and your compiler will probably give you a warning about this.

I'm doing this off the top of my head, so I can't really remember the BSTR to std::string one. Maybe convert the BSTR to a LPCTSTR or char*,then convert to std::string.

hope this helps.



BlackDice

 
In 32-bit Operating Systems, long and int are both 4 bytes long.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top