|
The asin() function returns the arcsine as a double .
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Hi all,
I'm a newbie in C++ and pointers also. I have two questions that confused my mind.
1. What is the difference between
int a = 25;
int& PtrA = a;
and
int* PtrA = &a;
2. Why these two returns different answers?
int* c = &a;<br />
<br />
cout << "(*c) + 1 is " << (*c) + 1 << endl;<br />
cout << "(*c)++ is " << (*c)++ << endl;
Kind Regards,
-
When in doubt, push a pawn!
-
|
|
|
|
|
I have found my mistake on second question.
It should be
cout << "++(*c) is " << ++(*c) << endl;
in order to get same results.
However, still confused on the first question...
Regards,
-
When in doubt, push a pawn!
-
|
|
|
|
|
1a. (int &PtrA = a;) In this case "PtrA" is a reference to "a"... sort of like saying they are one in the same. use PtrA in exactly the same way as you would "a". Only thing is that changes to "PtrA" effects "a" and vise versa.
example:
cout << a;
cout << PtrA; // both output the same value.
cout << &a;
cout << &PtrA; // both output the same address.
PtrA = 10; // after this statement both a and PtrA equals 10.
a = 15; // after this statement, both a and PtrA equals 15.
1b. (int *PtrA = &a;) "PtrA" in this case is a pointer to "a." Almost the same as references except in the way you use them.
PtrA // gives the addess of "a"
*PtrA // gives the value of "a"
as opposed to references where
PtrA // gives the value of "a"
&PtrA // gives the address of "a"
cout << *PtrA;
cout << a; //both output the same value.
cout << PtrA;
cout << &a; // both output the same address.
*PtrA = 10; //after this statment both a and *PtrA equals 10
a = 15; // after this statment both a and *PtrA equals 15
2. (*c)+1 adds one to the value of *c first then prints it but it doesn't store the value.
(*c)++ is post incrementing...so it uses value of *c first and then it adds one after the statement. Incrementing also stores the value back into *c. When you use x++ its like saying x = x + 1. So in your case it would be *c = c*+1.
you could use pre increment ++(*c). In this case it increments first and then uses the value. Stores it also...
Hope that wasn't too confusing...=)
|
|
|
|
|
Hi Mandroid,
Your explanation solved lots of confused parts about pointers in my mind, thank you. Nonetheless, I stuck on some point we can get the Address of Pointer by typing &Pointer but how can we get the Address of Reference? I mean the place that Reference is stored in memory?
Regards,
-
When in doubt, push a pawn!
-
|
|
|
|
|
Thats a good question. The answer is you can't! The compiler does some nifty stuff underneath it all as to how its implemented and stored, but as far as you are concerned you can't get the actual address of the reference. Unlike pointers, there is no command in C++ that returns the physical PHYSICAL address of a reference. To you, the reference and the referent should just be aliases for the same place in memory. Hope that helps...
|
|
|
|
|
Thanks for your rapid and kind help...
-
When in doubt, push a pawn!
-
|
|
|
|
|
There are few articles about registries but I could not find what I wanted.
I am trying to read a registry that I do not know what the name is. let me explain.
When an application is installed, it createds a registry name (?) based on the user entry however, this registry always contains a key called TIME (\SOFTWARE\MYREG\?\TIME). The TIME key contains values that I want to red.
How do I query/Read all keys under MYREG?
Thankx in advanced.
|
|
|
|
|
I think you like this---
The RegEnumKeyEx function enumerates subkeys of the specified open registry key. The function retrieves information about one subkey each time it is called. <br />
<br />
LONG RegEnumKeyEx(<br />
HKEY hKey,
DWORD dwIndex,
LPTSTR lpName,
LPDWORD lpcName,
LPDWORD lpReserved,
LPTSTR lpClass,
LPDWORD lpcClass,
PFILETIME lpftLastWriteTime
);
-----------------------------
"I Think It Will Help"
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
help me how to find IP of INTERNET RADIO. thanks
Nho'c Ti`
|
|
|
|
|
connect to it, and do a netstat
in the event that you dont how to do a netstat
Start -> Run Or WindowsKey+R
type "command" (without quotes)
when the console opens type "netstat -an" (without quotes)
or you can make a batch file like i have
FileName: Netstat.bat
@netstat -an>C:\netstat.txt
@start C:\netstat.txt
@exit
|
|
|
|
|
hey guys, I need help in reading a device dependent bitmap from the clipboard and displaying it. this needs to be done using win32. gimme some suggestions on how this can be done. Thanks in advance !
|
|
|
|
|
Call GetClipboardData(CF_BITMAP) or GetClipboardData(CF_DIB). You may want to call IsClipboardFormatAvailable(...) first it see if there is a bitmap available.
HANDLE MyGetClipboardBitmap()
{
HANDLE hClipBitmap = GetClipboardData(CF_BITMAP);
if( hClipBitmap )
{
HANDLE hCopy = MyMakeCopy(hClipBitmap);
return hCopy;
}
return NULL;
}
The above example did not call the OpenClipboard() or CloseClipboard(), which you need to call before trying to get anything from the clipboard.
The "Clipboard Functions" page in the MSDN library is kind of hard to locate, but it is there.
Good Luck!
INTP
|
|
|
|
|
when i try to set the wallpaper using this function i can only set a bitmap, to the best of my knowledge its suposed to work for all formats. anyone have any idea as to why it wont set anything but bitmaps?
note: OS = Win M.E.
if not if you know how to infom the desktop that the registry key has been changed then that would work just as well
|
|
|
|
|
As far as I know, it can only do bmp
<italic>Work hard and a bit of luck is the key to success. You don`t need to be genius, to be rich.
|
|
|
|
|
I have been trying to figure out how to use a try/catch throw statement to handle a file input error. All the block has to do is check to see if the file exists...if the file does not exist then it displays the message "File xxx.xxx does not exist." Any help is greatly appreciated. I have been trying to read my programming book on try/catch throw but it doesn't really give you a good idea how to use it with ifstream.
David Slone
|
|
|
|
|
By default the IOStreams libraries set error bits, if you're looking to use iostreams with exceptions you'll need to specify this manually. The following sample was based on http://www.cplusplus.com/ref/iostream/ios/exceptions.html
int main () {
ifstream file;
file.exceptions ( ifstream::eofbit | ifstream::failbit | ifstream::badbit );
try {
file.open ("test.txt");
}
catch (ifstream::failure e) {
cout << "Exception opening/reading file";
}
file.close();
return 0;
}
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts your aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
hi everyone..
i want to use mktyplib to make a tlb from an odl file but i get this error:
fatal error M0006 : unable to pre-process input file
i tried the mktyplib that comes with VStudio .net and the one that comes from VStudio 6 but both give the same error...
i thought the file might be wrong in syntax or something like that but i tried alot of odl files especially the ones that come in the include directory..
|
|
|
|
|
I am a MDI project. it gets data from outside and display them. I think the data should in Doc class. so I and Data object in MyDoc. I create a thread to read peripheral at 50ms interval. and call MyDoc::HandleData(). everything is fine so far. but when execute to there pDoc->UpdateAllViews(NULL) inside HandleDate(). It ASSERT(FASLE), (debug mode). I know it is because thread problem.( there are explain in the void CWnd::AssertValid() const. I wonder if there is a easy solution. anybody have idea?
|
|
|
|
|
It has been a while!
Essenualy your thread should not be calling function in you document class. I would sugest you thread safe class (directions in MSDN library) which you allocate and initialize in your document (a ponter to data). Pass a pionter to the data class to your thread and use event signals to inform you when the data has changed. This may require you to use OnTimer() some where to check when an modified event has occured.
MyClass::OnTime()
{
if( Event happened )
UpdateAllViews(NULL);
}
MyClass::OnUpdate( CView* pSender, LPARAM lHint, CObject* pHint )
{
if( pSender != this )
InvalidateWindow();
}
MyClass::OnPaint(...)
{
pDoc->mydata.lock();
pDoc->mydata.unlock();
}
Oh well, it should work something like that. You would probably want to maintain to copies of the data one for used by the your updata thread and one that holds a copy of the last update, that way you will not be trying to lock data access every time you need to repaint the data (leads to some unexpected results).
As usual there are some articles at CP on the subject and who knows one of them may have already solve your problem.
I hope this helps a little!
Oh! One last possibility is to use a CMemFile(), they can be share by multiple thread via a handle. By you'll still need a method to determine when the data has changed.
Good Luck!
INTP
|
|
|
|
|
OnTimer() won't work for Doc. What is "thread safe class"?
|
|
|
|
|
Type "thread safe class" in the index section of the MSDN library window, the information should be baried in there some where.
The OnTimer() function is the tricky part, for the method I was thinking about. You would only need to receive timer messages in one of your views, which would probably call one of your document function to make a copy of the udated data (before posting the update-all function). The problem is that if you close that view you would stop receiving the timer messages.
If the application only displays views of this particular data (and nothing else), then you could use an OnTimer() function in your main window and update the first document (of the specified type) you find from there.
Of cource with this last method you could store the data globaly and ignore the actual document class all together. (just using multi-doc to simplify the creation of multiple views)
Using a multi-doc interface in this fashion seems like a bit of a cludge, but it can work.
There is also the possiblity of creating a hidden view of the data that receives the OnTimer() messages (That is created just when the first visable view is created). You would have to close this view after the last visable view was closed.
Keep in mind that you may not even need to gather the data in a seperate thread, because unless you are recording each change for future use or study you only need it to update the views and (depending on the amount of data, and number of views) it may take longer than 50ms to do that.
Well if nothing else I hope I have stimulated your imagination with other possiblities.
Taa! Taa!
INTP
|
|
|
|
|
You can't (easilly) use any CWnd functions from a thread that the CWnd wasn't created in. The best way to handle your problem is to use PostMessage() to post back to the main thread and get it to update the views.
Alternatively you could set a flag in your document whenever the data changes and then use CDocument::OnIdle() to check the flag and call UpdateAllViews() if it set, and then reset the flag.
Neville Franks, Author of ED for Windows www.getsoft.com and Surfulater www.surfulater.com "Save what you Surf"
|
|
|
|
|
Thank you for your suggestion. It sounds great. But I already figure out a solution. I'd like to share with friends.
in stead of set a flag, I postmessage( CMainWnd* , WM_COMMAND, ID_XXX, 0 ). this Command is post to Mainframe, mainframe then routed to CDoc. so In MyDoc, just handle OnCmdMsg(ID_XXX, handler).
enjoy it.
Thanks to all your kindness reply
|
|
|
|
|
My project shows 3 help files in the Solution Explorer:-
Help Files
-- My_Prog.cnt
-- bullet.bmp
-- afxrtf.rtf
Currently when help is selected (say F1 key) I get the blank default page.
e.g.
<<YourApp>> Help Index<br />
<br />
<< Write a topic here that discusses your application's main dialog.>>
Now if I right click on the My_Prog.cnt file and open it with hcrtf I can added Help items into it but when I test it (Contents OK) I get the error:-
The topic does not exist. Contact your application vendor for an updated Help file. (129). But my program does not call up the correct file, still get the default help page.
Now I started to use a freeware program Cheetah to added the rtf data and also used Microsoft WorkShop (hcrtf)to take the Cheetah produced rtf file and compile to help files.
I can produce a help file that works fine on its own.
But how do I integrate it into my project.
If I copy over the new help files into the project I get the following error when I try and run Help.
The topic does not exist. Contact your application vendor for an updated Help file. (129).
I did try renaming files, and adding/removing help files from the project etc, but still no luck.
I seem to be going around in circles, any Help out there?
Can I link in the compiled Help producted by the freeware program and Microsoft Workshop.
Or how can I write the help using Visual Studio?
grahamfff
|
|
|
|