|
CDRAIN wrote: Yes, the progress bar belong to the MainThread of my Application, and I need to manage it from my thread.
Which is a sure-fire recipe for disaster.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
CDRAIN wrote: the progress bar belong to the MainThread of my Application, and I need to manage it from my thread.
in your first post you said
CDRAIN wrote: I need to manage a progressBar into MyThread class
I have no idea what to believe at this point. If your progress bar is in the main thread you DO NOT need to manage it from the worker thread. Instead you do something like this:
Progress Information Object
CWnd in main thread (Progress Bar or Window) has a reference to the Progress Information Object
CWinThread worker thread has a reference to the Progress Information Object and continuously updates the object to reflect the work in progress.
ProgressBar or Window sets a timer and on the timer event reads the progress information from the shared Progress Information Object and updates the ProgressBar state.
led mike
|
|
|
|
|
I developed a log parser in plain C in VS 2005. The essential for the parser is to take in buffer as much data for the processing as possible. I read file as a binary by using low level function “_read”. I discovered that the optimal size of the buffer is 100 kb. I need actually buffer approximately of 500kb. However when I increase the buffer’s size the processing time increases. It happens according to profile because the reading time increases. I would expect that reading larger portion of data should reduce reading time, but got opposite results. I assume it can depend on some compiler settings, but couldn’t find anything. I would appreciate any help in this matter.
Yefim
|
|
|
|
|
Hmm I don't know what I'm missing but reading 5 times as many bytes could take 5 times as long...
Are you accessing the file sequentially or randomly?
What flags are you specifying in the _open() call?
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Mark thanks for fast respond.
I’m accessing this file sequently and here is the opening and reading part
iFin = _open(szSourceFile, _O_BINARY|_O_RDONLY);
szBufRead = 100000;
iGet=_read(iFin,szBufRead,iReadData);
Thanks again Yefim
|
|
|
|
|
Try _O_BINARY|_O_RDONLY|_O_SEQUENTIAL.
Internally, the CRT uses the Windows CreateFile() API to open the file when you call _open().
_O_SEQUENTIAL causes the FILE_FLAG_SEQUENTIAL_SCAN flag to be added to the dwFlagsAndAttributes
parameter passed to ::CreateFile(). Whether the system actually uses this flag, I don't know
That's the only place I can see to possibly optimize buffering, aside from disabling all system
buffering and handling it yourself.
Are you sure it's not just a matter of reading 5 times as many bytes at a time from a relatively
slow device?
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
The strcpy below throw 'Access Violation'. Can anybody show me how to do it correctly? Thanks.
char **pArrayLabel = NULL;
int size=12;
pArrayLabel = new char*[size];
CString szLabel0 = "Januari";
strcpy(pArrayLabel[0],(char *)szLabel0.GetBuffer(szLabel0.GetLength()));
|
|
|
|
|
You're copying into an uninitialized pointer. You need to allocate a char buffer for each of the 12 char* s
|
|
|
|
|
I would do this:
char *pArrayLabel = NULL;
int size=12;
pArrayLabel = new char[size];
CString szLabel0 = "Januari";
strcpy(pArrayLabel,(char *)szLabel0.GetBuffer(szLabel0.GetLength()));
And when you pass it to the other function, pass it as "&pArrayLabel"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.soonr.com">SoonR Inc.</A>
|
|
|
|
|
once again, somebody is using CString::GetBuffer() when it's definitely not needed.
Call GetBuffer() only if you need to modify the CString object directly by writing inside its internal buffer. and this call to GetBuffer() requires a call to ReleaseBuffer() (which you don't do here).
if you only need to get the string contained within the CString, then you must use the cast operator (LPCTSTR) and that's it.
and for your problem, as that's been stated, you're assigning a NULL pointer.
modify your code into this.
ans at last, as i'm on it, please be careful with your variables names (generally, a variable starting with sz or psz is declared being a C-Style string)
const int iSize = 12;
TCHAR *pArrayLabel = ::new TCHAR[iSize];
CString strLabel = _T("Januari");
::_tcscpy_s(pArrayLabel[0], (LPCTSTR)szLabel0);
|
|
|
|
|
toxcct wrote: once again, somebody is using CString::GetBuffer() when it's definitely not needed.
Yeah, they should charge a toll $$$ to use CString::GetBuffer() and
CWnd::PreTranslateMessage() to help people consider alternative solutions
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
The (LPCTSTR) cast is superfluous there too, because the compiler will automatically call it when it sees that the _tcscpy() parameter is an LPCTSTR .
|
|
|
|
|
You already got enough information from other replies.
If you are using visual studio 2005, consider using secured version of these CRT function.
Refer Security enhancement to CRT[^].
Prasad
MS MVP - VC++
|
|
|
|
|
Hi,
Pls help anyone know how to control the brightness of avi. file??
Thanks in advance.
|
|
|
|
|
I dont know my answer wasnt enough or you like to ask again!
|
|
|
|
|
can anyone correct for me this:
CString strText;
CString strSQL;
CDaoDatabase db;
db.Open("D:\\copyktt.mdb");
m_cedit.GetWindowText(strText);
strSQL.Format("INSERT INTO Table6 SELECT * FROM Table3 IN 'C:\\ktt.mdb' WHERE MyField = %s",strText);
db.Execute(strSQL);
|
|
|
|
|
Not without specific error messages, but it looks like you are missing VALUES in your insert text... You need to also be sure that the DB you are connecting to can handle a subquery in the syntax you use.
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
I think if you read an article (read,write Access file) that I think I answered to you that link its better.
After read values of first database /*select * from Table3 that I dont think its good statement you must use Select with a Where maybe you have 200,000 records */ you can use like this code for example
CDaoDatabase database;
CDaoRecordset recordset(&database);
CString lpszFile = "d:\\copyktt.mdb";
database.Create(lpszFile);
CString lpszSQL = "CREATE TABLE MYTable
(Field1 VARCHAR(4),Field2 VARCHAR(4),Field3 VARCHAR(4),Field4 VARCHAR(4),MarketState VARCHAR(4))";
database.Execute(lpszSQL);
recordset.Open(AFX_DAO_USE_DEFAULT_TYPE,"SELECT * FROM MyTable",0);
database.Execute("INSERT INTO MyTable values('1','2','3','a','b')");
recordset.AddNew();
recordset.Update();
|
|
|
|
|
With what I understand about this macro, that its mandatory to use this
one for the following cases
<<
1)
All COM interface methods in "ATL using MFC" components should have this mac
ro.
2)
All COM eventsink methods in "ATL using MFC" components should have this mac
ro.
3)
Exported functions (or functions inside exported classes) of "Win32 dlls usi
ng MFC".
4)
Exported functions (or functions inside exported classes) of regular dlls us
ing shared MFC.
>>
Is this understanding correct??
For the 3rd case suppose I have a function inside a exported class, which ju
st uses some CString operations. Project as such uses MFC as shared dll. So
is it mandatory to use AFX_MANAGE_STATE at the beginning of such functions??
Am using VC 6.0 environment.
|
|
|
|
|
AFX_MANAGE_STATE mostly applies to anything in MFC that uses resources. Since MFC uses the app's
module handle when accessing resources, if you have an MFC extension DLL with its own resources
then the context needs to be switched in the DLL so the correct module handle is used by MFC.
CString is usable without having to use AFX_MANAGE_STATE.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
What message (WM_....) is fired by windows when user "stops a hardware device". How to trap this message through VC++.
(Go to USB Icon->right Click->click on "stop" button->Ok)
so how will i detect this through my Application,
My Problem is
handle of USB drive has been used by a service so when i am trying to safly remove this USB so one error is occuring i.e "The device 'generic volume' cannot be stopped righ now. Try stopping the device again later".
So anyone can help me out to resolve it.
Thanks in advance
RYK
|
|
|
|
|
So your problem is to write a usb detector app or unplug your usb from the computer?
--
=====
Arman
|
|
|
|
|
Yaa, i have USB detector but when i am stoping USB then it is not being detected if the handle of USb is being used by service
|
|
|
|
|
First, my apologies for posting this again - it went unanswered in the VB forum so I am trying with a bigger audience here....
I have a VB.NET 2005 application that makes calls to a C/C++ (VC6) DLL and I have that part working fine. The C/C++ DLL makes use of callback functions to let the VB application know of unsolicited events and that works as well (the functions are at least being called). The problem is I don't know the proper parameters to use (either the C++ or VB side) to get a byte array from C++ back to VB.
I have tried the following:
<br />
C++ side: <br />
BYTE bArray[] = { 11, 12, 13, 14, 15 };<br />
int len = 5;<br />
pfnCallback(bArray, len);<br />
<br />
VB side:<br />
CallbackHandler(ByVal data() as Byte, ByVal len as Integer)<br />
This resulted in the data array length of 1 and it only had the first value of the array no matter how big my array was.
Then I tried:
<br />
C++ side:<br />
SAFEARRAY *psa; <br />
(then properly created psa, and data copied in)<br />
pfnCallback(psa);<br />
(then properly destroy psa)<br />
<br />
VB side:<br />
CallbackHandler(ByVal data() as Byte)
This resulted in the data array length of 1 and it had the first element of C's SAFEARRAY in it (cDim). I could not see my data.
Am I barking up the wrong tree? Is what I want to do possible? I tried ByRef and got exception errors as it jumped from native code to managed code. For the short term, I made a string showing the hexadecimal values of the byte array and passed the string from the C/C++ library back up to VB; that works fine for now....
Thanks in advance,
Paul
|
|
|
|
|
have you tried using an IntPtr on the VB side ?
CallbackHandler(ByVal dataPtr as IntPtr, ByVal len as Integer)
then, Marshall the data into your VB objects...
|
|
|
|