|
|
I think the producer consumer example is the way to go, but maybe a version of that using asynchronous workers would help the most. What I have in mind would limit the threaded complexity to a minimum while still achieving very good performance.
If you are using Qt then my answer would be slightly different but in short I would do like this
Assuming I understood you correct and you do not have access
to c++11 or concurrency library features like future or asynch run ., I am also assuming that it is OK that the zip files are unzipped in a non-deterministic order.
1. A thread, maybe the main thread, tells a worker to start downloading one or several zip files.
2. As soon as a zip file is downloaded it is handed over to another worker that is unzipping the file at the wanted location
3. When a zip file is downloaded and unzipped then this is communicated back to the original calling thread
4. Communication between "participants" is done solely through message queues. No shared memory except the queue, that way data sharing and thread synchronization issues are minimal.
5. The "design pattern" I have in mind for this is the active object. There is plenty of material if you google for it. My favourite is Herb Sutters take on it.
I wrote my version of active object, which should be easy to use, maybe after making minimal change to use whatever thread library you use.
Another example., although more of the fire and forget nature than your scenario., is the asynchronous logger g2log
that I recently wrote about. Check in the code how the messages are passed from the g2logworker to it's thread internal and you will see how easy it is
modified 7-Dec-11 2:55am.
|
|
|
|
|
Sounds like you need a client/server approach. Since a majority of your time is spent downloading, and only for the sake of opening the file, leave the file on the server and simply send the server a request to unzip the file and extract the necessary information from it.
"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
|
|
|
|
|
hi all,
please help to convert from 'LPCTSTR' to 'const char *'
thanks.
|
|
|
|
|
Your question is a bit vague.
The short answer would be: "LPCTSTR tstr = (LPCTSTR)constCharPtr";
The long answer is most likely this: If your project setting is "MBCS" or "not set", then LPCTSTR should be "const char *" already, if your project setting is "unicode", then try using MultiByteToWideChar[^] to convert your string to a widechar string.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
If you look at the definition of LPCTSTR in your program you may find that is already defined as const char * ; that would give you a clue as to what you need to do next.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
|
Hello,
Case-1
SendMessage((*m_pIPedt).GetHWnd(), WM_SETFOCUS, NULL, NULL);
Result-1
Edit control is getting focus. But it is not accepting any text. Hanging sometimes.
Case-2
SetFocus((*m_pIPedt).GetHWnd());
Result-2
Edit box is getting focus and I am able to type text in edit control
I want to know difference between these 2 cases.
Please help me.
Regards
msr
|
|
|
|
|
The WM_SETFOCUS message is sent to a window by the Windows system, as the result of a call to SetFocus() or the user setting the focus to the window by mouse or keyboard. Thus option 2 is the correct way to do it.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
|
i am reading excel file .
Excel::_ApplicationPtr pApplication;
pApplication.CreateInstance( _T("Excel.Application") );
but i dont understand why pApplication.CreateInstance( _T("Excel.Application") ) failed on my PC while its working fine on another PC.
please help me for this.
thanks.
|
|
|
|
|
Le@rner wrote: but i dont understand why pApplication.CreateInstance( _T("Excel.Application") ) failed
Because you didn't bother to check the return value.
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]
|
|
|
|
|
no chk this
if ( FAILED( pApplication.CreateInstance( _T("Excel.Application") ) ) )
{
AfxMessage( _T("Failed to initialize Excel!") );
return ;
}
|
|
|
|
|
It is no use printing a message such as the above when something fails, as it provides no useful information. You need to capture the system error code from GetLastError() and print its details to find out why your program fails. I am assuming that you have all the necessary libraries installed on your PC in the first place.
Oops: sorry you need to interpret your HRESULT as CPallini suggests.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
I believe that's the optimal way with standard API (like Win32 ). On the other hand, COM calls provides error code in return value.
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]
|
|
|
|
|
You are, of course, correct; it was my bad (mea culpa) and I have fixed it.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
That way, you are discarding a precious info, the HRESULT return value.
HRESULT hr;
hr = pApplication.CreateInstance( _T("Excel.Application");
if ( FAILED(hr))
{
return;
}
is far better.
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]
|
|
|
|
|
HRESULT hr;
hr = pApplication.CreateInstance( _T("Excel.Application");
if ( FAILED(hr))
{
"An attempt was made to reference a token that does not exist" error comes when i format the message of GetLastError().
return;
}
modified 17-Jan-12 7:33am.
|
|
|
|
|
I don't know about, however it looks like Excel doesn't allow your application to access it (I guessed that from this page[^]: they face the same error message, see the "Configure Excel application to be accessed by non-System account" section. You may try to run your application 'As Administrator ' to validate such hypothesys.
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]
|
|
|
|
|
Hi.
I am facing exactly same problem and posted in the query in below link.
https://www.codeproject.com/Answers/5165616/Excel-applicationptr-createinstance-is-failing#answer1
Can any one explain how to resolve this CreateInstance() failure.
Windows 10 - 64 bit and Office 365 64bit and VS2017 enterprise edition i am using.
|
|
|
|
|
This is my first textbox using CreateWindow "edit", and I want to make sure the box is not empty.
So I sent the message, and the buffer comes back 0x0000, for the first wchar.
Is there a common method that folks use in c++ to check the contents of the box before performing any actions?
I wrote this, simple, but not good enough
LRESULT iTextSize = SendMessage(txt_SQL_DatabaseCreate_DB_Field, EM_GETLIMITTEXT, 0, 0);
WCHAR *szDatabaseName = new WCHAR[iTextSize];
SendMessage(txt_SQL_DatabaseCreate_DB_Field, WM_GETTEXT, iTextSize, (LPARAM)szDatabaseName);
if ((szDatabaseName[0] != 0x0000) && wcslen(szDatabaseName) >0)) {
|
|
|
|
|
jkirkerx wrote: LRESULT iTextSize = SendMessage(txt_SQL_DatabaseCreate_DB_Field, EM_GETLIMITTEXT, 0, 0);
You should probably be using WM_GETTEXTLENGTH instead.
"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
|
|
|
|
|
That was a good idea, I changed my code to that, it was more accurate.
|
|
|
|
|
I just use the GetWindowTextLength and GetWindowText functions, something like this:
case IDC_BTN_TEST:
editWnd = GetDlgItem(hwndDlg, IDC_EDIT1);
stringLength = GetWindowTextLength(editWnd);
if (stringLength != 0)
{
strBuffer = new WCHAR[stringLength+2];
GetWindowText(editWnd, strBuffer, stringLength+1);
MessageBox(hwndDlg, strBuffer, L"title", MB_OK);
delete strBuffer;
}
return TRUE;
For some reason, calling GetWindowText with stringLength (as opposed to stringLength+1) returns the string minus the last character... 
|
|
|
|
|
enhzflep wrote: For some reason, calling GetWindowText with stringLength (as opposed to stringLength+1) returns the string minus the last character...
That is of course because 'C' strings are terminated with a NULL character. The GetWindowTextLength function sends the WM_GETTEXTLENGTH message[^] and therefore is returning only the length of the text excluding the NULL character. When allocating space for C-style strings you should always calculate the bytes required as:
((number of characters) * sizeof(TCHAR)) + sizeof(TCHAR)
Feel free to replace TCHAR with char or wchar_t dependent on your compiler/platform and ANSI/Unicode build.
Best Wishes,
-David Delaune
|
|
|
|