I’m currently working on a program (for fun, this is not an assignment) that has multiple functions. I have never used Win32 prior to yesterday and so I am rather new. I used TheForger’s tutorials to get started. Right now, I have a dialog form with four edit boxes on it, charge1, charge2, charge3, and distance between particles. I am getting this information and plugging it into the formula to solve for the amount of force between the particles.
When I get to the part where I am getting the data from the edit box, I am receiving 0.
Here is my current code:
case ID_SOLVE:
{
ZeroMemory(coulombDisplay, sizeof(coulombDisplay));
GetDlgItemText(g_hCoulombs, IDC_DISTANCE, value1, 10);
coulombsDistance = atof(value1);
GetDlgItemText(g_hCoulombs, IDC_CHARGE1, value2, 10);
coulombsStrength1Base = atof(value2);
GetDlgItemText(g_hCoulombs, IDC_CHARGE2, value3, 10);
coulombsStrength2Base = atof(value3);
if(coulombsDistance == 0.0)
{
MessageBox(NULL, "WHAT", "WHAT", MB_OK | MB_ICONEXCLAMATION);
DestroyWindow(g_hCoulombs);
}
coulombsResult = (coulombsStrength1Base * coulombsStrength2Base);
coulombsResult /= (pow(coulombsDistance, 2));
coulombsResult *= kConstant;
sprintf(coulombDisplay, "%g", coulombsResult);
SendDlgItemMessage(g_hCoulombs, IDC_FORCE, WM_SETTEXT, 0, (LPARAM)(LPCSTR)coulombDisplay);
}
break;
value1, value2, value3, and coulombDisplay are all char[] that have been zero’d
coulombsResult, coulombsDistance, coulombsStrength1Base, coulombsStrength2Base are all doubles
The MessageBox stating “WHAT” is popping up each and every time that I run the program. I am using the multi-byte character set of VC++ 2010.
Any help would be greatly appreciated.
STATUS_ACCESS_DENIED has a good point. If you look at the documentation for atof you’ll see that a error condition will result in 0.0 being returned. I’d recommend writing to a log file or something to see what the data is going into the atof function. I’m wondering if your allocated char buffer is big enough.