|
Use GetLocalTime [^]
Величие не Бога может быть недооценена.
|
|
|
|
|
couldn't find an equivalent here. it depend on your requirement. 
|
|
|
|
|
Hi
i am using insert--> resource use create the menus. Then how to add menus in Dialog box? pls give any url or steps?
Regards,
M.Mathivanan
|
|
|
|
|
Hello,
Create the Menu in Menu Resources. (for eg. IDR_MENUDLG)
The dialog you want to add this menu (eg. IDD_DLGMNU)
Now, in the dialog procedure of your dialog IDD_DLGMNU, in WM_INITDIALOG case, add like this.
HMENU hmenu=LoadMenu(hInstance,MAKEINTRESOURCE(IDR_MENUDLG));
SetMenu(hwnd, hmenu); // --- hwnd is handle to window for your dialog IDD_DLGMNU.
hope this will help.
Thanks & Regards
A. Gopinath.
|
|
|
|
|
|
You can add it directly into the resource file unless you are using a dialog generated at runtime (which you arent)
Just open the dialog in the resource editor in Visual Studio, select the dialog box, then down near the bottom of the properties window (View->Other Windows->Properties Window) there is an optiom there for Menu, just select your menu ID from the dropdown list.
If you arent using the dialog editor, you can add it to the .rc file manually like this (the line in red):
IDD_UNDELETE_DIALOG DIALOGEX 0, 0, 320, 200
STYLE DS_SETFONT | DS_FIXEDSYS | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
EXSTYLE WS_EX_APPWINDOW
CAPTION "My Dialog"
MENU IDR_MAINFRAME
FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
CONTROL "",IDC_FILES,"SysListView32",LVS_REPORT | LVS_AUTOARRANGE | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP,98,0,222,200
END
|
|
|
|
|
I've got a DLL that is injected into every process in my system. Among other things, it does a bit of process monitoring. As part of that, I'd like to track the exit code of each process. DllMain with a reason code of DLL_PROCESS_DETACH enables me to tell if the process is exiting nicely or not via the value of the reserved parameter. I'm obviously interested in the not nice case. Calling GetExitProcessCode isn't useful because the process has not completely exited yet and the code isn't available until it's truly dead . I know that for DLL_PROCESS_ATTACH, the reserved value is actually a CONTEXT pointer. Is there something similar for the _DETACH case - in other words, what does the reserved parameter point to? I'm hoping that it points to something that I can use to see what that exit code is - the system knows what it is since the process is in the act of exiting, but there isn't an API to get it. Any ideas?
Thanks,
Judy
Be wary of strong drink. It can make you shoot at tax collectors - and miss.
Lazarus Long, "Time Enough For Love" by Robert A. Heinlein
|
|
|
|
|
Hi Judy,
I know that if you call NtQueryInformationProcess with the PROCESSINFOCLASS of ProcessBasicInformation on a normally executing process... the ExitStatus member of the PROCESS_BASIC_INFORMATION struct should always return 0x103 which is STATUS_PENDING. You could try checking this value during DLL_PROCESS_DETACH, it should be safe to make calls into NTDLL. I cannot remember off the top of my head when ntoskrnl sets this exit code value during process termination so it may not be changed yet. I'm not in my normal office so I cannot test this. Let me know how it turns out.
Best Wishes,
-David an eluDe
|
|
|
|
|
hi,
sorted eg:
!
)
1
2
3
t
T
the
The
THE
then
I'm wondering the 'best' way to go about this using the standard library.....
I could create a custom alphabetical order...in a struct?/class?.. say char_codes that holds 2 vectors..
vec 1 = all chars ..in order I need
vec 2 = char codes/values ..in order I need
then use: sort( s,e, compare )
..the compare func would use member function...something like int char_codes.value( char ) to retrieve the value I'v assigned to the char being compared
Or is there a better way???
|
|
|
|
|
Basically, but there is already a number of functions that can compare strings based on the ASCII values, like strcmp (case sensitive) or stricmp(case insensitive)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *szValues[] = {
"3",
"t",
"2",
"the",
"1",
"The",
"T",
"then",
"!",
"THE",
")",
};
int CmpStr(const void *szVal1, const void *szVal2) {
return strcmp(*(const char **)szVal1, *(const char **)szVal2);
}
int main() {
int nVal;
qsort(szValues, sizeof(szValues) / sizeof(char *), sizeof(char *), CmpStr);
for (nVal = 0; nVal < sizeof(szValues) / sizeof(char *); ++nVal) {
printf("%s\n", szValues[nVal]);
}
return 0;
}
|
|
|
|
|
thanks andrew and ash for the help, im new to c++ so its taking me a long time to test your ideas
CmpStr puts 'THE' before 'The'....and other problems as you can see below
..I would be interested if you can get this working as I would like to test the performance against the mapping solution
!
&
1
1
1
2
222
3
33
5
6
7
A
AND
ANDY
ANDY1)
And
And
THE
THE
The
The
a
an
an
andy
andy22
andy3
t
tHe
the
then
required output:
this is as far as I'v got using the mapping solution..as you can see it gets confused sorting strings made up of words&numbers..but thats not too important atm
!
&
1
1
1
2
3
5
6
7
33
222
a
A
an
an
And
And
AND
andy
ANDY
ANDY1)
andy22
andy3
t
the
tHe
The
The
THE
THE
then
here is the input for c&p
char *szValues[] = {
"The",
"222",
"andy",
"5",
"AND",
"6",
"ANDY1)",
"ANDY",
"7",
"&",
"the",
"andy3",
"an",
"3",
"And",
"1",
"tHe",
"THE",
"1",
"a",
"an",
"A",
"t",
"then",
"The",
"And",
"1",
"tHe",
"THE",
"andy22",
"2",
"!",
"33",
};
modified on Saturday, January 22, 2011 9:30 PM
|
|
|
|
|
Exactly how you do this depends on how often you think you're going to need to change the collation order. If it's something that doesn't change much or you haven't got that many orders you can hard code the orders in one or more functors.
If you want to parameterise the collation order even more I'd be tempted to use a map:
std::map<char, int> collation_map;
initialised with each character code and it's placing in the sort order. Then you can implement your comparison functor something like:
class collator
{
public:
collator( std::map<char, int> collation_map ) : collation_map_( collation_map ) {}
bool operator()( char a, char b )
{
return collation_map_[ a ] < collation_map_[ b ];
}
private:
std::map<char, int> collation_map_;
};
Caveats here are that this code hasn't even seen a compiler so I might have got something syntactically or semantically wrong this time of the morning. I hop the idea's sound though.
You might have some "interesting" performance issues (in terms of memory consumption) if you want to use wide characters using this method (especially on platforms with a 4 byte wide character) but it should be okay for ordinary characters.
Cheers,
Ash
|
|
|
|
|
thanks again for the help ash,
not sure how often the order will need to change, im in the process of learning string manip, and beginning to see how some kind of general String class will be helpful to contain all the required functionality to deal with strings/chars/text..so I guess it's preferable that its efficient and versatile ..enough to deal with a broad range of unknown alphabetical sorting situations
anyways your mapping idea seems to work well..even if it took me ages(noob) to implement...if I can get a working version of andrews solution I would like to compare them both using a large collection of strings to be sorted..maybe a dictionary or a book or something similar
modified on Saturday, January 22, 2011 5:58 PM
|
|
|
|
|
For those of you who have adopted one of the various techniques that have been proposed to avoid inadvertantly calling a virtual method from a constructor, which method did you choose?
So far, this one [^] seems the most promising to me but I've not tripped over this problem (that I'm aware of ) till today so I have not given it much thought in the past and I need some guidance.
|
|
|
|
|
If you use test driven development and write unit tests for your code you pick up very quickly when you've committed a virtual crime in a constructor or destructor. Another good way is never inheriting concrete classes but in existing code bases you've often not got that choice (and if you're using something like MFC you're well stuck).
Cheers,
Ash
|
|
|
|
|
The indicated method is a good one.
However, it's not "illegal" or "invalid" to call a virtual method in a ctor so long as you are aware of what you're doing and that's what you intend. You just need to remember what it will actually call in that instance.
"If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams
|
|
|
|
|
Looks like a malposed attempt to resolve a malposed problem (so it is a good question!).
Actually calling a vistual function from a constructor is LEGAL. It is not something the dumb compiler allows even if shouldn't.
The problem is that C++ is a "complex language" and that what such a call will do may be not what dumb programmers suppose it to do.
But whoever has a minimum of logic should understand that -during the execution of a base constructor- the derived component is not yet come into existence, and hence the base v-table cannot contain references to it. The virtual function at that point is not yet been overridden.
Now trying to find a way to "fix the language" to disallow this is like trying to make C++ to turn into something else. It is not something related to your implementation. Every C++ programmer MUST KNOW what happens if a constructor / destructor calls a virtual function. Ther is nothing to fix, here.
Unless you don't like how C++ works. But -at that point- just use another language.
Afer all, if you do
#define begin {
#define end }
you'd better to use Pascal/Delphi/Ada, and not C/C++/C#/Java/D ...
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
Oh, I am aware that it is legal and the C++ behavior makes sense but I unfortunately tripped over it anyway. I wasn't criticizing the language as I still consider C++ my language of choice. I was merely looking for an approach to initialization that would protect me from inadvertantly calling some virtual function from a constructor as it is so tempting with some class hierarchies. The effect of doing so blindly had subtle effects that had me chasing my tail for a bit, quite embarrassing but a reality with so many rules to remember.
Looking for a pattern to use that will allow me to initialize the base and derived class objects, with any function (virtual or not) which requires avoiding calling methods from the constructor directly except for simple member initialization lists and such.
I'm definitely not trying to fix the language.
thanks for the comments.
|
|
|
|
|
Hi everybody,
I have some problems reading the COM ports. In particular I have used WaitForMultipleObjects and ReadFile, that permit me
listen the COM port selected.
I use this code for reading the COM port while I was trasfering a file with Bluetooth from the phone to the computer.
I can open the right COM port (they are 4, one for the input, one for the output and two for some remote control, i think)
but in any of them I can see nothing in the buffer, because everytime the ::WaitForMultipleObjects switch
in the default case, exiting from the cycle.
My question is:
Is this the correct way to read the bluetooth packets arriving in the COM ports?
If, yes, why during the data transfert is like if no package where transfering in the port?
I have used also CSerial class present in this site with the same result.
Thank,
Anne
//[...]
HANDLE hevtOverlapped = ::CreateEvent(0,TRUE,FALSE,0);;
if (hevtOverlapped == 0)
{
cout << "Unable to create manual-reset event for overlapped I/O.\n";
return -1;
}
// Setup the overlapped structure
OVERLAPPED ov = {0};
ov.hEvent = hevtOverlapped;
// Open the "STOP" handle
string name1 = "Overlapped_Stop_Event";
HANDLE hevtStop = ::CreateEvent(0,TRUE,FALSE, name1.c_str());
// Keep reading data, until an EOF (CTRL-Z) has been received
bool fContinue = true;
do
{
// Wait for an event
lLastError = serial.WaitEvent(&ov);
if (lLastError != ERROR_SUCCESS)
{
cout << "Unable to wait for a COM-port event.\n";
return -1;
}
// Setup array of handles in which we are interested
HANDLE ahWait[2];
ahWait[0] = hevtOverlapped;
ahWait[1] = hevtStop;
// Wait until something happens
switch (::WaitForMultipleObjects(sizeof(ahWait)/sizeof(*ahWait),ahWait,FALSE,500))
{
case WAIT_OBJECT_0:
{
// Read data from the COM-port (ReadFile)
[...]
}
break;
case WAIT_OBJECT_0+1:
{
// Set the continue bit to false, so we'll exit
fContinue = false;
}
break;
default:
{
// Something went wrong
// exit
[...]
}
break;
}
}
while (fContinue);
//[...]
|
|
|
|
|
You should check better the WaitForMultipleObjects return value and, if it is WAIT_FAILED then call GetLastError , as stated in the documentation[^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Firstly, please put all your code in <pre></pre> tags, or select it and click the code block button above the message content text box. This will make it easier for everyone to read.
0.5s isn't a very long time to wait for something like bluetooth, try waiting for longer.
Make sure the hevtStop isn't set
Add cases to the WaitForMultipleObjects switch for WAIT_FAILED and WAIT_TIMEOUT , in WAIT_FAILED add a call to GetLastError() , if it is hit, find the error code in the System Error Codes[^] page on MSDN
If you are using ReadFile, I wouldn't bother with overlapped operations at this stage. Either get it working then put them in, or put this code into a different thread
|
|
|
|
|
Hi!
Thank you for the replay.
- I set 4000 instead 500 with the same result (I also set INFINITE, and the program is blocked in waiting)
- I haven't done any other operation with hevtStop, it shouldn't be set
- I add WAIT_TIMEOUT and WAIT_FAILED, and it enter in WAIT_TIMEOUT, after 4 seconds.
I use ReadFile, but I use it inside WAIT_OBJECT_0, where it doesn't enter.
Sorry for the tags, in future i'll use 
|
|
|
|
|
Well that really only leaves serial.WaitEvent(&ov) . How and where is the event set?
Have you tried opening the COM port in something like HyperTerminal or PuTTY?
|
|
|
|
|
I use the class CSerial (founded in this site) and serial is an object of the class.
serial.WaitEvent(&ov) is this:
<pre>
LONG CSerial::WaitEvent (LPOVERLAPPED lpOverlapped, DWORD dwTimeout)
{
// Check if time-outs are supported
CheckRequirements(lpOverlapped,dwTimeout);
// Reset error state
m_lLastError = ERROR_SUCCESS;
// Check if the device is open
if (m_hFile == 0)
{
// Set the internal error code
m_lLastError = ERROR_INVALID_HANDLE;
// Issue an error and quit
_RPTF0(_CRT_WARN,"CSerial::WaitEvent - Device is not opened\n");
return m_lLastError;
}
</pre>
I haven't used HyperTerminal and Putty, but I think is a good idea for seeing the effective data tranfer (if I undestand correctly the usage)
Anne
|
|
|
|
|
Your code looks pretty much the same as the sample code, so all I can suggest for now is that you open the COM port in PuTTY or HyperTerminal and make sure that you have the right settings for the connection
|
|
|
|
|