|
|
Hi all,
How can one test for a bad pointer (0xcccccccc)
I have this pointer array, but not all of the element contain data.
<br />
char *SendFiles[10];<br />
I have tried the following, without success...
<br />
if (SendFiles[y] == NULL)<br />
{<br />
...<br />
Thanx in advance
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
|
|
|
|
|
Always always always (and many more ) initialize your variables and pointers in your constructor (or at the start of your program). In your case, loop through the array and set all the pointers to NULL:
for (int i=0;i<10;i++)<br />
{<br />
SendFiles[i] = NULL;<br />
}
|
|
|
|
|
Many, Many Thanx Cédric, never knew that .. kinda
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
|
|
|
|
|
Cedric,
After doing what you said (and it works of course).
The very last element has these characters "ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ".
I assume it is garbage or something ... how can I test for this...
Just to let you know I'm retrieveing data from a file, and putting it into the char array.
If I press enter on the very last entry in the text file, the last element in the array is: ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ
And if I don't press enter I get someting like this:
dataline1ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ
Thanx in advance ... again
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
|
|
|
|
|
Check your code that you add a '\0' at the last character of each string if it's not there.
|
|
|
|
|
|
IsBadWritePtr and IsBadReadPtr can tell you if your process can legally use that pointer, but they won't tell you if the pointer is pointing to the place it should be pointing - it could be pointing anywhere in your process' address space and still be valid for read/write.
Cedric is right - you should always initialize pointers to NULL, and use that as your good/bad test.
|
|
|
|
|
Thanx Chris ... I appreciate the help ... O yes ... Happy B-Day CodeProject
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
|
|
|
|
|
Be careful with IsBadWritePtr(...) , there are scenarios where relying on it can cause reduced stability:
http://blogs.msdn.com/oldnewthing/archive/2006/09/27/773741.aspx[^]
Which is why I stopped using when I learned about Guard Pages when researching driver development.
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
Hi,
I have created dialog box in SDK(c++) and there is one button "B1" with style owner draw and other "B2" with default style.
When I press enter key then "B2" gets pressed but when "B1" is highlighted it doesn't respond.
I tried many styles of button and also tried subclassing but I am unbale to handle enter key event.
Is any one knows how to solve it?
Manish
|
|
|
|
|
You have three buttons on your dialog when you press one key you dont get any action,right?
|
|
|
|
|
No I have two buttons:
Button "B1" with owner draw style and button "B2" with default style.
On mouse click both get action.
On space bar when highlighted both get actions.
But when I press enter key when highlighted "B2" gets action but "B1" when highlighted doesn't respond to it.
Any sugestions?
Manish
|
|
|
|
|
Do you set Default Button to true (On property window) for B2?
|
|
|
|
|
In property page:
B2 having style: visible
B1 having style : visible and owner draw.
Please suggest any solution so that when B1 is highlighted,on pressing enter ket it should get action.
Manish
|
|
|
|
|
Not visible I said Default button on proeprty window of each button
|
|
|
|
|
I haven't set any default button on my dialog.
All other styles are set to false and only those wnich are mentioned are set.
With these styles I want to handle enter key event for "B1".
How will it be done?
Manish
|
|
|
|
|
if you run this code what happens?
<br />
#define IDC_TEST 1000<br />
<br />
BEGIN_MESSAGE_MAP(CAnswerDlg, CDialog)<br />
ON_BN_CLICKED(IDC_TEST, OnBnClickedTest)<br />
END_MESSAGE_MAP()<br />
<br />
void CAnswerDlg::DoDataExchange(CDataExchange* pDX)<br />
{<br />
DDX_Control(pDX, IDC_TEST, m_Test);<br />
}<br />
<br />
BOOL CAnswerDlg::OnInitDialog()<br />
{<br />
m_Test.Create("AS",WS_TABSTOP|WS_CHILD|WS_VISIBLE|BS_NOTIFY,CRect(0,0,100,23),this,IDC_TEST);<br />
}<br />
<br />
void CAnswerDlg::OnBnClickedTest()<br />
{<br />
MessageBox("A");<br />
}<br />
<br />
afx_msg void OnBnClickedTest();<br />
CButton m_Test;<br />
I run this code and it works for me does this code solve your problem?
|
|
|
|
|
Hi,
Regret for late reply...
I am using Win32 SDk application,no MFC is there.
I have implemented subclaasing of child controls(buttons in this case) to adrees this issue.Now I am able to handle enter key events as well.
Manish
|
|
|
|
|
I glad you find it
|
|
|
|
|
Hi all,
I'm trying to get the data from a file and assigning each of the lines to a variable (array or something)
I have tried the following:
<br />
HANDLE hFile;<br />
DWORD dwNumRead;<br />
BOOL bTest;<br />
char dwBuffer[256];<br />
<br />
hFile = CreateFile("client.cnf", GENERIC_READ, FILE_SHARE_READ,NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);<br />
bTest= ReadFile(hFile, dwBuffer, sizeof(char)*256, &dwNumRead,NULL);<br />
printf("%s",dwBuffer);<br />
I receive data from the file (dwBuffer), but how can I assign each line to an variable (array element or something)
Lets say the file has the following data:
[SEND]
file1.txt
file2.txt
[RECEIVE]
file3.txt
file4.txt
Thanx in advance
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
|
|
|
|
|
Why don't you use the MFC class CStdioFile it can read a file line by line.
Help your local Search & Rescue. Get lost!
|
|
|
|
|
Thanx for the reply Monty, but I'm not using MFC...
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
|
|
|
|
|
Then you can parse the string and break at every '\r\n' , alternatively you can use strtok
You can't see me
|
|
|
|
|
Thank you Monty, I'll check out MSDN...
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
|
|
|
|