|
I am loving this conversation, you're certainly a lot more knowledgeable in C++ than I am.
I am not against smart pointers, as I said I don't know them very well it might well be than one of them or a combination of them covers perfectly what I fuzzily thinking.
I am taking your comments into consideration and either give up or come with a new proposition.
I don't really want to fight against anyone on this, the idea is to accept some arbitrary and perhaps unorthodox concepts and see if it rolls.
Hopefully it is yes. If not we can change our arbitrary and perhaps unorthodox concepts and see if it works.
You're right the hypothesis I posted are too wild, I'll try to write something with less scope and see where it goes.
|
|
|
|
|
Well I don't 'fight' you, I just want to point out the problems. Consider this:
1. Dealing with pointers by yourself is tricky. But most people learn it soon enough.
2. Writing a class to automate this requires you to not only think of your code, but also the code of other users who will use that class. That is quite hard. Especially when you think of users who fail at 1.
3. Writing such a class to deal with multi-threading issues is mind-boggling!
It's not that I judge your abilities as poor, just that you might have set your goals too high. Me, I've tried myself at level 2, and although I thought I did it reasonably well, I know it wasn't quite perfect. I might be willing to experiment with sth at the level of 3, but I don't think I'd offer to write an article about it until after I know it works ...
On a sidenote, I did write an Object Pool implementation that hands out special smart pointers to make sure all pool items are released as soon as possible. In fact, the concept of releasing pool items ASAP runs a bit contrary to the idea of a pool, so in truth it's closer to a specialized garbage collector with 'immediate response'. That is about as close to garbage collection I dare go. And I only did it because I realized I could implement each function at a complexity of amortised O(1). Maybe I should put that up as an article, but I first have to fix memory alignment and then think up a new name...
|
|
|
|
|
Hello,
I have a problem ,
Whan I open a port by CreateFile(..) after closing it by
CloseHandle(..)
the CreateFile fails , I tried to do a Sleep(2000) before reopening
its didnt help,
on the first time that I am opening it, its succeed
it fails just if I open it after closing it.
And its happend only in my laptop that have windows 7, on the other computer that have windows XP its work fine.
What can be the problem with reopening port after closing it?
Thanks!!
|
|
|
|
|
What does GetLastError return after the second CreateFile call?
modified 13-Sep-18 21:01pm.
|
|
|
|
|
its return ERROR_ACCESS_DENIED
|
|
|
|
|
This[^] appears to be the same problem, you could try if that works.
modified 13-Sep-18 21:01pm.
|
|
|
|
|
Thank you its solved my problem
|
|
|
|
|
Typical. MS realley messed up with Vista. It seems a lot of the bugs are still there in Win7.
This is typical, how the hell does CloeHandle() succeed withouth flushing the data and leaving the port in a state ready to accept a new CreaeFile()?
I have written many many drivers for windows, serial drivers, network drivers, and never has one of my serial drivers behaved like this on Visa and Win7.
==============================
Nothing to say.
|
|
|
|
|
I found this in my 2001 MSDN
CloseHandle invalidates the specified object handle, decrements the object’s handle count, and performs object retention checks. After the last handle to an object is closed, the object is removed from the system.
<b>Persistent objects such as databases and files will remain in storage, but must be re-opened to be accessed again.</b>
Closing a thread handle does not terminate the associated thread. To remove a thread object, you must terminate the thread, then close all handles to the thread.
Use CloseHandle to close handles returned by calls to the CreateFile function. Use FindClose to close handles returned by calls to the FindFirstFile function.
I am not sure if newer OS , I run XP, should behave any differently if this is ( <b>bold stuff re-opened </b>) realy true.
|
|
|
|
|
XP set a kind of benchmark, thats why it lasted so long, and later OSs should of course maintain backwards compatability. Clearly they dont in this case, which IMO makes it a bug.
==============================
Nothing to say.
|
|
|
|
|
I want to hide a folder which exist in c drive. I use setfileattribute method and pass file_attribute_hidden.
But if c drive is open in window explorer then folder does not hide immediately
i need to refresh window explorer manually
please suggest how to do that
i got below link and function to do it but that code does not compile
http://social.msdn.microsoft.com/Forums/en/windowssdk/thread/cc4a702f-1b2f-4d19-bf68-c88967544172[^]
RefreshFolderSelectionPacket and RefreshSelection()
|
|
|
|
|
Your link needs to be made clickable by using the link control on the edit window thus:
clickety[^].
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Thanks for the link
The given link says to use RefreshFolderSelectionPacket
I get compile error when use this
WHere this structure is defined
|
|
|
|
|
MKC002 wrote: WHere this structure is defined
Sorry, no idea; the link is the one that you provided in your original post.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
I thought I got this right, but it's my first time converting numbers to letters, in a message I'm building to send to a text hwnd.
dBytes = ((float)ulProgress / (1024*1024));
dTotal = ((float)ulProgressMax / (1024*1024));
if ((dBytes > 0.10) && (dTotal > 0.10)) {
WCHAR str0[120];
WCHAR str1[120];
str0[0] = L'\0';
str1[0] = L'\0';
wprintf(str0, L"%.2f", dBytes);
wprintf(str1, L"%.2f", dTotal);
|
|
|
|
|
jkirkerx wrote: str0[0] = L'\0';
str1[0] = L'\0';
Unnecessary.
"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
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
jkirkerx wrote:
wprintf(str0, L"%.2f", dBytes);
wprintf(str1, L"%.2f", dTotal);
|
Don't you mean wsprintf ?
There are probably close to aleph-null ways to do it.
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
The wsprintf just gave me a f
I tried a char and sprintf, and the values I need came back. I'm new to this, so I thought I could go straight to unicode.
char szTemp0[20];
char szTemp1[20];
sprintf(szTemp0, "%.2f", dBytes);
sprintf(szTemp1, "%.2f", dTotal);
|
|
|
|
|
jkirkerx wrote: The wsprintf just gave me a f
In your original post, you used wprintf() not wsprintf() . They output to two different places.
Have you considered:
TCHAR szTemp0[20];
TCHAR szTemp1[20];
_stprintf(szTemp0, _T("%.2f"), dBytes);
_stprintf(szTemp1, _T("%.2f"), dTotal); This will handle both Unicode and MBCS.
"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
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
modified 15-Nov-11 15:07pm.
|
|
|
|
|
No.
But I did consider that perhaps I should always use TCHAR when working with Windows stuff like writing registry keys, and sending setting window text.
I change my code to this, and I'm still working with WCHAR on szStatusMessage. The code is inside the IBindStatusCallback in the OnProgress Loop in case your wondering. For me this is uncharted waters, and I sort had to guess at how to work with it.
dBytes = ((float)ulProgress / (1024*1024));
dTotal = ((float)ulProgressMax / (1024*1024));
dPercent = dBytes/dTotal*100;
if ((dBytes > 0.10) && (dTotal > 0.10)) {
swprintf_s(szStatusMessage, L"Downloading %.2f MB of %.2f MB [%.1f%%]", dBytes, dTotal, dPercent);
iMsgLen = wcslen(szStatusMessage);
szStatusMessage[iMsgLen] = '\0';
}
|
|
|
|
|
jkirkerx wrote: szStatusMessage[iMsgLen] = '\0';
Unnecessary.
"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
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
I took it out, and put it back in.
I wasn't sure how to handle the callback loop, and didn't want to create what I call variables in the loop. So I created the szStatusMessage in the private section of the class. When the loop goes round, some of the messages are longer than others, and the old message doesn't clear when the new message is written to the space, so I put the \0 back in just to get rid of the old message, so the cat writes the entire space. I could experiment with moving it back into the loop, and see what changes I need to make.
|
|
|
|
|
You are misusing swprintf_s() . The second argument is the maximum number of characters to store in the buffer. Correctly used, swprintf_s() will terminate the buffer where necessary.
Try:
swprintf_s(szStatusMessage, sizeof(szStatusMessage), L"Downloading %.2f MB of %.2f MB [%.1f%%]", dBytes, dTotal, dPercent);
|
|
|
|
|
Let me look into the proper use, I know there was a ms version wsprintf_s and a ansi version swprintf_s. I moved the variables inside the loop, works ok, but I get squares in the message because I haven't populated it yet.
I guess I should of shown more code, the other half of the if statement, that shows the status message from the callback. I may kill the idea of that message, I don't see anything relevant to it.
if ((dBytes > 0.10) && (dTotal > 0.10)) {
swprintf_s(szStatusMessage, L"Downloading %.2f MB of %.2f MB [%.1f%%]", dBytes, dTotal, dPercent);
iMsgLen = wcslen(szStatusMessage);
szStatusMessage[iMsgLen] = '\0';
}
else {
if (wszStatusText != NULL) {
int iStatusLen = wcslen(wszStatusText);
if (iStatusLen < 80) {
iMsgLen = wcslen(szStatusMessage);
wcsncpy_s(szStatusMessage, wszStatusText, iStatusLen);
szStatusMessage[iStatusLen] = '\0';
}
}
}
SetWindowText(hWnd_Progress_Text, szStatusMessage);
dPB = (float)ulProgress/ulProgressMax*5000.0;
SendMessage(hWnd_Progress_Bar, PBM_SETRANGE, 0, MAKELPARAM(0, 5000));
SendMessage(hWnd_Progress_Bar, PBM_SETPOS, (WPARAM)dPB, 0);
|
|
|
|
|
Thanks for the heads up on the swprintf_s. I appreciate the attention to detail and efficiency you gave me today. tough learn today, but it works well.
Changed it to this now.
case BINDSTATUS_DOWNLOADINGDATA:
dBytes = ((float)ulProgress / (1024*1024));
dTotal = ((float)ulProgressMax / (1024*1024));
dPercent = dBytes/dTotal*100;
if ((dBytes > 0.10) && (dTotal > 0.10)) {
swprintf_s(szStatusMessage, 80, L"Downloading %.2f MB of %.2f MB [%.1f%%]", dBytes, dTotal, dPercent);
iMsgLen = wcslen(szStatusMessage);
szStatusMessage[iMsgLen] = '\0';
}
break;
|
|
|
|
|