|
You've posted no source and no call stack; how can we possibly help given such limited data?
Steve
|
|
|
|
|
////////////////RTMPClient.cpp/////////////////
#include "StdAfx.h"
#include "RTMPClient.h"
#include "RTMPBuffer.h"
#include "VSocket.h"
RTMPClient::RTMPClient(void)
{
//m_sock =NULL;
m_buff = new RTMPBuffer();
}
RTMPClient::~RTMPClient(void)
{
}
BOOL RTMPClient::SendRectangle(RECT &rect)
{
char str[100];
sprintf(str," In RTMPClient Bottom %d,Right %d",rect.bottom ,rect.right);
MessageBox(NULL,CString(str),CString("TestRTMP"),0);
RECT sharedRect;
{
//omni_mutex_lock l(m_regionLock);
//sharedRect = m_server->GetSharedRect();
}
sharedRect.left = 0;
sharedRect.top = 0;
sharedRect.right = 1280;
sharedRect.bottom = 1024;
BOOL res = IntersectRect(&rect, &rect, &sharedRect);
if(res)
{
sprintf(str," In RTMPClientBottom %d,Right %d",rect.bottom ,rect.right);
//MessageBox(NULL,CString(str),CString("TestRTMP"),0);
}
// Get the buffer to encode the rectangle
m_buff->TranslateRect(rect,m_sock,sharedRect.left,sharedRect.top);
//UINT bytes = m_buff->TranslateRect(rect,m_sock,sharedRect.left,sharedRect.top);
// Send the encoded data
// return m_socket->SendQueued((char *)(m_buffer->GetClientBuffer()), bytes);
return TRUE;
}
///////////////RTMPClient.h//////////////////////
#include "RTMPBuffer.h"
#include "VSocket.h"
#pragma once
class RTMPClient
{
public:
RTMPClient(void);
~RTMPClient(void);
BOOL SendRectangle(RECT &rect);
public:
RTMPBuffer *m_buff;
VSocket *m_sock;
};
|
|
|
|
|
You haven't indicated where the crash is occuring! If you don't know run it in a debugger and find out.
Steve
|
|
|
|
|
In RTMPClient.cpp file
Program Crash on this line.......
//////////////////////////////////
UINT bytes = m_buff->TranslateRect(rect,m_sock,sharedRect.left,sharedRect.top);
//////////////////////////////////
it shows the unhandled exception like below......
/////////////////////////////////////////
TestRTMP.exe: 0xC0000005: Access violation writing location 0xcccccccc.
//////////////////////////////////////
|
|
|
|
|
on which line u got the error..
may be in this line?
m_buff->TranslateRect(rect,m_sock,sharedRect.left,sharedRect.top);
hiren
|
|
|
|
|
yes on this line i got error
if i initialize it with new operator in constructor then also it gives same error.
|
|
|
|
|
i think it is due to m_sock . which is not being initialize yet..
make simple function without any arument then try that function .i think u will defiantly not get any error.
|
|
|
|
|
I can't see a memory write operation on this line. Show the call stack and the machine code around the crash.
Steve
|
|
|
|
|
ashishbhatt wrote: char str[100];
sprintf(str," In RTMPClient Bottom %d,Right %d",rect.bottom ,rect.right);
MessageBox(NULL,CString(str),CString("TestRTMP"),0);
May I suggest:
CString str;
str.Format(" In RTMPClient Bottom %d,Right %d", rect.bottom , rect.right);
AfxMessageBox(str); ashishbhatt wrote: m_buff->TranslateRect(rect,m_sock,sharedRect.left,sharedRect.top);
What is the value of m_buff at this point?
"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
|
|
|
|
|
I think the best advice one can give you is to learn to use your debugger. This kind of errors can be easily fixed and quite quickly if you know how to use the debugger (and certainly much faster than asking on a forum).
So, press F5 to start your debugger. You will be able to set breakpoints in your code with F9 (breakpoints are points in your program where the execution will stop, allowing you to inspect the variables). Then, first localize where the crash occurs (and the callstack can be usefull there) and then you can inspect the different variables to see if everything is as expected.
|
|
|
|
|
Dear all,
I am in project of developing ISO 8583 Client Simulator. I got a problem here about how to read response message from the host. The response can contain NULL character any where within the bytes sequence and I never know how long the message is. The only thing about to know the message length is I must read the first two bytes of the message. And the remaining bytes actually is the message it self. Now, I want to create a variable to save the message and I must reserver the memory using "new". But how can I reserve the memory exactly as the message length it self, while the only one way to know the message length is to read the first two bytes of the message.
I am waiting any one response soon.
Ian
|
|
|
|
|
yah your problem seems to be solvable. even i faced the same problem few days ago.but some more details are required.
1.what could be the maximum length of a mesage.
2.as you said, first two bytes contain the message length, we can conclude that, the size cannot exceed 16 bits, i.e. 0xffff. did you try taking an array of that size and see?
like,
char data[0xffff].
3.if this is possible, then you can comfortably take an array and use a stack pointer, to find the end of the message.
|
|
|
|
|
This is snippet of my codes:
void CIsoMsg::mfc_voidGetByteRq(char *ld_pchrDst)<br />
{<br />
int ld_intByteRqLen;<br />
ld_intByteRqLen = this->md_strCompIsoMsg.length() >> 1;<br />
<br />
char *ld_pchrByteRq = new char[ld_intByteRqLen];<br />
for(int i=0; i < ld_intByteRqLen; ld_pchrByteRq[i++]=0);<br />
this->mfc_voidHex2Byte((char*)this->md_strCompIsoMsg.c_str(), ld_pchrByteRq, 0, ld_intByteRqLen);<br />
<br />
int ld_intTCPByteRqLen = ld_intByteRqLen + 2;<br />
char *ld_pchrTCPByteRq = new char[ld_intTCPByteRqLen];<br />
<br />
<big> if(ld_intByteRqLen <= 255)<br />
{<br />
ld_pchrTCPByteRq[0] = 0;<br />
ld_pchrTCPByteRq[1] = ld_intByteRqLen;<br />
}<br />
else<br />
{<br />
ld_pchrTCPByteRq[0] = ld_intByteRqLen / 256;<br />
ld_pchrTCPByteRq[1] = ld_intByteRqLen % 256;<br />
}</big><br />
for(int i=2, j=0; i < ld_intTCPByteRqLen; i++, j++)<br />
{<br />
ld_pchrTCPByteRq[i] = ld_pchrByteRq[j];<br />
}<br />
<br />
memcpy(ld_pchrDst, ld_pchrTCPByteRq, ld_intTCPByteRqLen);<br />
<br />
delete [] ld_pchrByteRq;<br />
delete [] ld_pchrTCPByteRq;<br />
}<br />
<br />
<br />
void CIsoMsg::mfc_voidHex2Byte(char *ld_pchrScr, char *ld_pchrDest, int ld_intStartOffset,int ld_intLen)<br />
{<br />
char ld_chrBuf1[2], *ld_pchrBuf2;<br />
ld_chrBuf1[1]=0;<br />
int ld_intShiftLeft;<br />
for(int i=0; i < (ld_intLen * 2); i++)<br />
{<br />
if(i%2 == 1) ld_intShiftLeft = 0; <br />
else ld_intShiftLeft = 4;<br />
ld_chrBuf1[0] = ld_pchrScr[ld_intStartOffset+i];<br />
ld_pchrDest[i>>1] = ld_pchrDest[i>>1] | strtol(ld_chrBuf1,&ld_pchrBuf2,16) << ld_intShiftLeft;<br />
}<br />
}
There are two function I attached here. The length of those message (the first two bytes) is not as simple like the maximum is 0xffff. But it use the algorithm which I show you above (BIG formatted).
So I can't know the exactly length by conclude it would be 0xffff length.
Ian
|
|
|
|
|
can you just comment your code and repost it.
meanwhile, i will try to hand run it.
|
|
|
|
|
Sory, here I repost the source code again cause the previous is not complete. The source code here is modified from the previous so you can run it on your machine. The certain variables here I initialized so it meet the testing environment that I used.
void main()<br />
{<br />
int ld_intByteRqLen;<br />
<br />
string ld_strCompIsoMsg("600015800002003020058020C010040010000000000333000002500021001500325577911013392824D12041011646435036343333373730313030303030303039323739393435357556C9933721414F0006303030333539");<br />
ld_intByteRqLen = ld_strCompIsoMsg.length() >> 1;<br />
<br />
char *ld_pchrByteRq = new char[ld_intByteRqLen];<br />
for(int i=0; i < ld_intByteRqLen; ld_pchrByteRq[i++]=0);<br />
<br />
this->mfc_voidHex2Byte((char*)this->md_strCompIsoMsg.c_str(), ld_pchrByteRq, 0, ld_intByteRqLen);<br />
<br />
int ld_intTCPByteRqLen = ld_intByteRqLen + 2;<br />
<br />
char *ld_pchrTCPByteRq = new char[ld_intTCPByteRqLen];<br />
<br />
if(ld_intByteRqLen <= 255)<br />
{<br />
ld_pchrTCPByteRq[0] = 0;<br />
ld_pchrTCPByteRq[1] = ld_intByteRqLen;<br />
}<br />
else<br />
{<br />
ld_pchrTCPByteRq[0] = ld_intByteRqLen / 256;<br />
ld_pchrTCPByteRq[1] = ld_intByteRqLen % 256;<br />
}<br />
<br />
for(int i=2, j=0; i < ld_intTCPByteRqLen; i++, j++)<br />
{<br />
ld_pchrTCPByteRq[i] = ld_pchrByteRq[j];<br />
}<br />
<br />
for(int i=0; i < ld_intTCPByteRqLen; i++) cout << "ld_pchrTCPByteRq[" << i << "] = " << (int)ld_pchrTCPByteRq[i] << endl;<br />
<br />
delete [] ld_pchrByteRq;<br />
delete [] ld_pchrTCPByteRq;<br />
}<br />
<br />
void mfc_voidHex2Byte(char *ld_pchrScr, char *ld_pchrDest, int ld_intStartOffset,int ld_intLen)<br />
{<br />
char ld_chrBuf1[2], *ld_pchrBuf2;<br />
ld_chrBuf1[1]=0;<br />
int ld_intShiftLeft;<br />
for(int i=0; i < (ld_intLen * 2); i++)<br />
{<br />
if(i%2 == 1) ld_intShiftLeft = 0; <br />
else ld_intShiftLeft = 4;<br />
ld_chrBuf1[0] = ld_pchrScr[ld_intStartOffset+i];<br />
ld_pchrDest[i>>1] = ld_pchrDest[i>>1] | strtol(ld_chrBuf1,&ld_pchrBuf2,16) << ld_intShiftLeft;<br />
}<br />
}
Ian
|
|
|
|
|
chandu004 wrote: 1.what could be the maximum length of a mesage.
What's the maximum value that two bytes can hold?
"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
|
|
|
|
|
obviously 0xffff, i.e 65535.
any thing wrong?
|
|
|
|
|
No, nothing wrong. I was just curiuous why you would ask such a question.
"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
|
|
|
|
|
my point was, if he could allocate 65535 bytes, as an array, instead of dynamic memory alloation,that would have solved his problem.
|
|
|
|
|
Reading two bytes, allocating the memory, then reading the remaining bytes
for a sent package isn't that inefficient.
The extra recv is so much faster than the actual transmission of the data
over the network that the extra copy is insignificant.
If you need to squeeze every last bit of performance and avoid an extra
2-byte copy then you can allocate a maximum package size. You still
won't know exacltly how many bytes to receive until you get those 2 bytes.
That means you'd need a constant size - less efficient.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi, thanks for your solution. I thought we can't using "read" 2 times to get the message. Now the problem is SOLVED.
Ian
|
|
|
|
|
You're welcome
I forgot to mention - my response assumed a stream based protocol like TCP.
For UDP you need to know the maximum datagram size and receive that many bytes
(although you can receive smaller datagrams).
Cheers,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark, if you answer all networking questions so detailed and helpful, what should I do then do in this forum? Hehe
/M
|
|
|
|
|
I'm trying to make a tab control (or empty container panel) that auto-hides. Anyone know where a good tutorial is for this?
|
|
|
|
|
Can you more about auto hide control?
|
|
|
|
|