|
There isnt any other way? Because there is a lot of code I have to change if I change the type of that one variable. I'd prefer keeping value as a LPSTR type.
|
|
|
|
|
Well, in that case, as Laxman says, you need to carefully check the sizes of your source and destination buffers.
For future code though I recommend using string objects (string or CString) instead of C-style strings. You'll have fewer problems of this sort.
Kevin
|
|
|
|
|
Is there really a need to pass by reference cos i think it can work without it.
|
|
|
|
|
It's a problem with RegQueryValue(IMHO). You are not opening the registry before modifying it.
Handle to an open key. The key must have been opened with the KEY_QUERY_VALUE access right.
This handle is returned by the RegCreateKeyEx or RegOpenKeyEx function, or it can be one of the following predefined keys:
HKEY_CLASSES_ROOT
HKEY_CURRENT_CONFIG
HKEY_CURRENT_USER
HKEY_LOCAL_MACHINE
HKEY_PERFORMANCE_DATA
HKEY_PERFORMANCE_NLSTEXT
HKEY_PERFORMANCE_TEXT
HKEY_USERS
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Ya I created a handle to the open key and all of that is fine (closed the handle appropriately etc). Its just with the strcpy that I'm having the problems with.
As well, either by passing via reference or returning LPSTR value, I am still receiving the same unhandled exception error. It still crashes when my program is loaded.
|
|
|
|
|
I just did a test using your code(with some modifications in bold) except without the reference and it works fine.:
void somefunc()
{
char cBuffer[400];
retrieveLogFileLocation(cBuffer);
}
bool retrieveLogFileLocation(LPSTR value)
{
char lszValue[255];
HKEY hKey = HKEY_LOCAL_MACHINE;
LONG returnStatus;
DWORD dwType = REG_SZ;
DWORD dwSize =255;
bool success = true;
RegQueryValueEx(hKey, "InstallationPath", NULL, &dwType, (LPBYTE)&lszValue, &dwSize);
strcpy(value, lszValue);
return true;
} I set hKey just for testing purposes. It could be a problem with your key.
Last modified: Monday, June 19, 2006 4:57:58 AM --
|
|
|
|
|
_AnShUmAn_ wrote: You are not opening the registry before modifying it.
While it's true that the registry key must be opened prior to use, it's certainly not being modified.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
capricious_001 wrote: bool retrieveLogFileLocation(LPSTR& value){
What is the size of the variable that value refers to?
capricious_001 wrote: char[255] lszValue;
What's this?
capricious_001 wrote: RegQueryValueEx(hKey, "InstallationPath", NULL, &dwType, (LPBYTE)&lszValue, &dwSize);
What does RegQueryValueEx() return?
capricious_001 wrote: strcpy(value, lszValue);
Use strncpy() instead.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
How could I show a CString use notepad.exe without saving the string into a txt file?
|
|
|
|
|
See
<br />
::ShellExecute(NULL,_T("open"),_T("notepad.exe"),NULL,NULL,SW_SHOWNORMAL);<br />
Sleep(150);<br />
<br />
HWND hNoteWnd=::FindWindow(_T("Notepad"),NULL);<br />
LPCTSTR MY;<br />
MY=_T("Check");<br />
<br />
CWnd* hEditWnd=FindWindowEx(hNoteWnd,NULL,_T("Edit"),NULL);<br />
::SendMessage(hEditWnd->m_hWnd,WM_SETTEXT,0,(LPARAM)MY);<br />
<br />
whitesky
|
|
|
|
|
WhiteSky wrote: Sleep(150);
HWND hNoteWnd=::FindWindow(_T("Notepad"),NULL);
Use ShellExecuteEx() and these two statements can be avoided.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Thank you Mr DavidCrow for information
whitesky
|
|
|
|
|
|
Hi guys
I get following error when running my program.
Run-Time Check Failure #2 - Stack around the variable 'Temp' was corrupted.
where 'Temp' is a pointer to a class.
Does anyone know what the source of this run time error is ?
regards
Mahdi
|
|
|
|
|
Maybe you have some strings (or arrays) around the Temp variable, and you assigned too long values to that strings?
|
|
|
|
|
m_monhi wrote:
Does anyone know what the source of this run time error is ?
Could you provide some code snippet..??
Knock out 't' from can't,
You can if you think you can
|
|
|
|
|
m_monhi wrote:
Run-Time Check Failure #2 - Stack around the variable 'Temp' was corrupted.
Initialize Temp variable with NULL.. are you using Temp variable without being intialise.. this is common error arises in Visual Studio .net 2003 and above
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Can you show your code that has error
whitesky
|
|
|
|
|
how can we apply socket program to send data from parent dialog to child dialog;
sree.
|
|
|
|
|
And why would one do this?
It's easy to pass data from parent dialog to child dialog using GetParent()......
etc.
However you will have to create a socket in your parent dialog, send data on it and then keep on listening to the port that you are binding the socket to, in your child dialog(in your case).
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
can be more detail on both types please it is very important to me and also urgent.
sree
|
|
|
|
|
wrote:
can be more detail on both types please it is very important to me and also urgent.
Just create the pointer of the Parent dialog into child dialog and before modeling the child dialog just assign the parent dialog pointer and now you can get the access to parent dialog;'s data from its child dialog.
Knock out 't' from can't,
You can if you think you can
|
|
|
|
|
You can use GetParent() to get the pointer to the parent class in the child dialog and then do whatever you want with those variables.
ex:
CTestDlg* wnd=(CTestDlg*)GetParent ();
wnd->m_edit .SetWindowText ("Anshuman");
where CTestDlg is the parent class and in OnInitDialog of the class associated with the child dialog I have written the above two lines of code. From the second dialog I am setting the text to the edit(m_edit is the control variable) window on the first ie parent dialog
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
here we r sending the data from child to parent.but what our intension from parent to child .because we must send points from parent.
sree.
|
|
|
|
|
I showed you how you can access variables, controls etc from the child dialog that are in the parent dialog. In the same manner you can access functions from the parent dialog in the child dialog. It was not about how you return values from child to parent but it showed how you can do it other way round.
Suppost you are having a function in your parent dialog
CPoint ReturnPoints()
{
return xpoint; //xpoint is a variable in your code of CPoint type
}
You can use this function as
CPoint valueOfPoint=wnd->ReturnPoints();
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|