|
And that made me update my little tip article here[^].
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Yes right, I should have said "code block", I was typing too fast
|
|
|
|
|
Mixing wcstok calls for different strings does not work. See the Note here[^]. You need to use wcstok_s to work round this limitation.
Note: Please use <pre></pre> tags round your code rather than <code></code> - the "code block" button does it for you.
I must get a clever new signature for 2011.
|
|
|
|
|
pre tags for some reason made code red. But.
Thanks for the info and link, it helped.
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|
|
csrss wrote: pre tags for some reason made code red.
Strange, I've not seen that before; drunken hamsters maybe.
I must get a clever new signature for 2011.
|
|
|
|
|
Ok, replying to my own thread, like Richard MacCutchan pointed out, in such case wcstok cannot be used. Here is working example.
#include <windows.h>
#include <stdio.h>
#define malloc(s) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, s)
#define free(m) HeapFree(GetProcessHeap(), 0, m)
#pragma warning(disable: 4996)
wchar_t *test()
{
wchar_t aaa[] = L"aaaa,bbbb,cccc,dddd";
static wchar_t *lol = (wchar_t *)malloc(sizeof(wchar_t *) * wcslen(aaa) + 1);
wcscpy(lol, aaa);
return lol;
}
wchar_t *lolz(wchar_t *lol)
{
int i = 2;
static wchar_t *stuff = (wchar_t *)malloc(sizeof(wchar_t *) * (wcslen(lol) + MAX_PATH)*i);
wcscpy(stuff, L" ");
while(i > 0)
{
wcscat(stuff, lol);
wcscat(stuff, L",");
i--;
}
return stuff;
}
int main(int argc, char **argv)
{
wchar_t *t, *nexttok;
int i;
wchar_t *stuff = test();
t = wcstok_s(stuff, L",", &nexttok);
for(i = 0; t; t = wcstok_s(NULL, L",", &nexttok), i++)
{
wprintf(L"::%s\n", t);
wchar_t *get = lolz(t);
wchar_t *t2, *nexttok2;
int i2;
t2 = wcstok_s(get, L",", &nexttok2);
for(i2 = 0; t2; t2 = wcstok_s(NULL, L",", &nexttok2), i2++)
{
wprintf(L":%s\n", t2);
}
wprintf(L"End for: %s [%d]\n\n", t, i);
}
return 0;
}
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|
|
Hi all.
I am reading some value from registry within a COM module.
The code runs fine in Windows XP and in Windows 7 locally but
in remote I am not able to read the value from the XP.
I am using CRegistry class to access the registry.
|
|
|
|
|
Debojyoti Majumder wrote: in remote I am not able to read the value from the XP.
Make sure that the Remote XP machine doesn't disabled the Remote Registry service
locally via the Windows Services MMC.
|
|
|
|
|
Hi All,
I have created 32 threads , out of these 20 threads are having infinite loop using while (1) {}. Remaining threads are also having infinite loop using while (1) {} but with some print statement. I have observed (With thirdparty utility) that threads WITHOUT print statement takes more time to context switch. Its almost few mins for me to get nothing on console because threads without printf were executed. After some time threads with printf statement executed in a shorter duration as my main () exited after a ::Sleep (300000). Why those threads without printf statement take much time to execute. Can any one have any idea...
Thanks
|
|
|
|
|
Although functionally a while(1){} loop could be described as doing nothing, the processor interprets it as a jump instruction. This effectively keeps the processor busy.
The printf statement relies on other resources (such as memory on your graphic card) which are slower, so when waiting for this, the processor isn't kept busy and can be assigned to some other thread by the OS.
modified 13-Sep-18 21:01pm.
|
|
|
|
|
I concur with Thaddeus.
On a simple processor, a single such loop would raise CPU load to 100% and achieve nothing. On a more complex processor, it would take a few of them to get at or close to 100%, the net result would still be nihil.
Now why would you have a single busy loop like your empty while loop? And why would you have many of those? It makes little or no sense to me; it is like a company hiring personnel to sit at a desk and do nothing.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
pandit84 wrote:
Why those threads without printf statement take much time to execute.
I don't know what OS you are using but I will give you a Windows NT kernel answer. Its because the kernel scheduler is waiting for the threads to become eligible for a context switch. When the threads performing printf have completed I/O they become immediately eligible for a context switch. The threads in a busy loop consume more time because the process scheduler is waiting for what it considers *work* do be done. However since they are inside infinite do-nothing loop they will comsume an entire time slice.
What OS did you test this on? The process scheduler has evolved alot and on Microsoft Vista and above and I believe the threads performing I/O will recieve priority boost.
Best Wishes,
-David an eluDe
|
|
|
|
|
Hi,
I am trying to download a zip file from server using CInternetSession. But i am getting incorrect size from server.
My application is unicode and code as below:
pConnection = session.GetHttpConnection((LPCTSTR)strServerName, (INTERNET_PORT)nPort);
LPCTSTR pstrAcceptTypes = NULL;
LPCTSTR pstrVersion = NULL;
pHttpFile = pConnection->OpenRequest(CHttpConnection::HTTP_VERB_GET, strObject, NULL, 1, &pstrAcceptTypes, pstrVersion, HttpRequestFlags);
pHttpFile->AddRequestHeaders(szHeaders);
pHttpFile->AddRequestHeaders(_T("User-Agent: GetWebFile/1.0\r\n"), HTTP_ADDREQ_FLAG_ADD_IF_NEW);
pHttpFile->SendRequest();
pHttpFile->QueryInfoStatusCode(dwRet);
int nFileLen = pFile->GetLength();
why I am getting incorrect size? Anything wrong in this code?
Same code was working with ANSI build and not working with unicode build.
modified on Thursday, January 13, 2011 5:43 AM
|
|
|
|
|
|
john5632 wrote:
int nFileLen = pFile->GetLength();
where is pFile defined and initialised? It does not appear in this code snippet.
I must get a clever new signature for 2011.
|
|
|
|
|
sorry this is
pHttpFile->GetLength();
|
|
|
|
|
Sorry, no idea, but maybe you should be looking at the information returned from your server.
[edit]Google found this[^], it may help.[/edit]
I must get a clever new signature for 2011.
|
|
|
|
|
Previously code was in ANSI and working fine but now I converted it to UNICODE and getting this issue.
Any problem with API to transdfr the string to server into UNOCODE format?
|
|
|
|
|
john5632 wrote: Any problem with API to transdfr the string to server into UNOCIDE format?
Assuming both ends are working in Unicode there should be no problems. You need to check both ends are following the same rules.
I must get a clever new signature for 2011.
|
|
|
|
|
Is the incorrect size comes in debug version? Please run in release mode and analyze nFileLen by means of messagebox or some thing else.
|
|
|
|
|
i wanted to create dynamically popupmenu on clicking rightclick... the item may very more than thousands worst case otherwise hundreds only. Is it possible?
|
|
|
|
|
yogish293 wrote: s it possible?
Did you try?
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]
|
|
|
|
|
For how long are you going to repost the same question ? You already got a lot of answers suggesting that it was a very bad design. Why don't you look at it from the user point of view and see if you can't use a more user-friendly approach ?
|
|
|
|
|
How much more information do you need on this? You have already been shown:
- This is not a good design, and you should consider alternatives.
- If you insist on doing it this way then you probably need to use a virtual menu - i.e. owner drawn.
I must get a clever new signature for 2011.
|
|
|
|
|
In that case instead of using regular menu , create a WS_POPUP style window, and handle the drawing and messages for performance improvement.
If u can Dream... U can do it
|
|
|
|