Click here to Skip to main content
15,902,114 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: error C2065: 'IDD_DIALOG1' : undeclared identifier Pin
anderslundsgard17-Aug-04 1:46
anderslundsgard17-Aug-04 1:46 
Questionsize of folder? Pin
lonely_life17-Aug-04 0:22
lonely_life17-Aug-04 0:22 
AnswerRe: size of folder? Pin
David Crow17-Aug-04 5:21
David Crow17-Aug-04 5:21 
GeneralDarg n Drop problm , TO get file path and name Pin
zahid_ash17-Aug-04 0:10
zahid_ash17-Aug-04 0:10 
GeneralRe: Darg n Drop problm , TO get file path and name Pin
David Crow17-Aug-04 5:35
David Crow17-Aug-04 5:35 
GeneralRe: Darg n Drop problm , TO get file path and name Pin
zahid_ash17-Aug-04 18:19
zahid_ash17-Aug-04 18:19 
GeneralRe: Darg n Drop problm , TO get file path and name Pin
David Crow18-Aug-04 6:08
David Crow18-Aug-04 6:08 
GeneralC++ Access violation Pin
rahbani16-Aug-04 23:48
rahbani16-Aug-04 23:48 
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;
}
/*------------------------------------------------------------------------------------------------------ */
Generalprevent from screen capture Pin
Member 65121716-Aug-04 22:52
Member 65121716-Aug-04 22:52 
GeneralRe: prevent from screen capture Pin
ThatsAlok17-Aug-04 0:36
ThatsAlok17-Aug-04 0:36 
GeneralRe: prevent from screen capture Pin
Member 65121717-Aug-04 7:25
Member 65121717-Aug-04 7:25 
GeneralSynchronization of two threads Pin
nnvidya16-Aug-04 22:47
nnvidya16-Aug-04 22:47 
GeneralRe: Synchronization of two threads Pin
Blake Miller20-Aug-04 5:22
Blake Miller20-Aug-04 5:22 
Questionhow to magnify the video Pin
zahid_ash16-Aug-04 22:10
zahid_ash16-Aug-04 22:10 
AnswerRe: how to magnify the video Pin
Blake Miller20-Aug-04 5:36
Blake Miller20-Aug-04 5:36 
GeneralRe: how to magnify the video Pin
zahid_ash20-Aug-04 19:14
zahid_ash20-Aug-04 19:14 
GeneralRe: how to magnify the video Pin
Blake Miller23-Aug-04 4:20
Blake Miller23-Aug-04 4:20 
GeneralFocus problem. Pin
V.16-Aug-04 21:47
professionalV.16-Aug-04 21:47 
GeneralRe: Focus problem. Pin
V.16-Aug-04 22:47
professionalV.16-Aug-04 22:47 
GeneralEnter Pin
Johnny Peszek16-Aug-04 21:21
Johnny Peszek16-Aug-04 21:21 
GeneralRe: Enter Pin
V.16-Aug-04 21:34
professionalV.16-Aug-04 21:34 
GeneralRe: Enter Pin
Johnny Peszek17-Aug-04 2:32
Johnny Peszek17-Aug-04 2:32 
GeneralRe: Enter Pin
V.17-Aug-04 3:53
professionalV.17-Aug-04 3:53 
GeneralRe: Enter Pin
Johnny Peszek17-Aug-04 9:23
Johnny Peszek17-Aug-04 9:23 
GeneralRe: Enter Pin
V.17-Aug-04 21:46
professionalV.17-Aug-04 21:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.