|
If you're using ATL/MFC COleDateTime then have a look at Format method.
If you're instead using Win32 then read about strftime function.
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]
|
|
|
|
|
if there are many if's in the replies, maybe you should provide more information to start with.
|
|
|
|
|
overloaded Name wrote: ...thus need to convert it to string, how can I do that??
In addition to the others, there's also asctime() and ctime() .
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
in mfc use COleDateTime class and after that Format method
in win 32 use sprintf function
|
|
|
|
|
Hi All
I need to block or show message when application run as Administrator.Is it possible?
Please help me
|
|
|
|
|
Already tried[^] ?
virtual void BeHappy() = 0;
|
|
|
|
|
Thanks for reply
No i just going through this let you know.
|
|
|
|
|
Hey i use code which is given in MSDN.I use like this
bool CCheckApp::IsUserAdmin(void)
{
BOOL b;
SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
PSID AdministratorsGroup;
b = AllocateAndInitializeSid(
&NtAuthority,
2,
SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_ADMINS,
0, 0, 0, 0, 0, 0,
&AdministratorsGroup);
if(b)
{
if (!CheckTokenMembership( NULL, AdministratorsGroup, &b))
{
AfxMessageBox("Test");
b = FALSE;
}
FreeSid(AdministratorsGroup);
}
return(b);
}
And call in
BOOL CCheckApp::InitInstance()
{
...
..
..
IsUserAdmin();
}
i am wrong or right.Please help me
|
|
|
|
|
Why not ?
You could modify the last line:
return (FALSE != b);
virtual void BeHappy() = 0;
|
|
|
|
|
|
Try it also in the admin mode at the switched-on UAC
virtual void BeHappy() = 0;
|
|
|
|
|
Hi all,
i m using COleDateTime Ctrl to find out dates.
i want to find out 2nd sat of month,
please tell me how can i do this.
thanks in advance.
|
|
|
|
|
0. Set a COleDataTimeSpan object (day) to a day
1. Set a COleDataTime object (date) to the desired month of the desired year
2. Build a loop of the incrementation (date += day)
while (1(sat) != date.GetDayOfWeek()) for two times
3. Now you (date) are at the second sat
virtual void BeHappy() = 0;
|
|
|
|
|
Saturday is 7 .
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]
|
|
|
|
|
OK
virtual void BeHappy() = 0;
|
|
|
|
|
COleDateTime dt(year,month,1,0,0,0);
int add = 14 - dt.GetDayOfWeek();
dt += add;
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]
|
|
|
|
|
I have a class that acts something like the following:
class Foo {
private:
int const (&InitPrimes() const)[3] {
int (*const rval)[3] = new int[1][3];
(*rval)[0] = 2;
(*rval)[1] = 3;
(*rval)[2] = 5;
return *rval;
}
public:
int const (&primes)[3];
explicit Foo() : primes(InitPrimes()) { }
virtual ~Foo() { delete[] ℙ }
}; If I have the following code in a main function, all three of the cout statements print the same value:
Foo a;
cout << a.primes << endl;
cout << &a.primes[0] << endl;
cout << &a.primes << endl; How is this possible? It seems logical that "a.primes" == "&a.primes[0]", but shouldn't "&a.primes" be a distinct value? If they are the same, then shouldn't the following contradiction be true (assume all three return value 0xF0):
Address 0xF0 (&a.primes ) is of type "(int*)[3]" and holds the value 0xF0, the location of a.primes
Address 0xF0 ( a.primes ) is of type " int [3]" and holds the value 0xF0, the address of the first element in the array
Address 0xF0 ( a.primes[0]) is of type " int " and holds the value 2, the first prime number Clearly I am misinterpreting which of these assumptions is false, because I know that address 0xF0 can't be 0xF0 and 2 at the same time (let's not get into a discussion on simultaneity with respect to relativity). If I type
*((int*)0xF0) into the immediate window (VS 2008), it returns 2, but then why is &a.primes == 0xF0? Any clarification on why the above is happening would be greatly appreciated. Thanks,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
IIRC, the original C idea (almost 40 years ago) was that the "value" of an array symbol was its base address. In other words, array == &array == &(array[0]) . This dates from the days when a pointer was a pointer (to anything), and void was not yet a keyword. Somewhere in a standard or pseudo-standard that I can't find right now, there is a statement to the effect that the address-of operator (&) is optional when referring to an array. I remember some fairly energetic debate when I was working on a very early non-PDP11 implementation of Unix and C.
[OT, sort of] I think this is sufficiently removed from the present message in the time dimension for considerations of simultaneity to be of probability zero. ]
Cheers from an old-timer,
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
Your problem is that you say that &a.primes is of type (int *)[3] . (Actually I think you mean int (*)[3] - a pointer to an array of three ints, not an array to three pointers to int, but that's another story) It's not - it's type is int * const .
The name of an array is an alias for the address of the first element in that array. This means that:
T t[ N ];
t == &t[ 0 ];
for all T and N.
Likewise the address of an array is an alias for the first element in that array. Again this means that:
T t[ N ];
&t == &t[ 0 ];
for all T and N.
it also means that the type of &t is T * const , not (T *)[3]; as you asserted in your post.
So t , &t and &t[ 0 ] are synonyms for the same thing and *t, *&t and t[ 0 ] all refer to the same location in memory.
Cheers,
Ash
|
|
|
|
|
Alright, I think that I understand what you are saying (although I'm still confused as to why the designers of C decided to do this). The point of my post was to ensure that class Foo is correctly deallocating the member primes in it's destructor. If I understand you correctly, then all of the following should be equivalent statements, all of which result in no memory leaks:
virtual ~Foo() {
delete[] primes;
delete[] ℙ
delete[] &primes[0];
} Is it true that all of these correctly deallocate primes in the example? Thanks,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
The best way of avoiding delete stress like this is to not bother with fiddling about with multi-dimensional arrays. Use a vector or vector of vectors and you don't have to worry about declaring it properly, sizing it or freeing it. The class does all that for you with very little overhead (bit of space, maybe some run-time cost if your optimiser isn't up to much).
Or another way is to handle the multidimensional bit yourself over a one dimensional array but that's a bit fiddlier and not the sort of thing you want to think about unless you're writing a collection class.
Cheers,
Ash
PS: All those will delete primes - just be careful of what they're pointing to. Arrays of pointers are a good way of going gaga and there's usually a better way of doing them.
PPS: The designers of C designed pointers and arrays to be very close to the hardware - which is why they're a bugger to use properly. Fortunately in C++ you don't need to use them that much, there's almost always a better alternative.
|
|
|
|
|
So, I'm fairly familiar with socket programming, but I have never before tried to send HTTP arguments to a web page before using WinSock.
I'm trying to duplicate the data in the following URL:
http://www.thewebsite.com/sub/database?action=authenticate&username=test&password=test
First, I am opening a socket to www.thewebsite.com on port 80. Then, I am sending the following:
<br />
std::string message = "POST /sub/database?action=authenticate&username=test&password=test";<br />
send(m_hConnection, message.c_str(), message.length(), 0);<br />
The problem is, I don't receive a response making me assume the format is incorrect since pasting the URL in a browser does return a response. Now, I'm kind of just guessing on the format to send the data in as I can't seem to find a good description online that doesn't involve a 3rd party library.
I have the following code in another thread in attempt to receive this data:
<br />
char recvbuf[MAX_BUFFER_LENGTH]; <br />
int result = recv(m_hConnection, recvbuf, MAX_BUFFER_LENGTH, 0)<br />
Any help is greatly appreciated.
Dustin
|
|
|
|
|
Found 2 of my problems.
First, it appears there is a problem receiving on the socket from a different thread that the one that created it. Can anyone confirm this and give me a possible solution?
Second, I added "HTTP/1.0\n" after POST in my message, I receive a response on a recv line directly after the send (not in the threaded method), but now I'm getting a response of:
HTTP/1.1 400 Bad Request
Content-Type: text/html
Date: Mon, 13 Sep 2010 21:35:24 GMT
Connection: close
Content-Length: 34
<h1>Bad Request (Invalid URL)</h1>
Any ideas?
|
|
|
|
|
Dustin Henry wrote: Any ideas?
Looks like a violation of the HTTP RFC, when client sends a HTTP 1.0 request the server must not answer with a HTTP 1.1 response as in your example. Well, try to send a HTTP 1.1 request as shown in my post below (including a Host header line), perhaps the server understand only HTTP 1.1. What kind of web server software are you using?
/M
|
|
|
|
|
Correct HTTP protocol[^] requires sending more than just the request line. If the service responds to pasting the URL to a browser, you must use the GET method instead of POST. The form data[^] is appended to the URL as name=value pairs separated by "& " characters.
|
|
|
|