|
I need Help Urgent !!!
What is the problem in this code:
in run time when use in read func the program gets error and shut down. Who can help ????
_________________________________________________
//Header file:
-------------------------
typedef struct dPerson{
CString str;
BYTE status;
CString id;
DWORD ID;
BYTE f2[400];
BYTE f1[400];
BYTE t[12];
}dPerson;
-----------------------------------------
class CPerson : public CCmdTarget
{
DECLARE_DYNCREATE(CPerson)
CPerson();
public:
virtual ~CPerson();
public:
dPerson per;
CPerson* pNext;
CPerson* pBack;
DECLARE_MESSAGE_MAP()
};
-------------------------------------------------------------
________________________________________________________________
//cpp file:
-----------------
void CDemo::OnButtonAdd()
{
UpdateData(true);
person.per.id = m_editId;
//person = member variable of CDemo from type CPerson
...
...
...
CFile file;
// CFileException ex;
if(file.Open(strPath, file.modeWrite|file.modeNoTruncate|file.modeCreate ))
{
file.SeekToEnd();
file.Write( &(person.per) , sizeof(dPerson));
MessageBox("************ S A V E D ************** ");
}
}
/************************************************************/
void CDemo::read_persons(CFile* persons)
{
CPerson* q = new CPerson;
DWORD dwRead = sizeof(dPerson);
if((*persons).Read(&q->per, sizeof(dPerson)))
{
q->pNext = q->pBack = NULL;
p_head = p_tail = q; //p_head and p_tail are member variables of CDemo - type CPerson*
}
else
{
MessageBox("Have not register of users ! ");
return;
delete q;
}
DWORD size = dwRead;
while (size == dwRead)
{
q = new CPerson;
if( (size = (*persons).Read( &q->per, sizeof(dwRead))) == sizeof(dwRead) )
{
q->pNext = NULL;
q->pBack = p_tail;
p_tail->pNext = q;
p_tail = q;
}
else
delete q;
}
}
/************************************************************/
|
|
|
|
|
|
It would probably help if you described what the error was, and what line it occured in. I for one am not drawn to messages that are ALL IN CAPS, nor do I have time to create a project to try and figure out what error you are getting and where it is, so I can try to help you.
Christian
#include "std_disclaimer.h"
The careful application of terror is also a form of communication.
Eagles may soar, but weasels don't get sucked into jet engines.
|
|
|
|
|
When I read from the file I gets incorrect vulues in the members of the object CPerson and this is performed a lot of problems !
|
|
|
|
|
I have a CString that is holding a date. I want this date to be the max date in the microsoft datepicker.
the function is -
void SetMaxDate(DATE newtime);
My question is how do you fill DATE?
I can not find any documentation for DATE.
|
|
|
|
|
You can use a COleDateTime (which is the MFC wrapper for the DATE type). You can set the date and time in the COleDateTime object using ParseDateTime(). ParseDateTime will take in strings in any of the standard Windows Date Time formats. Then you can just pass your object into the SetMaxDate function, which will cast the object to a DATE. For example:
COleDateTime vtMaxDate;
CString vcstrMaxDate = _T("01-01-2001");
vtMaxDate.ParseDateTime(vcstrMaxDate);
SetMaxDate(vtMaxDate);
Hope this helps.
------------------------
Derek Waters
derek@lj-oz.com
|
|
|
|
|
|
Hello,
I'm trying to write an OLE DB Wrapper class and have created a function called SetStringFieldValue and inside that function I need to set 1 columns data to the string passed to the function. I have yet to find any examples of SetData anywhere and for some reason its not working for me. Any help is greatly appreciated.
void COleDBWrapper::SetStringFieldValue(int nIndex, LPCTSTR lpszValue)
{
CString strValue(lpszValue);
IRowsetChange* pIRowsetChange = (IRowsetChange*)m_pUnkRowsetChange;
IRowsetUpdate* pIRowsetUpdate = (IRowsetUpdate*)m_pUnkRowsetUpdate;
IAccessor* pIAccessor = NULL;
HACCESSOR hAccessor;
ULONG cBindings = 1;
DBBINDING rgBinding[1];
memset(rgBinding, 0, sizeof(DBBINDING));
char szValue[50];
_tcscpy(szValue, strValue.GetBuffer(0));
rgBinding[0].iOrdinal = nIndex;
rgBinding[0].dwPart = DBPART_VALUE|DBPART_STATUS|DBPART_LENGTH;
rgBinding[0].obLength = (strValue.GetLength() + 1) * sizeof(TCHAR);
rgBinding[0].obStatus = (strValue.GetLength() + 1) * sizeof(TCHAR);
(CString)rgBinding[0].obValue = szValue; // -- DOESN'T DO JACK! -- //
rgBinding[0].wType = DBTYPE_STR;
rgBinding[0].pTypeInfo = NULL;
rgBinding[0].pObject = NULL;
rgBinding[0].pBindExt = NULL;
rgBinding[0].dwMemOwner = DBMEMOWNER_CLIENTOWNED;
rgBinding[0].cbMaxLen = (strValue.GetLength() + 1) * sizeof(TCHAR);
rgBinding[0].dwFlags = 0;
HRESULT hr = m_pUnkRowset->QueryInterface(IID_IAccessor, (void**)&pIAccessor);
if (FAILED(hr))
return;
hr = pIAccessor->CreateAccessor(DBACCESSOR_ROWDATA, 1, rgBinding, 0,
&hAccessor, NULL);
if (FAILED(hr))
return;
hr = pIRowsetChange->SetData(m_hRow, hAccessor, szValue);
// hr is ALWAYS DB_E_ERRORSOCCURRED
}
Bret Faller
Odyssey Computing, Inc.
|
|
|
|
|
I'm trying to write an OLE DB Wrapper class
It sounds like reinventing the wheel - can't you use ATL OLEDB consumer templates?
hr is ALWAYS DB_E_ERRORSOCCURRED
IErrorRecords should give you more detailed information. See DBViewer sample for details. You may also check the status variables associated with fields.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
IErrorRecords::GetDescription and GetSource both give me "M" so they were no help. Also, I am writing my own wrapper class because the templates are ok but they are still too primative. Thank you for your response.
Bret Faller
Odyssey Computing, Inc.
|
|
|
|
|
Hopefully the question is pretty descriptive.
Paradise is where I am.
Voltaire
|
|
|
|
|
|
Hi All,
my program has one dialog box. On the dialog box I have put
some buttons, 2 edit box components, some comboboxes and some labels,
I was wondering what can I do to move the components around on the sheet
when I want to resize the dialog box. I want to keep the components
at the same distance of the nearest dialog border, and I want to resize the CEdit boxes.
Any idea how to do that in run time?
Thanks!
John
|
|
|
|
|
Writing, writing and writing.
Use SetWindowPlacement.
You need to relocate the buttons each time that you recize the Dialog.
Make this in the OnSize Message
Good Luck!!!!
Carlos Antollini.
|
|
|
|
|
That function is only for window resizing.
How can I resize the components on the window?
It must be possible something like this
void CTestDlg::OnSize(UINT nType, int cx, int cy)
{
CButton *pCloseButton;
pCloseButton = (CButton*) GetDlgItem(IDCLOSE);
pCloseButton->Move(10,10);
}
Is there something like a move methode???
Thanks,
John
|
|
|
|
|
Like the original post said, you need to call it for child windows as well. A link has been provided to a class here that allows you to set rules by which child windows are automatically sized. I've not tried it myself, but it's the only other option to a list of MoveWindow or SetWindowPos calls in your OnSize code.
Christian
#include "std_disclaimer.h"
The careful application of terror is also a form of communication.
Eagles may soar, but weasels don't get sucked into jet engines.
|
|
|
|
|
From codeproject->Dialogs:
http://www.codeproject.com/dialog/resizabledialog.asp
http://www.codeproject.com/dialog/dynwindow.asp
|
|
|
|
|
check july issue at msdn magazine:
http://msdn.microsoft.com/msdnmag/issues/01/07/default.asp
http://msdn.microsoft.com/msdnmag/issues/01/07/winmgr/winmgr.asp
|
|
|
|
|
Thanks all for your help!
|
|
|
|
|
Please help me out.
I have a COleDataObject class in which i have the data in the Clipboard. If the data format in clipboard is bitmap, i need to store it in a file.
What i did is
i got the HGLOBAL from the COleDataObject and using GlobalLock i got void* pointer. Then I used CFile and created a file of extension .bmp and I used CArchive's Write function to write the raw data into the file.
But after this if i try to open the file using MS paint, it says unrecognized format.
Someone tell me what am i actually supposed to do. Thanks
Ganesh.M.Ramaswamy
|
|
|
|
|
forget it. i just made it.
Ganesh Ramaswamy
|
|
|
|
|
I'm converting a listbox control to be a list control and in reviewing the code I came across a method of CListbox that doesn't have a similar method in CListCtrl. The method is GetSelItems(int, LPINT). Did I completely miss something?
After thinking about what would be needed, I came up with the following code as a replacement. Comments or suggestions are welcome. Thanks.
int CMyListCtrl::GetSelItems(int nMax, LPINT paIndex)
{
int i;
POSITION pos = GetFirstSelectedItemPosition();
for ( i = 0; (i < nMax && pos); i++ )
{
*paIndex[i] = GetNextSelectedItem(pos);
}
return i;
}
Chris
|
|
|
|
|
Did I completely miss something?
I don't think so. List control implemented in comctl32.dll doesn't have the equivalent of LB_GETSELITEMS which is wrapped by CListBox::GetSelItems. Is this a real problem - performance-critical stuff, etc.?
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
With it missing, I'll have to implement it myself
I'm replacing a listbox with a list control and just trying to minimize the code changes in the dialog class. I'll probably end up using the code I posted previously. Thanks for the help. At least I wasn't overlooking something obvious.
Chris
|
|
|
|
|
I'm converting a listbox control to be a list control and in reviewing the code I came across a method of CListbox that doesn't have a similar method in CListCtrl. The method is GetSelItems(int, LPINT). Did I completely miss something?
After thinking about what would be needed, I came up with the following code as a replacement. Comments or suggestions are welcome. Thanks.
int CMyListCtrl::GetSelItems(int nMax, LPINT paIndex)
{
int i;
POSITION pos = GetFirstSelectedItemPosition();
for ( i = 0; (i < nMax && pos); i++ )
{
*paIndex[i] = GetNextSelectedItem(pos);
}
return i;
}
Chris
|
|
|
|