|
But be careful if you are looking for changes on remote (network) shares. Both ReadDirectoryChangesW(...) and FindFirstChangeNotification(...) may experience problems when working with network shares - regarding path lengths and/or the remote system might not support notification of filesystem changes in such a manner. (Experienced this myself more than one time.)
IOW, if your application could be working with remote filesystems, it should have a polling interval as a fallback as well. Nothing worse than getting a call first thing in the morning from a site saying that your "real-time file processing application" stopped working this morning (they upgraded a *nix box that hosted one of the shares used the previous evening, and its network file support was slightly broken).
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
Is it possible to start a class member function as a separate worker thread or do I have to define the typical UINT MyThread(void* pParam) type of function?
If I do need to define the typical thread function, how can I encapsulate every thing into a class?
Thanks in advance!
|
|
|
|
|
Cteate static MyThread function in your class:
<br />
UINT CMyClass::MyThread(LPVOID param)<br />
{<br />
CMyClass* _this = (CMyClass*)param;<br />
<br />
return _this->DoSomeWork();<br />
<br />
}<br />
You can start thread this way AfxBeginThread(MyThread,this);
rrrado
|
|
|
|
|
Don't forget that the 'thread function' has to be a 'static' function.
Something like this...
class CMyClass
{
public:
BOOL StartThread() { m_pMyThread = AfxBeginThread( MyThreadFn, this ); }
protected:
CWinThread* m_pMyThread;
UINT MyThreadFn();
static UINT MyThreadFn( LPVOID pThis ) { return ((CMyClass*)pThis)->MyThreadFn(); }
};
This[^] is the best article in my opinion to get started with multithreading.
--
Roger
It's supposed to be hard, otherwise anybody could do it!
|
|
|
|
|
Thanks Roger.. I wil try that...
|
|
|
|
|
I tried your solution and everything compiles and runs but my thread has no access to the class member variables. I initialize them in my class constructor but the thread function sees them as uninitialized.
Is there a way for my thread to access class member variables and functions.
Thanks!
|
|
|
|
|
You cant access nonstatic member from static function directly.
To solve this issue, create a static pointer to same class like
static CYourClass *thisClass; and assign this pointer to the static pointer, then user thisClass pointer in your thread. and aceess variable & functions using thisClass->fun() or thisCLass->varibel
|
|
|
|
|
I am not sure I completely understand your solution. Can you explain it a bit further?
Thanks.
|
|
|
|
|
I tried what you suggested and I got the following error:
CTCPServer::ListenThread': function call missing argument list; use '&CTCPServer::ListenThread' to create a pointer to member
Is there anyway to resolve this? If you need to see the code please let me know.. I didn't want to post it unnecessarily.
Thanks for your help.
|
|
|
|
|
The scenario is this:
In a 16 bit application A.app I am calling a 32 bit dll B.dll with a method exposed "DisplayDialog(HWND hWnd)".
DisplayDialog is called through the following sequence:
hDD = LoadLibraryEx32W(B.dll);
hDisplayDialog = (DISPLAYPPROC)GetProcAddress32W(hDD, "DisplayDialog");
CallProcEx32W(1, 1, hDisplayDialog, hWnd);
The resource for the dialog which I want to diaplay is in a 2nd 32 bit dll
C.dll. I am loading C.dll in B.dll using
hInstance = LoadLibrary(C.dll).
Then to display the dialog I am using this code in B.dll:
hDlg = CreateDialogParam(hInstance, MAKEINTRESOURCE(IDD_SOME_DIALOG), hWnd, (DLGPROC)SomeDlgProc, NULL);
ShowWindow(hDlg , SW_SHOWNORMAL);
SomeDlgProc is defined in B.dll.
hDlg is comming out as NULL.
GetLastError following the function call is returning 0.
Please advice what is going wrong.
Regards,
The scenario is this:
In a 16 bit application A.app I am calling a 32 bit dll B.dll with a method exposed "DisplayDialog(HWND hWnd)".
DisplayDialog is called through the following sequence:
hDD = LoadLibraryEx32W(B.dll);
hDisplayDialog = (DISPLAYPPROC)GetProcAddress32W(hDD, "DisplayDialog");
CallProcEx32W(1, 1, hDisplayDialog, hWnd);
The resource for the dialog which I want to diaplay is in a 2nd 32 bit dll
C.dll. I am loading C.dll in B.dll using
hInstance = LoadLibrary(C.dll).
Then to display the dialog I am using this code in B.dll:
hDlg = CreateDialogParam(hInstance, MAKEINTRESOURCE(IDD_SOME_DIALOG), hWnd, (DLGPROC)SomeDlgProc, NULL);
ShowWindow(hDlg , SW_SHOWNORMAL);
SomeDlgProc is defined in B.dll.
hDlg is comming out as NULL.
GetLastError following the function call is returning 0.
Please advice what is going wrong.
Regards,
|
|
|
|
|
Background
my MFC application developed on VS7.1, wrapped in InstallShield.
Users with Win2000 cannot run new project element.
(also installed SP4, .NetFramework and sometimes VS6)
Users with XP - no problems
Users with Win2000 and VS7 - no problem.
InstallShield delivers Mfc71.dll, mfc71u.dll, msvcp71.dll, msvcr71.dll, msvcrt.dll
New element is some windows hooking code.
I cannot use debug on VS7 becuase this fixes the problem.
I've tried Installshield dynamic scanning but i couldn't see what was missing.
The hooking code only includes stdafx.
Whats the easiest way to find the problem without adding loads of Message Boxes? I'm just toooo lazy for that
JBW
You can please some of the people all of the time and all of the people some of the time but not all of the people all of the time.
|
|
|
|
|
Use Process Explorer from SysInternals to see what modules are loaded while your program is running. One of those is probably missing from Windows 2000. Otherwise, perhaps you used an API that does not exist on Windows 2000.
People that start writing code immediately are programmers (or hackers), people that ask questions first are Software Engineers - Graham Shanks
|
|
|
|
|
Process explorer did show that for some reason Kernel32.dll is missing from my apps runtime on the problem machine. I don't get any system messages to warn me of an error though. I've tried statically linking my kernel32.lib but that doesn't work. It feels like some dll versioning problem but I don't really know so I'll have to keep looking.
You can please some of the people all of the time and all of the people some of the time but not all of the people all of the time.
|
|
|
|
|
I have reconsidered all my functions and I cannot see that I've used any functions that are XP only. I cannot find any articles to support my feelings that the kernel32.dll or other dlls are out of date. Furthermore, I cannot find any other developers, via google searching, who seem to have had this same problem where customers using win2000 with VS7 installed have no problem but customers without do.
Can anyone point me in a research direction?
You can please some of the people all of the time and all of the people some of the time but not all of the people all of the time.
|
|
|
|
|
I am currently developing a MFC dialog based application and i need a function----- void Pause(int time) such that Pause(3); will stop a loop(or rather the whole application) for 3 seconds...Pause(n) will stop a loop for n seconds..etc. What is the easiest way to write such a function(preferebly without #including any libraries) ? I have been experimenting with some of the syntax without much success...Can some kind soul please put me out of my misery and tell me how to do it ?
Thanks
|
|
|
|
|
|
|
|
What I do is set up a timer to interupt every second, and then count the interupts. When you have got to your required count, you can the go off and do the functionality that you want to do
Mike
|
|
|
|
|
WM_TIMER
This is a very easy thing to use, but is not 100% accurate.
You will need SetTimer and KillTimer
|
|
|
|
|
How can I achieve, that "Enter" works on a certain Button ? I´d like to change this during program. Sometimes Button "A" should work on ENTER, sometimes another one.
|
|
|
|
|
If you have a dialog-based application, you could set the default button with CDialog::SetDefID( UINT nID ) where nID is the ID of the new default button.
Hope this helps
--
Roger
It's supposed to be hard, otherwise anybody could do it!
|
|
|
|
|
Thanks, that works fine !
|
|
|
|
|
I'm writing a small app that has a number of classes in it. I would like to save the data to a single binary file. I understand how to write the data to the file, but when is comes to reading it again I'm lost.
If the data classes are written to the file in random order, (I know, not a good practice) how do I retrieve the data I have written to the file?
Or is it better to have a file for each class?
If you could point me in the right direction your help would be greatly appreciated...
Thanks, mcb36
|
|
|
|
|
You have of course to load your data in the same order you saved it. Otherwise you will get into big troubles.
|
|
|
|