|
i made CPoint object and inserted it in CObArray. by the way, the problem is occured.
i'd guess to be garbage value in there.
i wrote the following code.
--------------------------------------------------
CPoint point(10,10);
ArrFigure.Add((CObject*)&point);
--------------------------------------------------
Since CPoint is not derived from COject?
ask for answer
thank you
have a nice day
|
|
|
|
|
I'm assuming you call that code inside some function and notice the garbage after the function returns. The reason is that the CPoint is created on the stack and is destroyed when the function returns. To make it work you need to do the following...
ArrFigure.Add(new (CObject *) CPoint(10, 10));
Of course, since CPoint isn't derived from CObject you need to be careful. Better to use the template classes thusly...
CArray<CPoint *, CPoint *> ArrFigure;
ArrFigure.Add(new CPoint(10, 10));
Don't forget that when you destroy ArrFigure you must also destroy each CPoint object (the array object won't do it for you).
Rob Manderson
http://www.mindprobes.net
|
|
|
|
|
and one second after hitting the submit button I saw it
ArrRigure.Add((CObject *) new CPoint(10, 10));
Doh!!!
Rob Manderson
http://www.mindprobes.net
|
|
|
|
|
CObArray is an array of pointers - you're adding a pointer to the CPoint object.. That object is probably going out of scope, so when you try to read it later, it's not there anymore.
--Mike--
http://home.inreach.com/mdunn/
"You named the Borg... Hugh?"
-- Guinan
|
|
|
|
|
Hi
I have a strange problem. I have an application in VC6.0 which makes use of crystal reports to generate a report. Now thi sapplication works fine in variuos systems under various OS. But , only in one machine ( to my badluck it happens to be the live machine ) this applciation crashes. there's o'cos no MSDEV & source code in that machine.and so, i used the NTSD debugger to get a little mor eknowledge on this and i got the following extract ( I have jus tpasted just a thte point of crsahing )
NTSD ModLoad: 77bc0000 77bc7000 RPCLTC1.dll
NTSD: access violation
NTSD: !!! second chance !!!
eax=7469650a ebx=0000003f ecx=7469650a edx=0000003f esi=8c30cea6 edi=00000004
eip=7800d1c4 esp=0161fb7c ebp=0161fb98 iopl=0 nv up ei pl zr na po nc
cs=001b ss=0023 ds=0023 es=0023 fs=0038 gs=0000 efl=00000246
*** WARNING: symbols checksum and timestamp is wrong 0x0004ed1e 0x000528d6 for m
svcrt.dll
MSVCRT!set_sbh_threshold+827:
7800d1c4 8906 mov [esi],eax ds:0023:8c30cea6=????????
0:001> kb
ChildEBP RetAddr Args to Child
0161fb98 7800cc1c 00901dc8 8c30cea6 0161fdd7 MSVCRT!set_sbh_threshold+0x827
0161fbdc 7800578c 0093320c 41104111 0093320c MSVCRT!set_sbh_threshold+0x27f
0161fbfc 4110bd0f 009337c0 00000002 00934e60 MSVCRT!_crtGetLocaleInfoW+0x580
0161fc30 4110bc2f 00934e60 0161fc5c 4110a7d6 P2SEVT+0xbd0f
0161fc3c 4110a7d6 00000001 00911170 00934e60 P2SEVT+0xbc2f
0161fc5c 42d6a1f7 009337e0 009337a0 009320a2 P2SEVT!SQLReadNextRecurringRecord+0
x8b
0161fe64 77e42257 005f0778 0000061c 00000000 CRAXDRT!DeleteUFLString+0x124c47
0161fe90 77f663f3 0161fea0 00000018 005f0778 USER32!IsWindow+0xa7
0161fee4 5f401301 00911364 00000000 00000000 ntdll!KiUserCallbackDispatcher+0x13
00911364 00000000 00000000 00000000 00000000 MFC42!Ordinal5307+0x13
Pl. let me know what does this mean .
Thanks
regards
Sankar
|
|
|
|
|
Looks like Crystal Reports (CRAXDRT)is crashing in a call to IsWindow() - hmmm... could be tricky...
Its also telling you the symbol file for the MS C runtime is not the right one (which may be no big deal).
Maybe take a look at all the dependencies in your exe and see if the versions of those DLLs are the same on the problem machine.
|
|
|
|
|
Hi all,
This has probably been asked before, but I can't find it. I've done the usual generic app. that requires a user to select a bunch of files from one window and drop them into another yadda, yadda. At the moment, my app. mimics explorer by manually drawing tree and list controls and populating the contents based on drive and directory information and the system image list for icons. What would be _really_ nice is the have full explorer functionaility such as context menus and delete / rename functions etc. I assume this can be done by embedding a version of explorer into a view of my application (ala OLE?), but I just don't know where to start, what API's to use or even how to do it, any pointers?
Thanks, Jon.
|
|
|
|
|
Hi,
I have an MDI application with Doc/View arch. I am working on Print/preview feature for the application.
I have the following code in a function that is called when "Print" is chosen:
CPrintDialog *m_PrintDialog = new CPrintDialog(TRUE, PD_ALLPAGES | PD_RETURNDC, NULL);
DOCINFO di;
::ZeroMemory (&di, sizeof (DOCINFO));
di.cbSize = sizeof (DOCINFO);
//application title appears in the spooler view
di.lpszDocName = "Print Test";
if (m_PrintDialog->DoModal() == IDCANCEL)
return;
HDC hpDC = m_PrintDialog->GetPrinterDC();
if (hpDC !=NULL)
{
CDC *pDC = new CDC;
pDC->Attach(hpDC);
pDC->m_bPrinting = TRUE;
// use Textmappingmode
pDC->SetMapMode(MM_TEXT);
TEXTMETRIC tm;
pDC->GetTextMetrics(&tm);
lineHeight = tm.tmHeight + tm.tmInternalLeading;
pageVMargin = pDC->GetDeviceCaps(LOGPIXELSY) / 2;
pageHMargin = pDC->GetDeviceCaps(LOGPIXELSX) / 2;
pageHeight = pDC->GetDeviceCaps(VERTRES);
pageWidth = pDC->GetDeviceCaps(HORZRES);
Y = pageVMargin;
pDC->StartDoc(&di);
for (int i = 0; i<100; i++)
{
pDC->StartPage();
if(!pageStarted || Y > pageHeight - pageVMargin)
{ /* new page */
if(pageStarted)
{
pDC->EndPage();
//pInfo->m_bContinuePrinting=false;
}
//pInfo->m_bContinuePrinting=true;
pDC->StartPage();
pageNumber++;
Y = pageVMargin;
pageStarted = TRUE;
//pInfo->m_nCurPage = pageNumber;
//PageHeading();
} /* new page */
pDC->TextOut(pageHMargin, Y, PrintArray[i]);
Y += lineHeight;
}
pDC->EndDoc();
pDC->AbortDoc();
pDC->Detach();
}
This works fine if the user chooses to print. This function is called from OnPrint function. However, when "print preview" is chosen, nothing shows up. I tried to write similar function but without displaying the print dialog etc. and that prints only the last 6 or so lines on page 1.
Pleeeeeeeeeeease help! I've been doing this for a wk now and it's driving me nuts... I don't know what else to try!!!
Thank you so much for any input...
|
|
|
|
|
My code is:
CListBox* pListBox = (CListBox*)GetDlgItem(IDC_SCREEN_LISTING);
pListBox->ResetContent();
CFileFind finder;
CString extension = "*.fig";
CString filepath = "";
BOOL haveFile = finder.FindFile(extension);
while (haveFile)
{
haveFile = finder.FindNextFile();
pListBox->AddString((LPCTSTR)finder.GetFileTitle());
}
How can I search a file with NO extension....... (no .txt or .ini or...etc....nothing, just the file name...no extension)
|
|
|
|
|
Use extension = "*.*";
And in the while
while(haveFile)
{
havefile = finder.FindNextfile();
if(finder.GetFileName().Find(".") == -1)
pListBox->AddString(((LPCTSTR)finder.GetFileTitle());
}
Cheers!!!
Carlos Antollini.
|
|
|
|
|
Thanks for your reply.
I've tried these codes and it works!!!! However, it shows the "Directory name" also......how to get rid of those directory.....
One more thing...do you know how to list files in particular directory?? For example, i want to do the same thing (list all no extension files..)...and search them in directory c:\ABC
Thanks
|
|
|
|
|
how to get rid of those directory
you need to use the function CFileFind::IsDirectory()
Like next
while(haveFile)
{
havefile = finder.FindNextfile();
if(finder.GetFileName().Find(".") == -1 && !finder.IsDirectory())
pListBox->AddString(((LPCTSTR)finder.GetFileTitle());
}
how to list files in particular directory
haveFile = finder.FindFile("C:\\ABC\\*.*");
while(haveFile)
{
havefile = finder.FindNextfile();
if(finder.GetFileName().Find(".") == -1 && !finder.IsDirectory())
pListBox->AddString(((LPCTSTR)finder.GetFileTitle());
}
Cheers!!!!
Carlos Antollini.
|
|
|
|
|
THANK YOU VERY MUCH!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
YOU ARE SUPERBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
Everything works fine.............
Sorry...one more question.......
Can I search the files in the directory which is under my root directory?
For example, my exe file is in c:\abc\....but you know sometimes I can copy the files to other directory...so i don't know the exact name of the root directory.
For example, there is a file in my root directory called \TESTING......and i want to search all those files with no extension....how to do it.
THANK YOU THANK YOU THANK YOU!!!!
|
|
|
|
|
You can use GetCurrentDirectory
char szCurrentDir[_MAX_DIR];
::GetCurrentDirectory(sizeof(szCurrentDir), szCurrentDir);
//Now you have the currentdir in the szCurrentDir variable.
CString strFind = _T(szCurrentDir + "\\*.*");
And make the same that the others samples.
Cheers!!!
Carlos Antollini.
|
|
|
|
|
Do you want to recursively search for ALL files on your
C: drive with no extension? (exluding directories)
if so you could use the following function ....
void GetAllFiles(CString Dir)
{
CFileFind finder;
CString csFiles(Dir+"\\*.");
BOOL haveFile = finder.FindFile(csFiles);
while (haveFile)
{
haveFile = finder.FindNextFile();
if (finder.IsDots())
continue;
// search all directories recursively
if (finder.IsDirectory()) {
CString csNewDir = finder.GetFilePath();
GetAllFiles(csNewDir);
}else{
pListBox->AddString((LPCTSTR)finder.GetFileTitle()); }
}
finder.Close();
}
And call it with ...
GetAllFiles( "C:" );
if you want the list to show you where all the extensionless
files are on your disk replace
pListBox->AddString((LPCTSTR)finder.GetFileTitle());
with
pListBox->AddString((LPCTSTR)finder.GetFilePath());
Steve T.
|
|
|
|
|
>> ......how to get rid of those directory.....
use the IsDots and IsDirectory members.
>> ...to list files in particular directory
CString extension = "*.*";<br />
CString filepath = "C:\ABC\";<br />
<br />
BOOL haveFile = finder.FindFile ( filepath + extension );<br />
<br />
while ( haveFile ) {<br />
<br />
haveFile = finder.FindNextFile();<br />
<br />
// skip directories<br />
if ( finder.IsDots () || finder.IsDirectory () ) continue;<br />
<br />
//<br />
// do something with the file<br />
//<br />
<br />
}
-Ben
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
For your extension use "*."
This will now find all extensionless files AND
directories (including . and .. ) so put ...
if (!finder.IsDirectory()){
pListBox->AddString((LPCTSTR)finder.GetFileTitle());
}
...in your loop to prevent adding diectory names to
the list.
Steve T.
|
|
|
|
|
I have 2 classes CMainFrame and CDevice that need access to the same variable (bConnected) to tell whether I am connected to a device or not. How do I do that without creating a whole seperate function to gain access to that variable? I though just declaring it publicly should have done the trick....guess not
- John
|
|
|
|
|
Put the variable in the CWinApp.
Declare the BOOL m_bConnect; variable in the protected Section
And add these inline functions in the Public section of the Header of the CWinApp Class
void SetConnect(BOOL bRet){m_bConnect = bRet;};
BOOL GetConnect() {return m_bConnect;};
Cheers!!
Carlos Antollini.
|
|
|
|
|
I asked this question last week (I think). Noone answered, but I think it was a sunday so I figured everyone was watching the tube and relaxing. So, here goes again...
I have a docking window that creates a ListCtrl of type CListCtrl as its child. The listCtrl is created in the docking windows OnCreate function. I can add items to the list from within that OnCreate Function, BUT when I try to get a pointer to that listctrl from another class I always ASSERT in function IsWindow.
Obviously, because there isnt a valid m_hWnd attached to the pointer. BUT how do you define and then use a pointer to a listctrl from outside its own class.
Any help would be appreciated. I've never really grasped pointers 100%. So, maybe this will finally enlighten me.
Frank
|
|
|
|
|
The only thing I can think of is that you might be tring to use the control before it gets created. Also it is not enought to check whether the pointer to the list box is valid, you must check that it has been created(IsWindow will do, or set a flag in the docking window class).
-Ben
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
Thanks Benner,
My calls to add items to the list are done after the application has started, ie by a menu command.
My guess is (and I just had this revelation) that the variable that Is supposed to be storing the reference to my list ctrl is not holding it.
So...
If I'm creating a list ctrl by setting a public member like:
CListCtrl m_wndListCtrl;
And...that list ctrl get created in OnCreate...how do I get hold of it from another class? Yikes...I'm confusing the hell out of myself here.
Thanks,
Frank
|
|
|
|
|
Assuming the list control has been created, then it's just
pMyClass->m_wndListCtrl;
The m_hWnd member will not be valid unless Create has been called, so that the list control is visible. As has been said ::IsWindow() will check this for you.
A pointer is a variable that holds the memory address where something is stored, as opposed to the object itself. What don't you grasp about them ( I'm not being sarcastic, I'm asking so I can offer a reply ).
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|
|
Thanks Christian,
Pointers...and what I don't understand about them by /me:
I can grasp that a pointer defined as CClass* pointer is a pointer to an uninitialized variable. And, that a pointer defined as CClass& pointer is a reference to an initialized object...however I don't understand when you use one over the other. And, don't get me started on why you don't have to use & or * when using CDialog ie: CMyDialog dlg; dlg.DoModal();
As far as using pMyClass->m_wndListCtrl. OK, now if I'm understanding this correctly, the -> means that I must define pMyClass as CMyClass* pMyClass = (Something*)Something.
Where I'm getting confused is the Somethings above...(I hope I'm making sense here.)
Am I totally WRONG?
Calmly yours, and many thanks,
Frank
|
|
|
|
|
OK, here goes.
If you mean you CAN'T grasp that a CClass * pointer is uninitialised, consider this. By declaring this variable, you've declared your intention to store the address of a CClass and allocated enough space to store that memory address. When you call new is when you actually create the object. This is necessary, because sometimes you don't want to call new, for example when a function returns a pointer, or when you're using STL and have a container full of pointers ( the container owns the pointers, but does not call delete on them when it lets them go, so you need to ).
>And, that a pointer defined as CClass& pointer is a reference to an initialized object...however I don't understand when you use one over the other.
A reference is NOT a pointer. A reference allows you to pass an object without making a copy. You'd use this to pass an object into a function where the object either
a. has no copy constructor, or
b. is large and you don't want the overhead of making a copy
A reference cannot be dealt with like a pointer, for starters you can't use ++ to iterate through an array by starting with a reference to item 1.
>And, don't get me started on why you don't have to use & or * when using CDialog ie: CMyDialog dlg; dlg.DoModal();
I don't understand - why would you ? You can't use &, because there is nothing to refer to, you're creating the object. Having created it, you have a pointer to it (&dlg), although you'll lose it because when it goes out of scope the object will be deleted.
>OK, now if I'm understanding this correctly, the -> means that I must define pMyClass as CMyClass* pMyClass = (Something*)Something.
Yes, if it is your CMainFrame class, then it would be
CMainframe * pMain = (CMainframe*) AfxGetMainWnd();
This is a good place to store variables that you need across multiple classes, because it's so easy to get a pointer to. Note this is an example of why CMainframe * pMain creates nothing - you're not creating anything here, just storing a memory address for an object that exists already.
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|