|
geo19762005 wrote:
List should reside on reboot
trying to understand the above line, can you please help.
suhredayan There is no spoon.
|
|
|
|
|
Is there some reason you try to manipulate the environment strings?
You could more easily store your setting for each user in the registry under HKEY_CURRENT_USER\Software\<yourcompanyname>\<yourprogramname>\Preferences
Then make a REG_SZ (string) value and called FoldersToCheck and save the folders the user selected, perhaps separated by semicolons or something. Or make a key called FoldersToCheck and then make individual values under it Folder1, Folder2, etc. That is up to you.
|
|
|
|
|
I have a class TstClass, In the TstClass.cpp I declare 3 function, 2 are TstClass funxtions, 1 is general functions...
CTstClass.cpp:
...
...
void Process1( void (*pDataRecept)( CString sDataList ))
{
....
}
BOOL CTstClass::GetData()
{
...
Process1( DispData );
...
}
void CTstClass::DispData( CString sData )
{
...
}
But I got Compilling error : error C2664: 'Process1' : cannot convert parameter 1 from 'void (class CString)' to 'void (__cdecl *)(class CString)'
What is the reason? Thanks!
|
|
|
|
|
DispData is a member of CTstClass. The prototype calls for a 'void (__cdecl *)(class CString)'
|
|
|
|
|
As DispData is a member function from the CTstClass, it has an implicit parameter that is passed to the function: the this parameter. Thus, the function prototype does not match.
To avoid that, make your member function static (but then, inside the function you won't be able to play with non-static members).
|
|
|
|
|
In my application I want to access files, where the underlying character type (ASCII or Unicode) is transparent for the application.
Suppose that in a reporting module a report is written to file, like this:
myfile << reportHeader << std::endl;
for (all columns) myfile << columnname;
myfile << std::endl;
for (all records)
{
for (all columns) myfile << data;
myfile << std::endl;
}
Now, I want my application to transparently write the report to ASCII or Unicode files, depending on the user specification.
Currently, you have to do it like this:
std::ofstream asciiFile;
std::wofstream unicodeFile;
if (user wants Unicode)
{
unicodeFile.open ("output.txt");
unicodeFile << reportHeader << std::endl;
}
else
{
asciiFile.open ("output.txt");
asciiFile << reportHeader << std::endl;
}
for (all columns)
{
if (user wants Unicode) unicodeFile << columnname;
else asciiFile << columnName;
}
... and so on
The disadvantages seem obvious:
- clumsy, unreadable code (especially if the write-to-file logic is spread over several methods)
- writing Unicode strings (std::wstring) to an Ascii stream doesn't even work; it produced garbage
Therefore, I need a kind of transparent stream, so that I can write the following:
transparentstream myfile;
myfile.setMode (ascii or unicode);
myfile.open ("output.txt");
myfile << reportHeader << std::endl;
for (all columns) myfile << columnname;
myfile << std::endl;
for (all records)
{
for (all columns) myfile << data;
myfile << std::endl;
}
Problems are:
- from which stream do I inherit the transparentstream?
- how do I define the transparentstream so all defined output operators keep on working?
- where do I put the conversion logic? (basic_buf? basic_filebuf?)
Of course I want something similar for input, where the stream can find out itself whether the file is Unicode (starts with 0xfffe or 0xfeff) or plain Ascii.
And as an additional challenge: is it possible to have such a transparent stream that can do something like this?
transparentstream mystream;
mystream.open("http://www.mywebsite.com/mypage.html");
mystream >> ...;
And if this is possible, how do I implement such a stream of buf class?
Did some of you already encounter problems trying to mix the STL and Unicode files?
How did you solve it?
Probably Java and .Net solve this problem in a elegant way, but I really need a solution using only STL.
Thanks for you suggestions.
Enjoy life, this is not a rehearsal !!!
Enjoy life, this is not a rehearsal !!!
|
|
|
|
|
My first thought is to encapsulate the ASCII and UNICODE streams with in your own class (or template) then duplicate the methods. It may be as simple defining operators for both char and wchar_t (I dought it thou).
class transparentstream
{
std::ofstream asciiFile;
std::wofstream unicodeFile;
...
};
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
Is there a way to enumerate the windows of an application from it's process id?
thanks
|
|
|
|
|
I am not aware of a direct way.
Look at EnumWindows followed by a call to GetWindowThreadProcessId to correlate the known PID with the enumerated HWND.
To be really thorough, you can also EnumWindowStations followed by EnumDesktops followed by EnumDesktopWindows followed by GetWindowThreadProcessId
|
|
|
|
|
Hi,
I am doing a project in win32 . I use DBT_DEVICEARRIVAL and DBT_DEVICEREMOVECOMPLETE messages to do certain things when a usb device is connected and disconnected.When I tested the app in XP the above messages are being called twice. ie when I plug the usb device the DBT_DEVICEARRIVAL is called and after certain time say a sec later it automatically calls DBT_DEVICEREMOVECOMPLETE and again DBT_DEVICEARRIVAL. I dont know why it does that. Do anyone have any ideas...pls help
|
|
|
|
|
|
When does the BEGIN_MESSAGE_MAP gets called to map control ID's to functions? I am asking this because in my project, a previous software engineer designed a class that is derived from a CFileDialog and attaches another dialog to the bottom of the CFileDialog as a toolbar. The issue I am having here is that the current class is dependent on a resource file for that project and for my project the resource ID's are different. I am including the file into my project using #include "..\projectname\COpenFileDlg.h" and the resources (dialog use as a toolbar).
My idea to work around this was to create static member variables that I can access/change the ID's before the constructor, BEGIN_MESSAGE_MAP and the OnInitiDialog() gets called. I know this is pretty ugly and I don't have a whole lot of time on hand to redesign it right now. But this is an easy way to work around it by having whoever (projects) that uses this customized dialog to provide their own ID's.
Any suggestions?
|
|
|
|
|
kongy79 wrote:
When does the BEGIN_MESSAGE_MAP gets called...Any suggestions?
I would suggest placing a breakpoint in the constructor, BEGIN_MESSAGE_MAP() , and OnInitiDialog() to see the calling order.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Thank you for the offer. I fixed the bug already.
|
|
|
|
|
Hello,
I have some troubles to put version number in DLL generated by Message Compiler. In fact if I try to add a resource/Version, I just get some compiling errors.
Please help me.
Julien.
|
|
|
|
|
I'm working on a Windows Service and I'm looking for a straight-forward way to monitor its responsiveness while in the SERVICE_RUNNING state. I know that the Service Control Manager watches for hangs during startup with SetServiceStatus() and the checkpoint parameter, but what if the Service hangs while it's running?
I've thought about making another service to watch the service, but this seems a bit circular.
Any ideas?
Rodney
|
|
|
|
|
You ultimately have to be looking at it with something else, right?
And what can you do, or what is your goal, once you detect it is hung?
It could be sufficient to have your primary service thread (the one that MGHT hang) periodically update some counter or timestamp. A secondary thread (not likely to hang) within the same service can wake up periodically or be awoken with an event set by the first thread. It could examine the counter/time stamp. If the counter/timestamp has not bene updated 'recently' then maybe the secondary thread writes an event to the event log indicating the 'service' is hung and needs attention. Then you don't need to write two services.
An administrator can look at the event viewer to see if your service got stuck. Programs exist that can periodically scan the event log looking for particular items, and that might be sufficient to document the stuck service. There may be other things your secondary thread could do to bring attention to the stuck service.
|
|
|
|
|
Once I detect it as hung, I want to kill it and restart it. Using a counter-monitoring thread sounds good. I was also thinking of calling ::ControlService() with SERVICE_CONTROL_INTERROGATE to see if the call returns in a timely fashion, but I've heard this might not work because the Handler might still be processing commands when the rest of the service is hanging. Although, arranging the Handler to wait on an event to be set within ServiceMain() could still timeout the ::ControlService() call appropriately. Does this approach make sense, or do you think it's over-complicating things?
Rodney
|
|
|
|
|
ANY properly written Windows service should posess at least two threads. One thread does the service-specific work, and the other one services the control requests. In your case, I was proposing a third thread, which would monitor the status of your service and 'report' that it had hung. Now, I am not sure that a service can send a STOP control request to itself, this is something I have never thought to do or try. (Yoda was wrong, there is TRY and there is DO...) Anyway, you need to figure out what will 'terminate' your hung thread or cause your service to restart.
I suppose I would also encourage you to figure out why your service hangs. Is this truly unavoidable? Are you dealing with poor legacy design or something? I write and maintain a lot of code, and I don't think we have anything that we 'expect' to hang. That just does not seem right.
Maybe if you could describe for us here at CP what the underlying problem is, we could make some additional suggestions
|
|
|
|
|
Actually, my service is still relatively simple and has never hung, except when I make it do so on purpose. I'm just trying to develop defensively. At this point, my questions are "what-if". I plan on developing a service that never hangs! Never say never, though.
The three-thread approach sounds good. I figured I'd kill the hung service (as gently as possible) so that the Service Control Manager would boot it up again according to the set preferences.
One other thing, I was encountering difficulties when testing a service that hangs starting up. I was under the impression that the SCM would monitor the service and kill it if it takes too long to start up. In my case though, after two full minutes, the SCM tells me my service could not start, and then just leaves the struggling service in memory. It never actually kills it or tries to restart it. Am I misunderstanding the role of the SCM in this case?
Thanks for your responses!
Rodney
|
|
|
|
|
If you stop the service you need to restart it. The SCM will only start 'automatic' services when Windows is starting up or if another dependent serice is trying to start. At other times, you need to start it yourself.
When adjusting the service properties, I see a 'Recovery' tab in the dialog. It seems the default recovery options are to 'do nothing'. One of the choices is 'Restart Service'. Maybe you can try adjusting the options to see if you obtain a desired result.
|
|
|
|
|
Yeah, the "Recovery" options is what I meant by "set preferences" in my previous post. The "Restart" option works well when the service is killed, but restart doesn't seem to work when the service hangs during its start phase, even though I was led to believe that the SCM would kill a service unable to start up.
Rodney
|
|
|
|
|
I would have beleived the same thing, based upon all the MS documentation.
They would make you think your service is going to suffer hellfire and damnation if it does not report 'service start pending' periodically to the SCM during start up. And now your testing makes it look like the SCM does not do anything (except maybe report the service is hung or failed to start, to the event logger.
Regardless of recovery options settings, it seems your service is not killed and restarted. That sucks
|
|
|
|
|
I used the code below to create a slider control. I tried to put the code into another initialize function of my own but it wouldnt work. Can the code be put into another function?
What I really dont understand is why do I need to include:
CDialog::OnInitDialog()...to make the project run? Without it I get a run time error condition.
Jerry
/////////////////////////////////////////////////////////////Create slider control here
BOOL dialogWnd::OnInitDialog()
{
CDialog::OnInitDialog();
CWnd* pWnd = GetDlgItem(IDC_SLIDER1);
CRect rect;
pWnd->GetWindowRect( &rect );
ScreenToClient( &rect );
m_Slider.Create( WS_VISIBLE|WS_CHILD|TBS_HORZ, rect, this, IDC_SLIDER1 );
return TRUE;
}
|
|
|
|
|
Is your question why does OnInitDialog() exist or why you call it there ?
OnInitdialog contains initialisation code that is required by a number of functions such as Create() and DoModal().
As to why call it, your derived OnInitDialog() must call the base class function to use this code. It's that or write it again yourself.
Elaine
The tigress is here
|
|
|
|