|
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
|
|
|
|
|
if i use std::string and i declare strVar as a string, i get undeclared identifier. Is there something else that i am missing? I also did a #include <string.h>
Help!
|
|
|
|
|
#include < string >
..
std::string strVar;
strVar = "hi";
or
#include < string >
using namepsace std;
..
string strVar;
strVar = "hi";
most will recommend the former.
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
|
I have a .h and a .lib file that I can use in a Win32 C++ Console application. I like to use it in a .NET C# program is that possible. Suggestions on articles in this topic would be great!
_____________________________
...and justice for all
APe
|
|
|
|
|
Yes it's possible, BUT you have to create a c++ dll from the lib file.
Use a def file for the dll to export some functions from the lib (for C exports), or, change the header file with the class attributes __declspec(dllexport) to export classes.
Don't try it, just do it!
|
|
|
|
|
Ok.
Unfoutanly my the .h-file is about 50.000 lines of code and the lib is about 40MB. Does it exist any tool for accomplish this?
By the way, is it possible to export a class for use in C#?
_____________________________
...and justice for all
APe
|
|
|
|
|
Hello
Can anyone tell me that how can i search out the specific string in a text file.and then change it
|
|
|
|
|
How you search for a string really depends on how you are processing the file. If the file was opened as a CStdioFile object, you can use the ReadString() method to read one line at a time from the file. That line of text can then be searched for the string of interest.
Once you have this bit working, create another post and we can give you suggestions on replacing text.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
where can i get the simplest example ?
vivek
|
|
|
|
|
You can make use of the ADO wrapper classes from Carlos Antonelli here at codeproject in the Database section. The usage is same as the MFC DAO classes. Great work.
MS
|
|
|
|
|
|
Why threads are declared as Static when used from Class?...?
vivek
|
|
|
|
|
because you might be careful to the this pointer implicitely added to the header of a member function...
it is the same as CallBack functions
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
See here.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Functions used to be created as threads are defined as "static" when used with a C++ Class because there is an implied parameter that doesn't show up in code, the THIS pointer.
To avoid this confusion and make it simple "static" class members only operate on static data and not per-instance data and as such the "this" pointer is not passed in. So, it's easy to define the function as static and use it in CreateThread without worries. Of course they usually pass the object instance as the first parameter anyway.
class x
{
public:
static DWORD WINAPI MyThread(PVOID lParam)
{
x *pX = (x *)lParam;
}
}
...
x pX = new x;
CreateThread(...., x::MyThread, pX);
As you see in the above example the thread can be created and the system will pass in the "this" pointer and we will manually re-use it.
Another way to do this in the C++ is to simply define a class function to be standard call, NOT FAST CALL, and take "void" parameters.
class x
{
public:
DWORD WINAPI MyThread(void);
};
...
x *pX = new x;
CreateThread(..., x::MyThread, pX);
Why void parameters?
Because the system will now pass in the "this" pointer for you and in C++ the language hides this detail anyway.
Why stdcall and not fastcall?
STDCALL should pass the "this" pointer on the stack while fastcall passes the this pointer in ECX register, which the system has no idea about.
8bc7c0ec02c0e404c0cc0680f7018827ebee
|
|
|
|