|
How unbelievable it might seem, there are even more ways to corrupt a piece of memory than there are unspecific questions on this forum
|
|
|
|
|
Lol! My bad! I was reading your 'Otherwise' as 'if you don't delete scalar you will get memory corruption'.
|
|
|
|
|
Guess i should express myself more clearly, sorry...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Hi
We have a MFC Application in which we decide to perform a task based on the mouse click position.
We have a formula that converts this x and y value info into a index number,which we use to retrieve info
Now our customer have given us a crash dump in which CPoint x and y value has 5882 and 1150 which are very huge. Due to which the index generated is very high and since this index does not exists we get a crash(segmentation fault)
In our test we never get such high x and y value.
Can anyone explain the reason for this high x and y values?
Does resolution impact the x and y values?
thanks in advance
from
nayeem khan
|
|
|
|
|
nayeemkhan wrote: Can anyone explain the reason for this high x and y values?
nayeemkhan wrote: We have a formula that converts this x and y value info into a index number,which we use to retrieve info
I've got no idea...but I can suggest a way in which you can stop the crashes. Either validate your input data (you can find the screen extents easily enough - it makes sense that the mouse position should be on-screen?) or validate the index you've generated from the mouse position.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hi Stuart Dootson
Thanks for the reply
I have already coded the validation of x and y (which u suggested)
But i was wondering how can a resolution of screen can be such huge 5800x1150.
I am also investigating with respect to data limits of x and y.
Can we get a boo/tutorial which explains exactly how CPoint structure gets the x and y values?
from
nayeem khan
|
|
|
|
|
nayeemkhan wrote: I have already coded the validation of x and y (which u suggested)
I would suggest that validation of the index would be rather more useful
nayeemkhan wrote: Can we get a boo/tutorial which explains exactly how CPoint structure gets the x and y values?
Where does the CPoint come from? Is it from a Windows message?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
nayeemkhan wrote: Now our customer have given us a crash dump in which CPoint x and y value has 5882 and 1150 which are very huge.
Can you post the code where you retrieve those values ?
|
|
|
|
|
Hi
Below is the part of code which gets the x and y values and converts it to a index variable called ListClick
I have commented the code where ever necessary
void CHierDispWnd::OnLButtonDown( UINT , CPoint Point )
{
int ListClick;
long MemClick;
int GapX,GapY;
GapX = m_pStdProps->m_iGapX;
GapY = m_pStdProps->m_iGapY;
int mem_wd,mem_ht;
mem_wd = m_pStdProps->m_iMemWidth;
mem_ht = m_pStdProps->m_iMemHeight;
SetFocus();
if ((Point.x < CXSCROLLBTN) || (Point.y < GapY))
return;
ListClick = (Point.x - CXSCROLLBTN) / (mem_wd + GapX);
if (!pMiddle->ListValid( ListClick))
return;
}
|
|
|
|
|
Theoretically you can have very large numbers here, since the point is relative the window (this->m_hWnd). You can have windows a lot larger than the resolution of your screen. But I think that is only possible if you set the window size from your code. I don't know a way for a user to do that unless you explicitly allow it in your program. Do you do that?
|
|
|
|
|
nayeemkhan wrote: if (!pMiddle->ListValid( ListClick))//CRASHES IN THIS FUNC...LISTCLICK is 41,which does not //exists
So verify that it exists before trying to use it. This does not fix the problem of point.x equaling 5882 but it does keep your app from crashing.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
One possibility could be that your user has a virtual desktop (see Wiki[^], check the "Scrolling desktops" part) which can be any size i guess depending on what software the user might be using for it...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Perhaps your client has dual monitors, and has them set up to act like a single desktop window. That would make the X values double what you might expect while the Y values would be "normal".
Hope that helps.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
But wouldn't this would still require one monitor to have an x-axis of (about) 2941?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
To create a secured MS Access database programmatically using MFC I followed the procedure described at http://www.litwindow.com/Knowhow/HowTo/howto_create_secure_access_dat.html[^]. I have incorporated the code in one of my functions. However, while granting privileges to the newly created group exception is thrown and I am not able to create the database. The function in which I am using the code is as below.
void CSecuredAccessDlg::OnBnClickedOk()
{
if(m_fileName.IsEmpty())
{
MessageBox("No file selected!",NULL,MB_ICONERROR);
return;
}
CString strConfig,sSql;
CString strAccessDriver;
CDatabase database;
strAccessDriver="Microsoft Access Driver (*.mdb)";
if(_access("my workgroup.mdw",0)==0)
unlink("my workgroup.mdw");
if(_access(m_fileName,0)==0)
unlink(m_fileName);
strConfig.Format("CREATE_SYSDB=\"my workgroup.mdw\"\0\0");
SQLConfigDataSource(NULL, ODBC_ADD_DSN, strAccessDriver,strConfig);
strConfig.Empty();
strConfig.Format("CREATE_DB=\"%s\"\0\0",m_fileName);
SQLConfigDataSource(NULL, ODBC_ADD_DSN, strAccessDriver,strConfig);
strConfig.Empty();
TRY
{
strConfig.Format("DRIVER={%s};DSN='';READONLY=FALSE;"
"CREATE_DB=\"%s\";DBQ=%s;SystemDB=%s;UID=admin;"
"ExtendedAnsiSQL=1",strAccessDriver,m_fileName,m_fileName,
"my workgroup.mdw");
if(database.OpenEx(strConfig,CDatabase::noOdbcDialog))
{
sSql.Format("CREATE GROUP %s %s","Administrators","1234ABC");
database.ExecuteSQL(sSql);
sSql.Empty();
sSql.Format("CREATE USER %s \"%s\" %s","Pani","","1234DEF");
database.ExecuteSQL(sSql);
sSql.Empty();
sSql.Format("ADD USER %s TO %s","Pani","Administrators");
database.ExecuteSQL(sSql);
sSql.Empty();
sSql.Format("ADD USER %s TO %s","Pani","admins");
database.ExecuteSQL(sSql);
database.Close();
unlink(m_fileName);
strConfig.Empty();
strConfig.Format("CREATE_DB=\"%s\"\0SystemDB=my workgroup.mdw"
"\0UID=Pani\0\0",m_fileName);
SQLConfigDataSource(NULL, ODBC_ADD_DSN, strAccessDriver,strConfig);
strConfig.Format("DRIVER={%s};DSN='';READONLY=FALSE;"
"CREATE_DB=\"%s\";DBQ=%s;SystemDB=%s;UID=Pani;ExtendedAnsiSQL=1",
strAccessDriver,m_fileName,m_fileName,"my workgroup.mdw");
if(database.OpenEx(strConfig))
{
sSql.Format("GRANT ALL PRIVILEGES ON DATABASE TO Administrators");
database.ExecuteSQL(sSql);
sSql.Format("REVOKE ALL PRIVILEGES ON DATABASE FROM admin");
database.ExecuteSQL(sSql);
sSql.Format("REVOKE ALL PRIVILEGES ON DATABASE FROM admins");
database.ExecuteSQL(sSql);
sSql.Format("REVOKE ALL PRIVILEGES ON DATABASE FROM users");
database.ExecuteSQL(sSql);
sSql.Format("ALTER USER Pani PASSWORD %s \"%s\"","pani123","");
database.ExecuteSQL(sSql);
FillData(&database);
database.Close();
}
}
}
CATCH(CDBException, e)
{
if(database.IsOpen())
database.Close();
MessageBox(e->m_strError,NULL,MB_ICONERROR);
return;
}
END_CATCH
}
Can anyone provide suggestions for correcting the code?
Thanks in advance.
Pani68
modified on Thursday, April 2, 2009 3:32 AM
|
|
|
|
|
[edit]Looks like that Format call is your problem - once I realised I'd not converted one of your strings to Unicode, I was able to run your code all the way through with no exceptions (I commented out the FillData call, as that's not available)[/edit]
One issue you might have - this line:
strConfig.Format("CREATE_DB=\"%s\"\0SystemDB=my workgroup.mdw"
"\0UID=Pani\0\0",m_fileName);
Won't produce what you expect - CString::Format won't look beyond your first NULL character, so the string will end up as
CREATE_DB="whatever m_fileName is"
If you use some code like this:
std::basic_string<TCHAR> s;
s = _T("CREATE_DB=\""); s+= m_fileName ; s += _T("\"");
s += TCHAR(0);
s += _T("SystemDB=my workgroup.mdw");
s += TCHAR(0);
s += _T("UID=Pani");
s += TCHAR(0);
s += TCHAR(0);
s += TCHAR(0);
then the string will be created with all the bits in correctly, as std::string doesn't care about nulls as much as CString . You can pass s.c_str() to your call to SQLConfigDataSource to access the string content.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
modified on Thursday, April 2, 2009 4:51 AM
|
|
|
|
|
Hi Stuart Dootson,
Thanks for providing the hints. I am using VS 2003 (without unicode). Hence, I changed the lines to:
char szConfig[1024];
sprintf(szConfig,"SystemDB=%s%cUID=%s%cCREATE_DB=\"%s\"%c%c",
"my workgroup.mdw",'\0',"Pani",'\0',m_fileName,'\0','\0');
SQLConfigDataSource(NULL, ODBC_ADD_DSN, strAccessDriver,szConfig);
Now it is working fine.
Pani.
|
|
|
|
|
pani68 wrote: Now it is working fine.
Excellent - that's the desired outcome
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I am using unicode in my Program.i have stored a CString value into const void* variable.now i want to convert a const void* into CString where i am unable to convert .
|
|
|
|
|
Assuming the void pointer is called lpvoid, do this -
CString cstring(reinterpret_cast<wchar_t*>(lpvoid));
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Can you show us how you stored the CString into a const void* ?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hello all.
I've a dialog box application and in that i'm taking 2 bitmaps which behaves like buttons.. Initially My OK Bitmap button is disable and CANCEL bitmap button is enabled, I've one field for password, when user gives right password OK bitmap button get enabled and i can click on that....Now my problem is that despite of clicking if user presses ENTER key it should behave like mouse click...
So intot i need to know how to capture Enter Key.. Small search gave me that i need to handle WM_KEYDOWN and VK_RETURN...
Thanks all
|
|
|
|
|
Assuming you are using MFC, simply override the OnOK() and OnCancel() in you dialog class.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Damn.. I always forgot to tell you guys it's NON-MFC..
Sorry ..
|
|
|
|
|
Hey!
On a side note: having a button that gets enabled when a correct password is entered makes it a bit easier to guess the password by bruteforce (or/and maybe other methods) because one only has to write a program that enters a password and then checks the state of the button, if it is disabled, it tries the next possible password and checks the button again until the button becomes enabled... althorough you can add a -let's say- 3 seconds pause if a wrong password is entered before the user is allowed to enter the next password, this makes it take much much more time to hack.
Aside of this, did you try handling WM_KEYDOWN? Did it work?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|