|
|
Hi!
I've decalred a pointer variable inside a class. I'm assigning value to this variable inside a function. I've to make this variable visible to classes in other files. How to make this visible to other files?
|
|
|
|
|
it depends on the relationship between the two classes. However an instance or pointer to an instance of the first class is required to access its members from another classes. So keep a pointer to the first class in other classes from which you want to access the variable. Or declare the variable as 'public static' so that it canbe be accessed from anywhere by using ClasssName::variable syntax.
|
|
|
|
|
If you really want to do this (and judging by other questions you've posted on these forums I'm waiting for the inevitable "my pointer's being overwritten/when I dererference the pointer an exception is thrown" question) then:
- add a member function to the class that returns the pointer
- include the header with the class in it to the other files that contain code that you want to mangle^h^h^h^h^h^haccess the pointer.
Generally (although not always) it's a bad idea to expose a class's internally dangly bits to the outside world like this though. If you start thinking of classes less as dumping grounds for data but as things that do stuff your question changes from: "How do I access this pointer?" to "what behaviour do I want my class to have?" You'll probably find that you only need a small subset of what unfettered pointer access gives you in the code you currently think of as wanting access and your code will be a bit safer as a result.
Cheers,
Ash
|
|
|
|
|
{
DWORD dw;
int i;
char ch;
printf("Enter first value=");
scanf("%x",&dw);
printf("\nEnter second value=");
scanf("%d",&i);
printf("\nEnter single character=");
//control not stop here......
scanf("%c",&ch);
}
Here program control does not stop at
"scanf("%c",&ch);"
Waiting 4 reply.
Thanks
Sagar
|
|
|
|
|
So what values have you entered for the two integers before the scanf for the character? If you entered "Fred" at the first prompt then no conversion will happen and there'll still be characters left in the buffer for the final call.
To get around this check the return value of scanf to make sure that you're actually reading and converting something. If it's zero read everything you can and try and try again.
And I've just noticed that you're reading a DWORD using %x. Even if it doesn't fail you want to be reading values through this format specifier into an int.
Cheers,
Ash
PS: The final call to scanf, does it leave a newline character in ch ? I can't remember how scanf processes newlines but it might be an avenue to investgate.
Edited to correct my Unglish.
modified on Wednesday, July 28, 2010 4:28 AM
|
|
|
|
|
By "Enter Key" control goes to next line.
And in ch value of last "Enter key" pressed was coming.
The solution for my problem is, need to flush the standrad input stream using fflush(stdin).
Thank you for response.
|
|
|
|
|
After every scanf statement put the statement fflush(stdin) .
This clears the keyboard buffer of any leftover characters.
|
|
|
|
|
Can any one give tips in how to use pdb file. Currently i am working in real time project. Where we give only the executable to customer. Rare occasion the appilication crashes. Is analysing pdb is good procedure. If so how to generate pdb for release version VC++. What settings has to be made set . If any give me simple example it much helpful for me.Thanks in advance.......
|
|
|
|
|
Open the properties window of your project and select the release configuration, then:
- in the general section of C++ properties, ensure that the field Debug Information Format is set to Program Database (/Zi)
- in the debugging section of Linker properties, ensure that the field Generate Debug Info is set to Yes (/DEBUG) (the field Generate Program Database File will hold the path of the generated pdb file)
Cheers,
Sauro
|
|
|
|
|
If you ship release binaries to the customer your code will be optimised and therefore using the pdb file will make no sense. In the past I've logged a callstack to a file when an unhandled exception has occurred by setting a hook into the kernel exception handler the walking the stack. Doing this can give you a stack in hex (though functions are often missing due to optimisation). You can then decode the stack information using a map and cod files generated at build time giving you the line in the code that caused the exception.
|
|
|
|
|
|
BOOL checkExistence(HKEY *hKey, LPCTSTR lpszAppName)
{
CRegKey regKey;
if( regKey.Open(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"),
KEY_READ) != ERROR_SUCCESS )
return FALSE;
DWORD dwIndex = 0;
DWORD cbName = 128;
TCHAR szSubkeyName[128];
CString strSubkeyName;
int nHasAllItems = 0;
while( regKey.EnumKey(dwIndex, szSubkeyName, &cbName) != ERROR_NO_MORE_ITEMS )
{
dwIndex++;
cbName = 128;
strSubkeyName.Format(_T("%s"), szSubkeyName);
if( strSubkeyName.Compare(lpszAppName) )
{
nHasAllItems++;
continue;
}
else
break;
}
regKey.Close();
if( nHasAllItems == dwIndex )
return FALSE;
else
{
*hKey = regKey.m_hKey;
return TRUE;
}
}
I wrote this funx to check whether there's a particular installed app in the registry. After calling this funx, hKey is expected to be assigned the registry handle. But prob occurs as Ive indicated above.
|
|
|
|
|
How are you calling checkExistence() ?
Krauze wrote: strSubkeyName.Format(_T("%s"), szSubkeyName);
What's wrong with:
strSubkeyName = szSubkeyName;
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
I mean:
*hKey = regKey.m_hKey;
Prob occurs here.
|
|
|
|
|
How are you calling checkExistence() ?
Aso, have you considered something a little more manageable, like:
BOOL checkExistence( HKEY *hKey, LPCTSTR lpszAppName )
{
CString strKey;
strKey.Format(_T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\%s"), lpszAppName);
return RegOpenKey(HKEY_LOCAL_MACHINE, strKey, hKey) == ERROR_SUCCESS;
}
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
In fact Ive tried this method later. And it works perfectly.
|
|
|
|
|
"hKey is expected to be assigned the registry handle."
but how as you did regKey.Close(); before *hKey = regKey.m_hKey; ??
Try
*hKey = regKey.Detach(); Remeber to call RegCloseKey() on the obtained handle once finished using it.
modified on Wednesday, July 28, 2010 1:30 AM
|
|
|
|
|
regKey.Close();
*hKey = regKey.m_hKey;
after closing the key the handle is invalid. You really shouldnt do that
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
Hi,
I have MFC dialog app and there is hosted WindowsFormsControl.
In MFC app it is declared as: CWinFormsControl<windowsformscontrollibrary1::usercontrol1> m_ctrl1;
Could somebody explain me why I can use it as a pointer: m_ctrl1->textBox1 and as a object: m_ctrl1.GetControl()
|
|
|
|
|
See CWinFormsControl is a template class.
template<class TManagedControl>
class CWinFormsControl : public CWnd
It has the -> operator overloaded to return TManagedControl.
inline TManagedControl^ operator->( ) const;
Then m_ctrl1->textBox1 will be TManagedControl->textbox. Also, GetControl() is a method of CWinformControl and it gets called when you use m_ctrl1.GetControl().
inline TManagedControl^ GetControl( ) const;
http://msdn.microsoft.com/en-us/library/7f8b5xd9(v=VS.80).aspx[^]
|
|
|
|
|
Thank you for explanation.
|
|
|
|
|
Hello,
Does anyone know how I might handle file inputs to my MFC program? So basically say windows is configured to launch my app for files with a given extension. What do I need to do in MFC so that I can get the path to the file and process it accordingly?
Many thanks,
Keith
|
|
|
|
|
All that you should do is check out HKEY_CLASSES_ROOT. And write the handler for command lines that are transferred to your app when opening the files.
|
|
|
|
|