|
fury 84 wrote: I'm trying to store info in a .INI file but I get a runtime error everytime. My code looks something like:
GetDlgItemText (hwnd, ID_EDIT1, user, 40);
GetDlgItemText (hwnd, ID_EDIT2, edit2, 40);
WritePrivateProfileString (user, "settings", edit2, "info.INI");
It will create the info.INI file but won't write anything to it before closing. Thanks for any help.
What is the data types of the variables??
-if they are pointers and you haven't allocate the memory for them then runtime error may occur.
-Check the maxcount you providing and the available size of the variable.
Knock out 't' from can't,
You can if you think you can
|
|
|
|
|
I got a 600*480(pixel) picture with my camera. I wonder how many centimeters the width and height are.
how to calculate?
|
|
|
|
|
1 pixel = .04 cm (as per my knowledge and study)
Therefore :
600 pixel= 24 cm
480 pixel= 19.2 cm
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
|
hi, i am writing a program that stores data into a text file i specify in the form of a class object. when i initialize the window where i can edit this data, i have a combo box that reads the file and inserts part of the object(the name of each class object) into the combo box. than i select the name and when i hit the button to edit the data for that particular object i am trying to have my program insert each part of the class into its own text box but when i try to do this my program completely crashes without any information as to why. i tried to push the values of the variables into a buffer and than use setwindowtext but it would still crash which i have done else where in my program without any bit of trouble.
|
|
|
|
|
Can you show your code that has error
whitesky
|
|
|
|
|
sure not a problem, i will post the whole function, hope that will be enough to help solve the issue.
afx_msg void CEditDialog::OnEdit()<br />
{<br />
elements s;<br />
int size = sizeof(elements);<br />
bool found = false;<br />
<br />
CComboBox *pSelection;<br />
pSelection = (CComboBox *)GetDlgItem(IDC_SELECTION);<br />
CEdit *pNameText;<br />
pNameText = (CEdit *) GetDlgItem(IDC_ENAME);<br />
CEdit *pSymbolText;<br />
pSymbolText = (CEdit *) GetDlgItem(IDC_ESYMBOL);<br />
CEdit *pAtomicText;<br />
pAtomicText = (CEdit *) GetDlgItem(IDC_EATOMIC);<br />
CEdit *pPeriodText;<br />
pPeriodText = (CEdit *) GetDlgItem(IDC_EPERIOD);<br />
CEdit *pGroupText;<br />
pGroupText = (CEdit *) GetDlgItem(IDC_EGROUP);<br />
CEdit *pElectronText;<br />
pElectronText = (CEdit *) GetDlgItem(IDC_EELECTRON);<br />
<br />
int iCurSel = pSelection->GetCurSel();<br />
<br />
if(iCurSel == CB_ERR)<br />
{<br />
MessageBox(" Please Select an Item.", "Error", MB_ICONWARNING);<br />
<br />
return;<br />
}<br />
<br />
char lpszText[32];<br />
pSelection->GetLBText(iCurSel, lpszText);<br />
<br />
access.Open(file, CFile::modeCreate | CFile::modeNoTruncate | CFile::modeReadWrite);<br />
<br />
do{<br />
access.Read(reinterpret_cast< char * > (&s), sizeof(elements));<br />
MessageBox(lpszText, "debug", MB_ICONINFORMATION);<br />
if(strcmp(s.element, lpszText) == 0)<br />
{<br />
access.Seek(-(long)size, CFile::current);<br />
MessageBox("Found", "debug", MB_ICONINFORMATION);<br />
found = true;<br />
pNameText->SetWindowText("test");<br />
}<br />
}while(found != true);<br />
access.Close();<br />
}
all the code works as expected except the setwindowtext, anythign i put for it to output causes a crash(please excuse my sloppy code).
|
|
|
|
|
You might try putting a breakpoint on this line and see if pNameText is NULL (which it probably is):
CEdit *pNameText;<br />
pNameText = (CEdit *) GetDlgItem(IDC_ENAME);
GetDlgItem will return NULL if it can't find the control with the specified ID.
The symbol might exist in your resource file, so no compile time error, but check the specific control in the resource editor and make sure it is assigned an ID of IDC_ENAME.
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
or maybe i guess IDC_ENAME isnt CEdit
whitesky
|
|
|
|
|
That's possible, although every CWnd derived object supports SetWindowText, so my best guess is GetDlgItem is returning null.
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
you right(of course in this thread it seems that my guess is ture)and i think he find problem. and i agree with GetDlgItem is returning null
whitesky
|
|
|
|
|
you said this code has problem
<br />
CEdit *pNameText;<br />
pNameText = (CEdit *) GetDlgItem(IDC_ENAME);<br />
pNameText->SetWindowText("test");<br />
Do you have IDC_ENAME in your program
and is this CEdit
whitesky
|
|
|
|
|
you know...i went back to check the ids and names of controls as you said to do...noticed that some how the names of controls in another window were being used in that window so i changed them to what they needed to be and well it works fine, now to see if i can get it to do what i need(which should be no problem at all.) thank you so much .
|
|
|
|
|
Hi
in my application I use the bellow statement.
<br />
std::sort(m_nOrgPtSortX.begin(), m_nOrgPtSortX.begin() + 17, SortInX);<br />
its working fine.
But when I change 17 to 18 or more than 18 the application halts there.
like the bellow statements making problem.
std::sort(m_nOrgPtSortX.begin(), m_nOrgPtSortX.begin() + 17, SortInX);<br />
std::sort(m_nOrgPtSortX.begin(), m_nOrgPtSortX.end(), SortInX);
m_nOrgPtSortX is a vector.
Please suggest any idea.
One more thing is that, when I use the vector I used push_back funtion.
So the size should increase accordingly. But the capacity() funtion shows 2048 element. and when I push more than that data it fails. I solved it by resize(5000) . But couldn't find the reason for the fail.
Regards
Anil
|
|
|
|
|
How many items are in there, more than 2000 ? Why would you want to sort the first 17, just for a test ? What about sorting 16 somewhere in the middle ? And what does your functor look like ( what's SortInX ) ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Christian Graus wrote: How many items are in there, more than 2000 ?
yes more than 2000 i.e 3050 data are there.
Christian Graus wrote: And what does your functor look like ( what's SortInX ) ?
BOOL SortInX(const Point& ptOne, const Point&ptTwo)<br />
{<br />
if( ptOne.X == ptTwo.X )<br />
return( ptOne.Y <= ptTwo.Y );<br />
<br />
return( ptOne.X < ptTwo.X);<br />
}
and the vector is like
struct Point<br />
{<br />
WORD X;<br />
WORD Y;<br />
WORD Val;<br />
};<br />
<br />
typedef std::vector < Point > CPointArray;<br />
CPointArray m_nOrgPtSortX;
Thank you very much for your reply.
Regards
Anil
-- modified at 23:00 Wednesday 7th June, 2006
std::sort(m_nOrgPtSortX.begin() + 10, m_nOrgPtSortX.begin() + 25, SortInX);
the above statement is also working
|
|
|
|
|
If I compile this in VC2005, I get an ASSERT, which seems to be saying that your function object does not return consistently, that is it doesn't return true for a < b and false for b < a. I changed it to this:
bool SortInX(const Point& ptOne, const Point&ptTwo)
{
if( ptOne.X == ptTwo.X )
return( ptOne.Y < ptTwo.Y );
return( ptOne.X < ptTwo.X);
}
and filled a list with 3000 random objects and sorted them, no problems. I reckon your list is being thrown into an endless sorting loop based on your 18th element.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Yes after changing the funtion as you told its working fine.
Thank you verry much for your supprot.
I am using STL for the first time, as used of using CArray
But I like STL after using it.
Thank you very much again.
Regards
Anil
|
|
|
|
|
Like a lot of c++ newbies, I spent a little time struggling with pointers, the address-of business, and references. I think I got a handle on it now, so I wrote this addition operator for a matrix class...
// Matrix addition (overloads the plus operator)
// Notice that the matrix is passed as a reference.
// This will be less taxing if the matrices are really big.
// However, this leaves the matrix referred to here as toAdd
// vulnerable to changes, so we add a const to the parameter.
// Returns a reference as well
matrix& operator + (const matrix &toAdd)
{
// Create a zero matrix of the same size to output.
// Allocate the memory from the heap so it won't get
// deleted after this method is called (use "new")
matrix* output = new matrix(toAdd.get_rows(), toAdd.get_cols(), 0);
matrix& outref = *output; // Create a reference to the output matrix
// Don't forget to dereference output with *
// A temporary variable to hold the sum of each element
double val;
// Go through every element and sum
for(int i = 0; i < nrows; i++)
{
for(int j = 0; j < ncols; j++)
{
// Don't forget... the indices are always one less
// than the row and column numbers
val = elements[i][j] + toAdd.get_el(i+1,j+1);
output->set_el(i+1, j+1, val); // output is a pointer so use ->
}
}
// Just return a reference, rather than a giant matrix...
return outref;
}
Can someone with more experience than me please take a look at that and make sure there's nothing funny going on? I get the right result, but I want to make sure it's actually doing everything with references. The idea is that if I need to deal with very large matrices, I only want to pass references in, and pass a reference out.
Also, I was curious why the compiler threw an error if I did
matrix output = new matrix
rather than
matrix* output
I think I'm on the right track here. If I can get confirmation that everything's ok, I should be on my way.
Thanks everyone
-Mark
|
|
|
|
|
MALDATA wrote: Also, I was curious why the compiler threw an error if I did
matrix output = new matrix
Because new only creates pointers. matrix output; is fine, as is matrix output(/*constructor parameters*/);
Operator plus has two objects to work with, why don't you work with 'this', rather than create a new one ? At least, that's how I thought it worked.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I just did that to preserve the matrices being summed. If I use "this" will that change one of the matrices involved in the sum? Seems to me that it would, but I could be wrong. Is there really a benefit to doing it that way? I figure if I'm passing by reference anyway, the only thing that'll help is by saving the memory.
Thanks for the suggestions,
-Mark
|
|
|
|
|
MALDATA wrote: If I use "this" will that change one of the matrices involved in the sum?
No, the regular aritmetic operators should not change the operands.
It's a convention that operator overloads where the first operand is of type T , are made members of class T . You don't have to write the operators that way, but making them members can make the code easier to maintain since it keeps the matrix-related code closer together.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
Hi there,
I wanna read the boot sector of a floppy without using DeviceIoControl() function.So i just made a structure shown below;
struct boot_sector
{
char jump[3];
char name[8];
unsigned char secpercluster;
short int bytepersec;
short int reserved;
unsigned char fatcopy;
short int maxdirentry;
short int totalsec;
unsigned char mediadescriptor;
short int secperfat;
short int secoertrack;
short int noofsides;
long int hiddensectors;
long int hugesectors;
unsigned char biosdriveno;
unsigned char reservedsec;
unsigned char signature;
long int volumeid;
unsigned char volumelabel[11];
char filesystem[8];
}bt;
Now the size of the structure should be 62 bytes but vc++ compiler shows it to be 68 bytes .But i hav cross checked it using borland c++ compiler.In that also the sixe is 62 bytes. Can anybody help me out of this ,specially u nish. Suggest me something plzzzzz..
|
|
|
|
|
I'd say it has something to do with in memory padding. Why is it a problem ? Have you tried adding to parts of the struct using byte offsets to see where it's going wrong, if anywhere apart from the end ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I would agree with Mr. Graus.
Try
#pragma pack(1)
and it'll give you 62 in the Microsoft compiler
|
|
|
|