|
Nemanja Trifunovic wrote: I can't believe I wrote that
I don't think any of us can believe you said that!
|
|
|
|
|
I'm expecting sincere apologies
codito ergo sum
|
|
|
|
|
|
I am writing a short piece of code to broadcast a UDP packet over a network. It initialises the socket system, created a DGRAM socket, broadcasts the packet and then closes the socket. My problem is that when the Close() function is called it crashes with the message
HEAP[Test.exe]: Invalid Address specified to RtlFreeHeap( 01470000, 0147425C )
Here is the snippit of code :
#define BROADCAST_PORT 9122<br />
<br />
CAsyncSocket m_Broadcast_Socket;<br />
char Data[] = "1234567890";<br />
int Bytes_Sent;<br />
BOOL Value;<br />
<br />
<br />
AfxSocketInit();<br />
<br />
VERIFY(m_Broadcast_Socket.Create(BROADCAST_PORT, SOCK_DGRAM));<br />
Value = TRUE;<br />
VERIFY(m_Broadcast_Socket.SetSockOpt(SO_BROADCAST, &Value, sizeof(BOOL)));<br />
Bytes_Sent = m_Broadcast_Socket.SendTo((LPCTSTR)Data, 3, BROADCAST_PORT);<br />
DWORD Error = GetLastError();<br />
m_Broadcast_Socket.Close();
I can see the packet on my network monitor.
If I take out the SendTo call I have no crash.
If I take out the Close call the destructor crashes (again in the Close call).
What am I doing wrong ?
|
|
|
|
|
Anorexic Tribble wrote: What am I doing wrong ?
One guess is that you did not call Shutdown(..) and the other thing I would note is that you are using an Asynchronous Socket in serial fashion.
Are you following a book, article or tutorial? If so please reference it.
|
|
|
|
|
I put in the Shutdown call, but that made no difference. It be honest at the moment my small routine is the only thing sending and nothing receiving (at the moment). But good idea to put Shutdown call in.
I used an async socket because eventually I will be sending and receiving in a non linear fashion.
I'm using bits and pieces from various articles. To be honest I haven't found a really good one that deals specifically with DGRAM sockets. MSDN for example mixes its description of DGRAM and STREAM sockets to provide a very confusing piece if spaghetti writing. Do you know of any good articles?
|
|
|
|
|
This place[^] has been around since the 90's and is always a good source to check out.
|
|
|
|
|
Hi All,
I have unsigned char * buffer in which some data are stored , now I want to move these all data to my CString variable for some operations.
I tried to copy but problem is that in my unsigned char * some data are padded as zero, So I hope that in CString it gets the null value so it can not copy whole data.
I tried to copy from unsigned char * to the CString using...
CString tmpMsg = CString(msg); // Here msg is the unsigned char *
Ashish Bhatt
|
|
|
|
|
|
Thanks ...
I used memcpy() as u told me, But I used like ........
memcpy(&tempMsg,(unsigned char*)msg,noOfBytes);
Then it gives me the run time Access violation error as below...
TestRTMP.exe: 0xC0000005: Access violation reading location 0x49468964.
So,plz help me , is there any other way to copying.
Ashish Bhatt
|
|
|
|
|
Does not surprise me that it gives you an access violation when doing that.
The first and foremost rule to remember is: DO NOT USE MEMCPY ON CLASSES.
Classes work independently, managing their own memory and so on. Therefore, you should use the exposed interfaces in the classes to do stuff.
In this case, you're overwriting important data in the class, not to mention that the class's internal buffer is nowhere large enough to hold your data.
As mentioned, use CString.GetBuffer(LengthOfBuffer). It returns a pointer to a buffer. Copy data using memcpy/CopyMemory. Then call CString.ReleaseBuffer(LengthOfData).
That should do the trick.
|
|
|
|
|
Actually you just need to keep the data in CString? Then use GetBuffer, and copy the data using CopyMemory. But remember, you should not perform any string operations because it is having null characters...
- NS -
|
|
|
|
|
The CString class is designed to handle C-style strings, meaning strings that are terminated with a character value of zero (AKA NUL ). It is not designed to handle raw data that contains embedded NUL characters, not double-NUL -terminated collections of strings.
Sounds like you may be a bit too comfortable with CString s...
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
i want to lern to draw a dynamic curve,but do not know how to do;
is there any good Activecontrol or methode,
my idea is, continuesly get data from a database or by some way else, then draw them on a picture, the curve should be dynamic.
thanks a lot
wuhuaiji
|
|
|
|
|
What is your problem?
In OnDraw() , you draw the curve (MoveTo() , LineTo() ) into the client rect . Whenever you get new data and fell the need to redraw, you Invalidate() .
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all. Douglas Adams, "Dirk Gently's Holistic Detective Agency"
|
|
|
|
|
hello
thanks for your answer
my problem is, how to make the curve move smoothly? it move from right to left with time going
wuhuaiji
|
|
|
|
|
Do you want algorithms to interpolate and smooth the curve-data?
Or do you want to reduce flicker on the screen?
Either case, there are articles here on codeproject and on the net.
E.G. here[^].
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all. Douglas Adams, "Dirk Gently's Holistic Detective Agency"
|
|
|
|
|
have you googled to for "Active X Control to draw a curve"
there are somany articles and active X controls related to that topic.
or if you want to develop one active X control, then i can guide you.
|
|
|
|
|
But why he must uses of Activexs control?
|
|
|
|
|
good question,
but as he said, he want to draw it on a picture.
so i thought, he would have to develop an AX to fulfil his task.
iam not sure, weather any existing control, has a mixture of both image and a graph on it.
|
|
|
|
|
Why are you so obsessed with ActiveX controls . Why not simply use a custom control ?
Do you know why ActiveX are used ? Do you know that the purpose of ActiveX is to have a control that can be used in different languages. If you just developping a C++ app, why bothering with an ActiveX when you can simply use a custom control.
|
|
|
|
|
yes you are right.
But i feel comfortable with AX because most of the times I use it in other languages also. Thats why i'm used to that.
Thank You.
|
|
|
|
|
Well, but for somebody that only wants to use a control in its C++ application, this is a bad advice to tell him to develop its own ActiveX control. Why do you want to make things even more complex to him ? Developping an ActiveX control is more complicated than developping a simple custom control.
|
|
|
|
|
yes and thanks,
i agree to your point.
|
|
|
|
|
thanks
i have googled, and now i know how to draw a static curve
but i want to draw a dynamic curve, which can move smoothly with time going
wuhuaiji
|
|
|
|