|
kylur wrote:
your "answer" is less than helpful
Yes that is correct. I did not understand the point or goal of your design and actually still don't. Perhaps Mr. Binns solution is what you were looking for.
Good luck
|
|
|
|
|
Make the derived constructors private (or protected ), and add "friend CBase; " to your derived class definition.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Much appreciated... exactly what I needed.
Thank you,
Kylur.
|
|
|
|
|
I want to check if a file path I have is valid and refers to a file before actually going ahead and opening it. Is there a quick and easy way using MFC, the Platform SDK, or the runtime library to check this?
Joel Holdsworth
|
|
|
|
|
Just open the file. Given that you're using a multitasking operating system, there's always a chance that the file could be deleted, renamed, moved, whatever between the time that you check, and the time that you open it.
If you really insist on doing it this way, you could try using FindFirstFile/FindNextFile.
Edit: MFC has the CFileFind class, which wraps these APIs.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
try{
//try opening the file here
catch(someexception){
//the file path is not valid...
}
this way if the filepath does exist you don't have to do that extra step.
Good luck.
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix
|
|
|
|
|
<br />
CFile f;<br />
CFileStatus fs;<br />
<br />
if(f.GetStatus(lpszFileName, fs))<br />
{<br />
}<br />
else<br />
Arjan
|
|
|
|
|
GetFileAttributes(path) != (DWORD)-1
But this makes sense only if you can drop additional code between the check and the file open request
we are here to help each other get through this thing, whatever it is Vonnegut jr.
sighist || Agile Programming | doxygen
|
|
|
|
|
|
_access() is one of several ways.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
I think opening the file with fopen() or CFile() would be easy and fast. I use that function too:
BOOL FileExists(LPCTSTR lpFileName)
{<br />
DWORD dwFileAttr = GetFileAttributes(lpFileName);<br />
<br />
if ((dwFileAttr != 0xFFFFFFFF) &&<br />
!(dwFileAttr & FILE_ATTRIBUTE_DIRECTORY))<br />
return TRUE;<br />
else<br />
return FALSE;<br />
}
I think that should be enough solutions for that problem.
|
|
|
|
|
Joel Holdsworth wrote:
I want to check if a file path I have is valid and refers to a file before actually going ahead and opening it. Is there a quick and easy way using MFC, the Platform SDK, or the runtime library to check this?
there is api called PathFileExist(),try that
-----------------------------
"I Think It will Work"
Formerly Known As "Alok The Programmer" at CP
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
I've to check the status of a TCP connection (managed using CSocket objects) in order to know the status of the remote client/server and the status of the physical connection.
I've implemented a dedicated thread that periodically tryes to send a zero byte packet to the client/server.
It works good to check the status of the remote client/server but, if the physical connection is broken (cable disconnected) it doesn't works! The send operation doesn't fail !
How can I detect the physical disconnection ?
Are there some specific settings for the CSockect object ?
Thanks a lot !
|
|
|
|
|
I am not familiar with CSocket. In raw winsock, one solution is via select().
Kuphryn
|
|
|
|
|
You derive from it and override CAsyncSocket::OnClose()
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
Hi,
Is there a rule of MFC that does not allow thread creation from CMainFrame?
The situation is the following:
I have a menu function that wants to create a thread using
::CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE) ThreadAnalyse, &m_stThreadArg, 0, &dw);
The ThreadAnalyse Function is a static global function, not a member of CMainFrame. The m_stThreadArg is a member of CMainFrame and contains 4 pointer to the CMainFrame Object and 3 pointers to other data.
However it appears that once the menu handler function has returned the whole computer hangs up and runs very slowly. If I place a break point in the Thread function the function is not called for a very long time. Once the function returns the computer returns to normal operational conditions and timings.
Does anyone know why this is?
regards,
RichardS
"Programming today is a race between software engineers striving to build bigger and
better idiot-proff programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
Where in CMainFrm() does the program call CreateThread()?
Kuphryn
|
|
|
|
|
The function is an afx message handler from a menu.
void CMainFrame::OnFileOpenstream (void) is the prototype.
"Programming today is a race between software engineers striving to build bigger and
better idiot-proff programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
RichardS wrote:
contains 4 pointer to the CMainFrame Object
Do not pass MFC objects across threads. This is a well known issue and is documented on MSDN.
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
I have found that if I put a :Sleep (10) after creating tehe thread it runs fine. Do you know where the MSDN documentation for this is?
"Programming today is a race between software engineers striving to build bigger and
better idiot-proff programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
RichardS wrote:
I have found that if I put a :Sleep (10) after creating tehe thread it runs fine. Do you know where the MSDN documentation for this is?
There should be no reason for that to change the behavior of your thread unless there is some problem in your code. No it is not documented that I know of since I don't believe it is any type of feature.
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
Why are you not using AfxBeginThread() ?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
I am used to writing non-MFC applications/libraries so CreateThread was the only alternative that I knew about.
"Programming today is a race between software engineers striving to build bigger and
better idiot-proff programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
Hi,
In my code i use a dialog which contains a propertysheet with multiple propertypages.
All propertypages contain comboboxes and editboxes for the user to fill in.
I would like to have all the propertypages validated [B]as soon as the Ok button
of the dialog is pressed[/B]. This means probably that i can not place validation code in DoDataExchange(), because this function is called everytime when a tab is switched.
The Address Book of Microsoft which can be found in 'Programs->Accessories' also uses this kind of validation. It validates the pages as soon as OK is pressed, not between switching tabs.
How can i do this?
|
|
|
|
|
Do your validating in OnOK()
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|