|
bisserke wrote:
I did check the return value. It was 3, as one would expect.
Why would you expect the return value of _open() to be 3? Since when do handles have known values?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
because 0,1,2 are default so normally, in this little app, the first one free is 3.
I used to have a life ... now I have a computer
|
|
|
|
|
IIRC, file handles are local to the instance of the C-runtimes in which they are created. if your DLL and your calling program are not using the same instance of the C-runtimes, they cannot share file handles.
this applies to memory too: malloc/new across DLL boundaries = bad, if the DLL and EXE use different CRT instances.
so.. are your DLL and EXE statically linking to the CRT or, using dynamic linking ?
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
Well they are dynamically linked. So I'm gonna look into this. Looks like a good lead.
(I'm actually pretty new to Windows environments...)
thx
I used to have a life ... now I have a computer
|
|
|
|
|
bisserke wrote:
Has to do with a porting job.
If you're going for portability, then you should probably just put the functionality in a standard library (which has to be staticaly linked).
If you are putting the functionality into a DLL then the DLL should be handling all the file I/O. That is it should export the functions for reading/writing and any other file related activity required.
Good Luck!
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
I have an application that launches a wizard based property page that contains N property sheets. All of the pages are added to the property sheet at initialization.
At one point in the wizard, it has a group of radio buttons that determine which sheet should be shown next. I am able to get to the next page without a problem. However, when I press back, it should skip all the pages in between and go back to the radio button selection page. I am using the following code to go back:
LRESULT CPropPageOptions::OnWizardBack() <br />
{<br />
CPropSheet* pParent = (CPropSheet*)GetParent();<br />
ASSERT_KINDOF(CPropSheet, pParent); <br />
<br />
switch(pParent->m_nScheduleType)<br />
{<br />
case 1:<br />
return pParent->SetActivePage(&pParent->m_pageWeekly);<br />
case 2:<br />
return pParent->SetActivePage(&pParent->m_pageMonthly);<br />
case 3:<br />
return pParent->SetActivePage(&pParent->m_pageOneTime);<br />
default:<br />
return pParent->SetActivePage(&pParent->m_pageDaily);<br />
}<br />
return TRUE;<br />
<br />
}
This doesn't seem to work correctly. It goes back through all the pages one at a time. Is there any way to make this work correctly, short of redesigning this so the pages are added as they are needed?
Brigg Thorp
Senior Software Engineer
Timex Corporation
EDITED - the returns in the switch statement are now present.
|
|
|
|
|
You forgot to break . If that's exactly what you wrote, cut-and-pasted, it will always drop through the bottom of each case , meaning that m_pageDaily is the page shown.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Actually, I had returns in there...don't know why they didn't show up. This is how it actually is.
LRESULT CPropPageOptions::OnWizardBack()
{
CPropSheet* pParent = (CPropSheet*)GetParent();
ASSERT_KINDOF(CPropSheet, pParent);
switch(pParent->m_nScheduleType)
{
case 1:
return pParent->SetActivePage(&pParent->m_pageWeekly);
case 2:
return pParent->SetActivePage(&pParent->m_pageMonthly);
case 3:
return pParent->SetActivePage(&pParent->m_pageOneTime);
default:
return pParent->SetActivePage(&pParent->m_pageDaily);
}
return TRUE;
Brigg Thorp
Senior Software Engineer
Timex Corporation
|
|
|
|
|
Brigg Thorp wrote:
It goes back through all the pages one at a time
Are you aware of that :
Returned Value (of OnWizardBack):
0 to automatically advance to the next page; –1 to prevent the page from changing. To jump to a page other than the next one, return the identifier of the dialog to be displayed.
So be careful to what you actually return, because pParent->SetActivePage(); is always a BOOL .
~RaGE();
|
|
|
|
|
I figured out what the problem was. I needed to set the active page first, then return -1 to tell the base class to not change the page, since I already did. Code as follows:
LRESULT CPropPageOptions::OnWizardBack() <br />
{<br />
CPropSheet* pParent = (CPropSheet*)GetParent();<br />
ASSERT_KINDOF(CPropSheet, pParent); <br />
<br />
switch(pParent->m_nScheduleType)<br />
{<br />
case 1:<br />
pParent->SetActivePage(3);
break;<br />
case 2:<br />
pParent->SetActivePage(4);
break;<br />
case 3:<br />
pParent->SetActivePage(5);
break;<br />
default:<br />
pParent->SetActivePage(2);
}<br />
<br />
return -1;<br />
}
Regards,
Brigg Thorp
Senior Software Engineer
Timex Corporation
|
|
|
|
|
I had some trouble with my app because it allocates a lot of memory. The longer you use it the more memory was eaten away. After searching for a reason I endet up with CFindFile as the only reason for that.
I have a loop and after deleting all but the CFileFind calls it is the only think that keeps running and allocating memory. Unfortunately CFileFind seems to not release the memory it uses. I tried everything:
CFindFile* findfile=new CFindFile();<br />
findfile->Close();<br />
delete findfile;
doesn't release any of the allocated memory. Can someone help me? How can I free the allocated memory. Is there a alternate way to search for files in a directory?
|
|
|
|
|
There is no reason to use a heap variable here. Use a stack variable and your memory-related problems will stop.
ryuki wrote:
doesn't release any of the allocated memory.
Actually it does, but you are confused as to what happens with memory once it is freed. If you are using Task Manager to watch your program's memory drop after each call to free , you will surely be disappointed.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
I work under Win98 and use the systemmonitor for viewing allocated memory. Its not easy to say but there seems to be more to the memory issue than expected. I managed to find another source of consuming memory. It is a little part including SHGetFileInfo. And that small codebit causes much more trouble than all other together. It seems that SHGetFileInfo allocates memory too. But you can't see it at the systemmonitor. It eats all of it with time and at a single point I can't create threads anymore or some functions like StretchDIBits doesn't work properly because there is no memory anymore. I get a lot of "Not enough memory" errors allthough all ressourceviewers say there are more than 100 MB of free memory still there.
I can give you the small code example:
<br />
SHFILEINFO sfi;<br />
UINT uFlags = SHGFI_SYSICONINDEX | SHGFI_DISPLAYNAME | SHGFI_ICON | SHGFI_SMALLICON;<br />
if ( SHGetFileInfo ( tmp, 0, &sfi, sizeof(SHFILEINFO), uFlags ))<br />
m_ctrPathFrom->InsertItem ( npos, sfi.szDisplayName, sfi.iIcon );<br />
Thats all. I looked at the documentation but it says nothing about freeing the structure or something. Does someone know what to do?
And you can be believe me, i traced the cause of the memory issue to that single if-line.
I hope someone can help.
|
|
|
|
|
From MSDN:
[quote]
Remarks
If SHGetFileInfo returns an icon handle in the hIcon member of the SHFILEINFO structure pointed to by psfi, you are responsible for freeing it with DestroyIcon when you no longer need it.
[/quote]
sig test
|
|
|
|
|
Thank you for the hint. I use the standart documentation, the msdn library coming with VC++ 6. Next Time I will check the online docu too.
|
|
|
|
|
ryuki wrote:
...the msdn library coming with VC++ 6.
Which is nearly five years old.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
I am a little new to the thread world and was wondering if someone can provide some assistance to get me started in a file monitoring project. Here is what i am attempting to accomplish:
From a win 32 dll, monitor a particular directory constantly for new files. Everytime a new file gets put in there, this thread or something will detect this, open the file and read from it. Once done reading, it will store it in another directory and move onto looking to see if another file got placed in that directory.
I was thinking that in the dll, i can run a thread that will monitor the directory and perform the functionality above.
Firstly, does it make sense to use a thread in this case, and secondly, can anyone provide some guidance or sample code to get me started?
Thanks in advance.
|
|
|
|
|
you can't just do it like this!!
It takes time to write a file -> it may happen that you detect a new file when it is not yet completly written!
What exactly do you want to do? Which software does create the files? What kind of files? ...
Don't try it, just do it!
|
|
|
|
|
If the other progrma is under your control, you would need to make sure it opened the file for exclusive readn and write access, so that the file monitor could not access the file until the 'original' author was finished.
This would partially solve the problem.
|
|
|
|
|
It is a third party software that is creating the files. I can assume that the files will be saved off to a known directory at any time.
These files are XML files. Even if it takes 1 hour for the file to be written to the directory that is fine. I just have to monitor the directory it so that when it does get written, i can load it and parse through xml parser for what i need.
|
|
|
|
|
Look at FindFirstChangeNotification . I am pretty sure there are some samples on CodeProejct for this API. Yes, it is the kind ofperation I would place into a thread, since you have to use the Wait... functions to wait for changes to occur. Not the kind of operation I would want blocking the primary thread of my program.
|
|
|
|
|
Thanx, i will try this and let you know how it works.
|
|
|
|
|
Also check out ReadDirectoryChangesW() .
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
I use a win32 dll to read an XML document. CString is not an option. I read one particular tag and i have to store the contents of that tag in a variable and then parse it to extarct certain data and store elsewhere.
My first question is :
MSXML2::IXMLDOMNodePtr ptagNode;
sometype strvar = ptagNode->text;
What "type" should sometype be? I am using a _bstr_t but i do not know how to exactly use functions to search this if there are any at all, cause i haven't seen any. Can anyone advise me as to what type i should use that will allow me to easily parse the data since i cannot use CString? I would like to use methods such as find to find a substring etc.
Thanks..
|
|
|
|
|
LCI wrote:
What "type" should sometype be?
std::string
it's a little non-intuitive, at first. and a lot of functionality you might expect doesn't exist. but it's pretty simple to add what you need, in most cases.
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|