|
Hi man,
I have a really urgent matter and I really could use your help
Right now, I am doing an internship in a company and unless I can finish this project correctly, I will have
to re-do my internship
Here it goes
I have to make an application (for a small brokers company) that does the following:
1- Get data from a certain data source (using dll interface) - Step succeeded
2- Turn a first thread to start reading continuous flow of data (c++ structures), transforms them to xml flow
(std::string strXml = ProcessThe Record ) and place the strXml in a Queue
In fact we have 3 Queues (each of which corresponds to the type of message)
2 StaticQueue + 1 Dynamic Queue
3- Turn another thread that creates a socket, and listens to sockets trying to connect
Each new client will start receiving data from the 2 static queues (temporary queues are used coz the data
contained in a static queue need not to be lost)
When this new client receives the static messages, he will start receiving dynamic ones from the dynamic queue
The problem is that the applicaiton is compiled and built successfully
It runs fine but after a while (sometimes half an hour, sometimes 6 hours) it gives me this error
"instruction at ... uses adress memory ... Memory cannot be written"
"Unhandled exception in ....exe NTDLL.dll 0xC0000005 Acess violation"
I tried to debug the application:
I sometimes get the cursor on this line of code : strMsg = dynQ.pop(); (Thread connection)
I have rewritten the Queue class making it a "Synchronized queue" coz I thought it was a "critical section"
We have 2 threads, 1 is reading and the other is writing to the same Queue
Here is the code of the synchronized Queue:
............................................................................................
#include <queue>
#include <deque>
typedef std::queue<std::string, std::deque<std::string,="" std::allocator<std::string=""> > > SQ;
class SynchronizedQueue {
public:
SynchronizedQueue(){ boolTurnIsTaken = false; };
~SynchronizedQueue(){};
std::string pop();
void push(std::string);
void clear();
bool empty();
private:
bool boolTurnIsTaken;
SQ myqueue;
};
std::string SynchronizedQueue::pop() {
std::string res = "";
while(boolTurnIsTaken == true) Sleep (1);
try{
if (!myqueue.empty()){
boolTurnIsTaken = true;
try{
res = myqueue.front();
if (!myqueue.empty()){
try {
myqueue.pop();
}
catch(...)
{
res = "";
boolTurnIsTaken = false;
return res;
}
}
boolTurnIsTaken = false;
}
catch(char *strQ){
res = "";
boolTurnIsTaken = false;
}
}
}
catch(...){
boolTurnIsTaken = false;
res = "";}
return res;
};
bool SynchronizedQueue::empty() {
return myqueue.empty();
};
void SynchronizedQueue::push(std::string xToPush){
while(boolTurnIsTaken == true)
Sleep (1);
try
{
boolTurnIsTaken = true;
myqueue.push(xToPush);
boolTurnIsTaken = false;
}
catch(...){boolTurnIsTaken = false;}
};
void SynchronizedQueue::clear(){
while(boolTurnIsTaken == true) Sleep (1);
std::string strWhat;
try
{
while (!myqueue.empty()){
boolTurnIsTaken = true;
strWhat = myqueue.front();
myqueue.pop();
boolTurnIsTaken = false; }
}
catch(...){boolTurnIsTaken = false;}
};
............................................................................................
The main 3 threads in my application are the following:
- ThreadGetMessage: Read messages from the provider + converts them to XML + Fill the Queues
- ThreadTreatMessage: Creates a server socket + listens to connected clients
Each newly connected client will get the static messages and afterwards it'll start getting dynamic msg
_ ThreadConnection :
Broadcast XML Converted Messages to all Connected Clients
We do not take into consideration the status of the Client
This thread works apart from from the thread that adds New
Clients and provide them with static messages
I am really desperate
Please, your help would be greatly appreciated
/* THREAD No I ---------------------------------------------------------------------------------------
Read Messages + Convert to XML from QuoteSpeed
------------------------------------------------------------------------------------------------------ */
UINT ThreadGetMsg(LPVOID pParam){
// Output File
ofstream foutM("Messages.txt");
std::string strXML, resultat;
int nSize;
nSize = -1;
strXML = "";
resultat = "";
BYTE *bMessageBuffer;
bMessageBuffer = new BYTE [1024];
while(true){
try {
// Reading Msg Buffer
if ( bMessageBuffer != NULL )
{
if ( (nSize=TApiReadRecord(bMessageBuffer)) != NULL ){
try{ // Try to Process the Record
strXML = ProcessTheRecord(bMessageBuffer);
if (strXML.empty()== 0 && strXML.size() > 10){
if (boolMessageisStatic == true){
if (boolMessageisStaticIS == true){
// Add Static Messages to Static Queue for Index and Stocks
staQ.push (strXML.c_str());
foutM << strXML.c_str() << endl;
intTotalStatic ++;
intTotalIndexStock ++;
IntroScreen ();
}
else if (boolMessageisStaticOF == true){
// Add Static Messages to Static Queue for Futures and Options
staQ2.push (strXML.c_str());
foutM << strXML.c_str() << endl;
intTotalStatic ++;
intTotalFutureOption ++;
IntroScreen ();
}
}
else { // It's a Price, Add it to the Dynamic Queue
//while (boolDynQIsBusy)
// Sleep(1);
//boolDynQIsBusy = true;
dynQ.push (strXML.c_str());
//boolDynQIsBusy = false;
foutM << strXML.c_str() << endl;
intTotalDynamic ++ ;
IntroScreen ();
}
} // End if strXML NOT Empty
}// End Try Process the Record
catch( char * strTM ){fout << " Error: ThreadTreatMessage - " << strTM << endl;}
}
else
{
Sleep (10);
}
} // else bMessageBuffer != NULL
else
Sleep (10);
//bMessageBuffer = NULL;
//delete [] bMessageBuffer;
}// End Try
catch (char *strE3){
intErrorCode = 5;
if (strGError == NULL)
strGError = new char [30];
strGError = strE3;
fout << strGError << endl;
IntroScreen ();
getch();
foutM.close ();
return 1;
}
}//End While
foutM.close ();
// Thread completed successfully
return 0;
}
/* End THREAD No I ------------------------------------------------------------------------------------- */
/* THREAD No II --------------------------------------------------------------------------------------
Broadcast Messages to all Connected Clients
------------------------------------------------------------------------------------------------------ */
UINT ThreadTreatMsg( LPVOID pParam )
{
// Server listens on port 4020 + Broadcasts Messages to all conected clients (Specify Port No + No of Connections)
SocketServer in(4020, 10000);
std::string charC, statMsg;
int intCounter = 0;
int intCounter1 = 0;
Sleep (10000);
while (1) {
charC = "";
const std::string b = ".";
Socket* s = in.Accept();
if (s != NULL){
// Give Client Static Messages
charC = in.getCurrentClient();
intTotalClients ++;
IntroScreen ();
statMsg = "";
try {
intCounter = 0;
while (!staQ.empty()) {
// Give the Newly Connected Client Static Messages
statMsg = staQ.pop();
tempQ.push (statMsg); // Add item to the temp Queue
try{
(*s).SendLine(statMsg);
intCounter ++;
}
catch(char *strEConnT1){fout << "Error: Thread Treat Message: " << strEConnT1 << endl; }
} // End While Sta Queue Not Empty
foutCount << "Sent Index and Stocks TOTAL = " << intCounter << endl;
intCounter1 = 0;
while (!staQ2.empty()) {
statMsg = staQ2.pop(); // Give the Newly Connected Client Static Messages
tempQ2.push (statMsg); // Add item to the temp Queue
try {
(*s).SendLine(statMsg);
intCounter1 ++;
}
catch(char *strEConnT2){ fout << "Error: Thread Treat Message 02: " << strEConnT2 << endl; }
} // End While Static Queue 2 Not Empty
foutCount << "Sent Futures and Options TOTAL = " << intCounter1 << endl;
try {(*s).SendLine(b);}
catch(char *strEConnT3){ fout << "Error: Thread Treat Message - Sending Break : " << strEConnT3 << endl; }
// Empty the Temp Q + Refill Static Q
while (!tempQ.empty()) {
try{
statMsg = tempQ.pop();
staQ.push (statMsg);
}
catch (char *strETM3){ fout << "Error: Thread Treat Message - ReFilling Static Queue: " << strETM3 << endl; }
} // End While Static Queue Not Empty
while (!tempQ2.empty()) {
statMsg = tempQ2.pop();
staQ2.push (statMsg);
} // End While Static Queue Not Empty
AfxBeginThread(ThreadConnection, (void*) s);
}
catch (char *strESend ){
intErrorCode = 6;
if (strGError == NULL)
strGError = new char [30];
strGError = strESend;
fout << strGError << endl;
IntroScreen ();
getch();
return 1;
}
} // End if s != NULL
Sleep (4000);
} // End While (1)
return 0; // Thread completed successfully
}
/* THREAD No II ----------------------------------------------------------------------------------- */
/* THREAD No III -------------------------------------------------------------------------------------
Broadcast XML Converted Messages to all Connected Clients
We do not take into consideration the status of the Client
This thread works apart from from the thread that adds New
Clients and provide them with static messages
------------------------------------------------------------------------------------------------------ */
UINT ThreadConnection(LPVOID pParam){
std::string strMsg;
strMsg = "";
try {
Socket* sTC = (Socket*) pParam;
g_connections.push_back(sTC);
socket_list::iterator os;
Sleep (20);
while (1) {
// Old client does Not Get Static Messages
while (!dynQ.empty()) {
try {
strMsg = "";
strMsg = dynQ.pop(); // Read and Remove Message
// Send Message
for (os = g_connections.begin(); os != g_connections.end(); os++){
try { (*os)->SendLine(strMsg);}
catch(char *strEConnT){fout << "Error: ThreadConnection - Sending Message : " << strEConnT << endl; }
} // End For
}
catch (char *strEConn)
{fout << "Error: ThreadConnection - Front + Pop + SendLine: " << strEConn << endl; }
}// End While Dyn Queue Not Empty
Sleep (20);
}// End While (1)
g_connections.remove(sTC);
delete sTC;
}// End try
catch (char *strE2) {fout << "Error: ThreadConnection: " << strE2 << endl; }
return 0;
}
/*------------------------------------------------------------------------------------------------------ */
|
|
|
|
|
hi...
I have no clue in my troubles.
I hope somebody can help me.
Question: How can I prevent from capturing a screen capture utilities or PrintScrn key?
thanks in advance!
|
|
|
|
|
basically you can prevent Printscrn keystoke using the Windows Keyborad hook.
there is dozens of pretty gud article on hook at cp just find using keyword "hooks"
|
|
|
|
|
thanks for your reply.
I understand what you mean.
If i hook the key stroke for print screen, i will prevent from screen capture. OK.
But, I still have a question.
How can i prevent from screen capturing by image capture utilities?
|
|
|
|
|
In my application there are two threads running.
One is main thread which is handled in GUI(front end) another one is
backend thread which is running in the background.
There is a result structure which will be filled by the backend thread and displayed in the gui by main thread.
Each time the new result will be added to the previous one. like iteration info1, 2....10 like that.
When backend thread fills info 1 it generates an event to main thread to display that in gui, and it starts reading/calculating for the second iteration info.
Any iteration info can be displayed only when it is completely filled.
But here i am getting exception as the event for the second one is invoked before the first one is not displayed completely.
Please let me know how to handle this using mutex.
vidya
|
|
|
|
|
You can create two buffers, the thread doing filling fills an alternate buffer each time, the main gui reads from the one NOT being filled.
If you fill faster than you read, however, then you need a thread-safe queue.
The mutex would be locked when you are reading and element from or writing and element to the queue.
|
|
|
|
|
hi,
I m capotruing a video using VC++ and DirectX.
i want to magnify it ,,in running mode Means to say that wil preview / Capturing it.
or in second sense zoom it.
but better word i think is to magnfiy it ,same as when u r getting picture from ur digittal camera u cam zoom / magnify it .
any hint or sample
thanx
Regards.
|
|
|
|
|
Look at source code for ZoomIn developer utility ships with Visual C++.
|
|
|
|
|
hi,
Where can i get this xource code of Zoom in utility of VC++.
plz tell ,
and i want to use zoom in for video previewing that i m building with VC++ and directshow ....
thanx for help
Regards.
|
|
|
|
|
The ZoomIn is a utility that ships with visual Studio 6.0.
I am pretty sure the source code is available from the MSDN library.
Also take a look at PJ's code here:
http://www.codeproject.com/tools/imageviewer.asp
It has ability to zoom in as well.
|
|
|
|
|
Hi,
In our project @ work we have a flex grid component. When you double click a cell you get in 'edit mode' and a dialog appears so you can type a value and if you press OK the cell gets this value. (They probably had their reasons to do it like that )
I derived a class from this one with some extra features, but now it seems I have to click on the dialog again to get the focus on the dialog (after doubleclick) setting the focus to another cell in the grid! (if you would press OK the WRONG cell gets the value)
I have checked my code against the base class and there is nothing I can see that is significantly different.
In the OnInitDialog from the called dialog I set the focus to a control.
Question: How can I put focus ON the dialog and OFF the grid without an extra click? (which will set focus to another cell)
1 more note: I can type in my control no problem, so If you would press enter everything would be fine. It's just as if the mouse doesn't get there?
I hope somebody can help me, tnx in advance!
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix
|
|
|
|
|
OK, I found it:
<br />
SendMessage(WM_LBUTTONDOWN);<br />
SendMessage(WM_LBUTTONUP);<br />
and it seems to work. (pfew )
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix
|
|
|
|
|
Hi!
In a dialog based application with a multiline edit box I’m trying to count the number of enter hits. I tried to use code like this:
void CNanoDlg::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if(nChar==VK_RETURN)
{
counter++;
}
CDialog::OnChar(nChar, nRepCnt, nFlags);
}
The code doesn’t work.
Any Ideas?
Thanks in advance.
|
|
|
|
|
Do this:
message map:
<br />
ON_WM_GETDLGCODE() <br />
header file:
<br />
afx_msg UINT OnGetDlgCode( );<br />
in code:
<br />
UINT CtrlFlexArray::OnGetDlgCode(){<br />
return DLGC_WANTALLKEYS;<br />
}
good luck.
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix
|
|
|
|
|
I almost got it. But when I press enter or any different key in the edit box the function OnGetDlgCode()
returns always the same result so I’m not able to count enter hits. Am I missing something?
Regards.
|
|
|
|
|
I dunno,
Do you handle your keystrokes in OnKeyDown (or Up) messagehandler?
in message map:
ON_WM_KEYDOWN()
in header:
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
in code:
void yourclas::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags){<br />
}
if you do have this I wouldn't know, what you could have forgotten.
Hope this helps.
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix
|
|
|
|
|
The code that you wrote works fine in SDI or MDI application. But I have dialog based application with edit box in which I want to count enter hits.
|
|
|
|
|
Try adding a button to your dialog,
set it as default button and make it invisible.
(note: it could take the ESC button too)
(note: if it doesn't work, set it's focus explicitly)
just an idea, hope it works.
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix
|
|
|
|
|
HI,
Plz tell me differnce between Win32 and MFC programming
thanx
Regards.
|
|
|
|
|
Win32 is the programming interface to Windows, including all the Windows functions.
MFC is an application framework that includes much of the Win32 functionality, and a lot more.
|
|
|
|
|
thanx
but i want to know
When we use File ->New(PRoject tab)
there r options many ....
wts there differece win32 application and MFC wizard,
is that we can not use MFC classes in Win32 application or some else
thanx
Regards.
|
|
|
|
|
Check the following links
FOR MFC:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/_core_overview.3a_.creating_an_mfc_exe_program.asp
FOR WIN32:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/vcgrfoverviewwin32appwizard.asp
|
|
|
|
|
Per MSDN:
MFC is an "application framework" for programming in Microsoft Windows. Written in C++, MFC provides much of the code necessary for managing windows, menus, and dialog boxes; performing basic input/output; storing collections of data objects; and so on. All you need to do is add your application-specific code into this framework. The MFC framework is a powerful approach that lets you build upon the work of expert programmers for Windows. MFC shortens development time; makes code more portable; provides tremendous support without reducing programming freedom and flexibility; and gives easy access to "hard to program" user-interface elements and technologies.
The Win32 application programming interface (API) defines the 32-bit members of the Windows operating system family from the programmer's point of view. Some members of the Windows family use the entire Win32 API, while others use subsets. MFC encapsulates, or "wraps," much of (but not all of) the Win32 API. In general, MFC supplies classes representing key Windows objects, such as windows, dialog boxes, brushes, pens, and fonts. The member functions of these classes wrap most of the important Win32 API functions associated with the encapsulated object. That is, the MFC class member function calls the Win32 API function.
With Visual C++, you can program for Windows using either C or C++ and the Win32 API, or using C++ and MFC.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Actually,let me explain the diffence between them in wasy way.
i think you know dosbased c and c++ before going for the MFC and win32 api.
here is the solution,
you can win32 api as windows based c and mFC as Windows Based c++.
basically as dos based c is more close to system same way win32 are more close to system and dos based c++ is oops based same way the mfc is oops based.
and as you know c++ use wrappper of c to provide easy handlling of function ,same way mfc provide wrapper some commonly used win32 api function,i think that enough.
if you want more search CP
-----------------------------
"I Think It will Work"
Formerly Known As "Alok The Programmer" at CP
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
Hello,
I have a group of files, how do I check the integrity of the files with a the given value which summarize the files content. For a single files, I know there are CRC. But how about a group files?
Any proven methods?
thanks
Sonork 100.41263:Anthony_Yio
|
|
|
|