|
Hi,
I wrote an application( simulator) that creates a textfile, with some lines of text in it. This same application also deletes this textfile after a couple of seconds. This process repeats itself over and over again. So the outputfile is present for lets say 5 seconds and gets deleted for about the same amount of time.
This simulation file gets created with the following code :
CStdioFile OutFile;
if (OutFile.Open(m_strOutFileName, CFile::modeWrite | CFile::modeCreate | CFile::shareExclusive))
{
...
}
Then I wrote a second application, which checks every 100 millisec if the simulation file is present, and if so reads it in and processes it. This is done with following statements :
int CTimer::Scan(CPLine *pPLine, LPCTSTR lpszPFInPath, BOOL bInBuf)
{
int nBCCnt = 0;
try
{
CString strBC;
CStringArray BufArr;
CStdioFile inFile(lpszPFInPath, CFile::modeRead | CFile::shareExclusive);
while (inFile.ReadString(strBC))
{
if (strBC[0] == _T('\"'))
strBC.Delete(0);
if (strBC[strBC.GetLength() - 1] == _T('\"'))
strBC.Delete(strBC.GetLength() - 1);
if (bInBuf)
BufArr.Add(strBC);
else
{
if (LookupBC(pPLine, strBC))
nBCCnt++;
}
}
inFile.Close();
if (bInBuf)
{
int nSize = BufArr.GetSize();
for (int i = 0; i < nSize; i++)
if (LookupBC(pPLine, BufArr.GetAt(i)))
nBCCnt++;
}
}
catch (CFileException *e)
{
e->Delete();
nBCCnt = -1;
}
return nBCCnt;
}
When I run both applications, I sometimes receive the follow message :
CFile exception: sharingViolation, File C:\WINDOWS\Temp\L7.dta, OS error information = 32.
First-chance exception in PCnt.exe (KERNEL32.DLL): 0xE06D7363: Microsoft C++ Exception.
What is wrong here and how can I prevent this error ??
tia.
|
|
|
|
|
paperke67 wrote: When I run both applications, I sometimes receive the follow message
If this is in your debug output window, it's just informaing you that your try/catch is working correctly. If your using the same filename/path for each application, then I would expect an exception to occur periodically as a matter of statistic.
You did not post a Try/catch with the first apps code but I'm guessing its around the actual code, otherwise I would expect an exception dialog box to pop up on you for the same reason.
Since you are simply ignoring the exception by deleting the CException pointer without reporting it, it would appear that suppressing the error is by design and what you intended so any indication of a first chance exception in the debug output window for file operations is likely just informative and should cause you no alarm or indicate any problems with your code.
-- modified at 15:16 Sunday 9th July, 2006
I guess I forgot to mention that based on what your doing, two apps are competing to open the same file exclusively and since there is no syncronization between the apps and there are certain lag times on file locking operations, that the exception is expected to occur and again is just the nature of the beast when dealing with files, databases, or any resource that could be unavailable for a moment based on inherent environmental conditions. One of the competing apps is bound to find the file locked from time to time and it is safe to simply ignore it, and try again on the next interval or timer.
NOTE: However, if the file remains locked indefinitely, You app will not indicate this problem to the user since it is happily ignoring the exception every time. You might want to keep track of failures and after some excessive period report an error to a log file or popup an error via the GUI.
|
|
|
|
|
OP: That's a terrible design.
You could, alternatively, do something like a circular buffer of files:
writer writes file data0001
reader reads data0001 and deletes
writer knows it last wrote data0001 so next time it writes data0002, on up to, say, 1000 then loops back to 0.
reader always deletes. This way, the two apps shouldn't get into a race over the same file.
Alternatively, there is a whole body of stuff called IPC for getting data from one process into another. The ones that come to mind are pipes, sockets, and perhaps mailslots.
earl
|
|
|
|
|
earl wrote: OP: That's a terrible design.
Your replying to the wrong person. The thread initiator asked a question. I attempted to answer it and reassure them that the debug messages were just informational based upon their design decisions. What they are attempting to accomplish was "By design" as far as there code appeared. Why they choose to design systems this way or that is their business. Not mine.
I'll add suggestions from time to time but only when it's obvious that they will not achieve their objectives based on the code they post. This was not one of those methinks.
Good day.
|
|
|
|
|
Sorry Bob (again ), that's why I prefixed the response "OP:".
I'm still getting used to threaded / indented slashdot style forums...
|
|
|
|
|
Right clicking on CEdit pops up a context menu
this behaviour isn't working when using CRichEditCtrl?
any suggestions?
thanks
Yaron
Interface basics click here :
http://www.codeproject.com/com/COMBasics.asp
don't forget to vote
|
|
|
|
|
Hello everyone!
Does anyone have a tutorial on the basics of making MFC controls? I've read some tutorials, but they talk about sending messages and stuff that I don't understand... Basically, this is what I need to do:
A grid control that looks like this:
* No labels at the top.
* Fixed-size grid boxes.
* Colorable boxes. (Basic text formatting will do)
* Remove grid lines (The user can select to add it though)
Can anyone help me? Thanks!
Windows Calculator told me I will die at 28.
|
|
|
|
|
search CP for Grid Controls.
SaRath.
"Where I am from, there is no plan B. So, take advantage of today becuase tomorrow is not promised. - 50 Cent"
<blink>My Blog | Understanding State Patte
|
|
|
|
|
Hmm... Isn't there a tutorial that explains the basics on how to do it? The ones I found that looked useful are over 10 thousand lines total... Thanks!
[edit] Nevermind, too complex... I'll just use something else. Thanks! [/edit]
Windows Calculator told me I will die at 28.
-- modified at 20:38 Sunday 9th July, 2006
|
|
|
|
|
Hi all i am very new to visual c++ . I am using [B]visual studio 6[/B] . So i might ask some simple questions but since i am new i consider you guys bare with me.
I have the following 2 block of codes and i want to be able to call the first one like this :
int pos=-1;
pos=GetPosByNick("name");
I am making a form with a textbox and a button. On the click of the button i want to take the input and place it instead of name in above function call and get the pos value and then use that in my second block of code instead of zero :
(WPARAM)0
so i be happy if an expert tell me step by step what do i need to do to be able to use these blocks of codes. Where to place them , what do i need to declare. Since it is my first attempt to do a program in visual c++ i be happy if an expert give me step by step instrcutions. Thanks
int GetPosByNick(CString szNick) <br />
{ <br />
<br />
HWND hList=NULL;
<br />
HWND parent,child; <br />
parent=NULL; <br />
child=NULL; <br />
parent = ::FindWindow("My Window Class",NULL); <br />
CString c; <br />
<br />
child =::FindWindowEx(parent,0,"WTL_SplitterWindow",NULL); <br />
child =::FindWindowEx(child,0,"WTL_SplitterWindow",NULL); <br />
child =::FindWindowEx(child,0,"WTL_SplitterWindow",NULL); <br />
child =::FindWindowEx(child,0,"ATL:0053C8D0",NULL); <br />
hList=::FindWindowEx(child,0,"SysListView32",NULL); <br />
<br />
<br />
HWND hwnd=parent; <br />
HWND listview=hList; <br />
<br />
int count=(int)::SendMessage(listview, LVM_GETITEMCOUNT, 0, 0); <br />
int i; <br />
<br />
LVITEM lvi, *_lvi; <br />
char item[512]; <br />
char *_item; <br />
unsigned long pid; <br />
HANDLE process; <br />
<br />
GetWindowThreadProcessId(listview, &pid); <br />
process=OpenProcess(PROCESS_VM_OPERATION|PROCESS_VM_READ|PROCESS_VM_WRITE|PROCESS_QUERY_INFORMATION, FALSE, pid); <br />
<br />
_lvi=(LVITEM*)VirtualAllocEx(process, NULL, sizeof(LVITEM), MEM_COMMIT, PAGE_READWRITE); <br />
<br />
_item=(char*)VirtualAllocEx(process, NULL, 512, MEM_COMMIT, PAGE_READWRITE); <br />
<br />
<br />
lvi.cchTextMax=512; <br />
<br />
<br />
for(i=0; i<count; i++) { <br />
lvi.iSubItem=2; <br />
lvi.pszText=_item; <br />
WriteProcessMemory(process, _lvi, &lvi, sizeof(LVITEM), NULL); <br />
::SendMessage(listview, LVM_GETITEMTEXT, (WPARAM)i, (LPARAM)_lvi); <br />
<br />
<br />
ReadProcessMemory(process, _item, item, 512, NULL); <br />
if(item==szNick) <br />
{ <br />
VirtualFreeEx(process, _lvi, 0, MEM_RELEASE); <br />
::CloseHandle(process); <br />
return i; <br />
} <br />
<br />
} <br />
VirtualFreeEx(process, _lvi, 0, MEM_RELEASE); <br />
::CloseHandle(process); <br />
return -1; <br />
<br />
}
Second block of code:
HWND listview=NULL;
HWND parent,child; <br />
parent=NULL; <br />
child=NULL; <br />
parent = ::FindWindow("My Window Class",NULL); <br />
<br />
child =::FindWindowEx(parent,0,"WTL_SplitterWindow",NULL); <br />
child =::FindWindowEx(child,0,"WTL_SplitterWindow",NULL); <br />
child =::FindWindowEx(child,0,"WTL_SplitterWindow",NULL); <br />
child =::FindWindowEx(child,0,"ATL:0053C8D0",NULL); <br />
listview=::FindWindowEx(child,0,"SysListView32",NULL); <br />
<br />
LVITEM lvi, *_lvi; <br />
unsigned long pid; <br />
HANDLE process; <br />
<br />
GetWindowThreadProcessId(listview, &pid); <br />
process=OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE, FALSE, pid); <br />
if(process) <br />
{ <br />
<br />
_lvi=(LVITEM*)VirtualAllocEx(process, NULL, sizeof(LVITEM), MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); <br />
lvi.mask = LVIF_STATE; <br />
lvi.state =15; <br />
lvi.stateMask = LVIS_SELECTED | LVIS_FOCUSED; <br />
<br />
WriteProcessMemory(process, _lvi, &lvi, sizeof(LVITEM), NULL); <br />
::SendMessage(listview, LVM_SETITEMSTATE, (WPARAM)0, (LPARAM)_lvi); <br />
VirtualFreeEx(process, _lvi, 0, MEM_RELEASE); <br />
} <br />
::CloseHandle(process);
|
|
|
|
|
Found a great article of Nicloai Teofilov concerning 2D graphs. But I failed in drawing rectangles or circles with his code.
I don't know, how to link t his article, the adress is:
http://www.codeproject.com/miscctrl/ntgraph_activex.asp?forumid=13557&select=1567363&df=100&msg=1567363
Thanks, Gerhard
|
|
|
|
|
|
hi all,
i have a requirement to check the status when internet connection is lost and as well as again reconnected
when i disable and enable network connections it is shown well and good but when internet connection is lost from service provider stil my application shows me internet connection available
is there any other way to dectect internet connection ?
other than using
internetgetconnectedstate() method !
thanks
ranjith
|
|
|
|
|
as I know, there is no fast checking.
2 methods are:
(1) ftp - you need to provide a server which you have rights to access, then use ftp to check.
(2) try to "download" a file, but you can stop downloading once download starts because you just need to check connection.
This issue can be done by CInternetConnection.
(1) is faster than (2), but not very fast.
(2) may need only 1 second If internet connection is OK.
But if connection is not OK, you may have to wait for up to a few of minutes to get result - timeout does't work well in the case.
|
|
|
|
|
|
How can I determine the available/installed RAM on a machine? In VC++.
|
|
|
|
|
|
|
Hi,
I have a string formatted somewhere in my program as
Cstring strMain;
strMain.Format("Health: \nWealth");
At some other part of the program, I need 'Health:’ as a separate string and ‘Wealth’ as a separate string. I tried using sscanf but it is not separating the strings.
Cstring s1,s2;
Cstring strOriginal = getmain();
Sscanf(strOriginal,"%s: %s",s1,s2);
This give just ‘Health’ . i.e. both s1 and s2 hold the string ‘Health’
Please can you tell me the right way?
Fortitudine Vincimus!
-- modified at 9:02 Saturday 8th July, 2006
|
|
|
|
|
First of all, you can't use pass CString 's directly to sscanf . Arguments to sscanf must be pointers.
If you are using the '\n' as the delimiter, you could try something like the following:
CString s1,s2;
CString strOriginal = getmain();
int offset = strOriginal.Find('\n');
if (offset >= 0) {
s1 = strOriginal.Left(offset);
s2 = strOriginal.Mid(offset + 1);
}
Software Zen: delete this;
|
|
|
|
|
Thanks a lot.
Fortitudine Vincimus!
|
|
|
|
|
hi all,
i am getting following error in vc ++ .net 7.0
fatal error C1083: Cannot open include file: 'olestd.h': No such file or directory
can any one help me to solve this problem ?
Regards
venu
|
|
|
|
|
for which function, you are referrnig the same file? I strongly believe that, the file is local one(defined for your project).
AFAIK there's no such file named, oldstd.h
SaRath.
"Where I am from, there is no plan B. So, take advantage of today becuase tomorrow is not promised. - 50 Cent"
<blink>My Blog | Understanding State Patte
|
|
|
|
|
i'd like to see color dialog when i click a button(ID_BORDERCOLOR) on my ToolColor and then i can get color by m_bordercolor in CView.
Thanks
all for development
|
|
|
|
|
add message handler for ID_BORDERCOLOR, then inside the message handler,
add the code
CColorDialg dlg;
dlg.DoModal();
COLORREF clr = dlg.GetColor();
SaRath.
"Where I am from, there is no plan B. So, take advantage of today becuase tomorrow is not promised. - 50 Cent"
<blink>My Blog | Understanding State Patte
|
|
|
|
|