|
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?
|
|
|
|
|
You can always try to set the window style to WS_MINIMIZE or WS_HIDE by masking the actual style and adding it.
Where to find that message depends on which project you have. CChildFrame::PreCreateWindow () if the project is MDI, CMainFrame::PreCreateWindow () if the project is SDI or CMyApp::OnInitInstance () if it is not using Doc/View.
for CMainFrame and CChildFrame:
{ if( !CMDIChildWnd::PreCreateWindow(cs) )
return FALSE;
cs.style = WS_SYSMENU | WS_CAPTION | WS_OVERLAPPED | WS_MINIMIZE;
cs.lpszName = m_pDoc->m_szNewFrameName;
return TRUE;
}
for CMyApp
BOOL CMyApp::InitInstance()
{
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
return FALSE;
m_pMainWnd = pMainFrame;
pMainFrame->ShowWindow(m_nCmdShow | SW_SHOWMINIMIZED);
pMainFrame->UpdateWindow();
return TRUE;
}
Hope it helps.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
What is it that you want to be hidden: a particular tab, or the whole dialog?
"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'd like to hide the tab control except for the tabs. Or basically, I'd like the same functionality as the auto-hide windows in VS 2005 .NET
|
|
|
|
|
I'm in the process of writing a set of custom controls, things like horizontal and vertical sliders, knobs, switches, etc... These controls have no background but do display a PNG image (with transparencies). For example, a slider is only responsible for painting its thumb, not the background underneath it.
My approach has been to use MFC to create custom controls deriving them from CWnd. I override OnPaint and OnEraseBkgnd so that I'm in control of how painting is done. I'm using GDI+'s Graphics class for drawing the images.
The custom controls are placed on a dialog box. Actually, they are placed on a Picture control displaying the background as a bitmap. When a control needs to repaint itself, it doesn't invalidate itself directly but tells the parent window to invalidate the rectangle it is within. If I have the control invalidate itself directly, then there's nothing to erase the previous image. Since there are transparencies involved, they just keep getting layered on top of each other.
I'm running into problems with flickering, especially in the case of my Knob control. The knob control uses 91 PNG images stitched together. When the knob changes values, it draws a specific knob image offset into the stitched group.
I know there's been a lot written here about flickering while drawing. But I must be dense about this because I can't seem to apply what I'm reading with my situation. I'm not trying to draw with primitives but rather use images that I load. I've looked at the GDI+ API for ways of somehow caching my PNG images so that I can switch between them seamlessly. I'm not coming up with much, so I'm asking for help. Thanks for your time and patience.
|
|
|
|
|
Any time you have to draw a background and then overlay something on top,
there's going to be flicker.
You have two options -
1) do it fast enough so a human can't notice.
2) do it offscreen.
Option 1 is pretty much impossible with current PCs.
For option 2, double buffering is pretty simple.
Before you draw the control the first time, and before redrawing the
control any time it gets moved or resized, get a copy of the background
pixels in a bitmap. Keeping this in a screen-compatible bitmap, selected
into a screen compatible memory dc is best.
A great place to do this is in response to WM_SIZE, where you can (re)create
the bitmap to the appropriate size.
Now, every time you need to draw the control, you can
1) blt the background image to a memory DC (compatible with screen)
2) blt the png overlay to the memory DC
3) blt from the memory DC to the screen
Make sense?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|