|
hello
i have used directly the socket i want to use the
socket ActiveX available ("WinSock").
Do have any idea.
the main reason behind using an acitveX is that the
response from the client is not guranteed , so when
do listen(client); many times my application hangs-up
any solution do u know
thank you
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
|
|
|
|
|
I want to write a program that supports mutilanguage. so I read strings
in a ini file. who can help me ?
Just relax
|
|
|
|
|
I ve got a socket listening and accepting on another socket, how would I copy 2nd socket to a 3rd socket, so I would be able to close the 2nd socket...
// create temp and permanent sockets
CSocket tSocket, pSocket;
// accept listening onto temp socket
m_pListenSocket->Accept(*tSocket);
tSocket->Init();
// copy temp to perm
pSocket->Attach(*tSocket); or pSocket=tSocket;
produces the same.
pSocket->Init();
pSocket will pass data now,
// close the temp socket
tSocket->Close();
now pSocket won't pass data.
any helps always appreciated.
shotgun
|
|
|
|
|
afaik u would have to send a message to the client telling it to disconnect from the current socket and reconnect at a socket u pass to it in the message ... that way u can hand off clients to arbitrary servers and sockets
this is usually how i write servers who accept the client connection and authenticate them before handing them over for the actual data transfer
hth
"there is no spoon" {biz stuff} {about me}
-- modified at 23:52 Tuesday 18th October, 2005
|
|
|
|
|
CSocket pSocket,tSocket;
//This will Attach the Socket handle
pSocket.Attach(tSocket.m_hSocket);
//Donot Do any other operation b/w these 2 Lines on the Socket
//This will detach the Socket Handle in the m_hSocket data member of tSocket and set to NULL
Socket handle=tSocket.Detach();
|
|
|
|
|
hello
i have used directly the socket i want to use the
socket ActiveX available ("WinSock").
Do have any idea.
the main reason behind using an acitveX is that the
response from the client is not guranteed , so when
do listen(client); many times my application hangs-up
any solution do u know
thank you
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
|
|
|
|
|
Hi,
I had the following code to close my dialog application when ESC key is pressed. But WM_KEYDOWN is not invoking at all.
What am I missing here....
case WM_KEYDOWN:
{
switch (wParam)
{
case VK_ESCAPE:
ExitApp(hDialog);
break;
}
return TRUE;
}
|
|
|
|
|
I think WM_CHAR is the only one that recieves the ESCAPE key.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Ann66 wrote: I had the following code to close my dialog application when ESC key is pressed.
Doesn't the Esc key do this by default?
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
I have an OnPaint function and it's being called over and over and after a while, it throws a resource exception by simply saying:
A required resource was unavailable.
I have no idea what that means beyond what it says but it's happening sometime in the OnPaint function after it's run a couple thousand times. I only get the "CPaintDC dc(this);" at the top of the try block (to catch exceptions) and then I draw or not draw with if statements later. Am I allocating the drawing context without deallocating it, do I need to release the 'dc' variable or something to the system?
Under the CPaintDC constructor, it says this as a remark:
An exception (of type CResourceException) is thrown if the Windows GetDC call fails. A device context may not be available if Windows has already allocated all of its available device contexts. Your application competes for the five common display contexts available at any given time under Windows.
Is that affecting me? If so, how I do rectify this?
|
|
|
|
|
It sounds to me like your paint handler is leaking resources. Could you post the code ? Do you clean up the brushes/bitmaps/DCs etc that you use ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
The code is complex, but here's the short of it:
try {<br />
CPaintDC dc(this);<br />
if ((thread == NULL) && (files != NULL)) {<br />
dc.Rectangle(x, y, x + 300, y + nTextHeight + 4);<br />
COLORREF OldColor = dc.SetTextColor (RGB(192, 192, 192));<br />
dc.SelectObject (new CBrush(RGB(192, 192, 192)));<br />
sMsg.Format("%s, %s", obj->GetName(), obj->GetStringFilesize());<br />
dc.TextOut(x + 2, y + 2, (LPCTSTR) sMsg);<br />
dc.SetTextColor(OldColor);<br />
dc.SelectObject (new CBrush (RGB(255, 255, 255)));<br />
}<br />
<2 more sections like the above exist with different if statement tests><br />
} catch (CResourceException * e) {<br />
e->Delete();<br />
thread->SuspendThread();<br />
char * lpszMessage = new char[128];<br />
e->GetErrorMessage(lpszMessage, 128, NULL);<br />
MessageBox(lpszMessage, "Critical Error", MB_ICONSTOP);<br />
delete[] lpszMessage;<br />
thread->ResumeThread();<br />
}
That's the gist (and most complex) part of it. I have 3 blocks like the if statement above, the first two are rarely used, but the third is heavily used when a particular thread is running. The heavily used if statement is similar in layout to the above but it draws a text element and pie, both correspond to a progress display of the thread the code mentions. I was handling the CBrush's by new'ing and delete'ing them manually but it threw runtime errors when delete'ing the CBrush's, it said a "pure virtual function call" or something like that. I don't do any clean up, I just get the dc from CPaintDC and then draw, that's it. I figured I didn't need to deallocate the drawing context because I was using it in this method, instead of using a handle to a drawing context with GetDC/ReleaseDC.
|
|
|
|
|
LighthouseJ wrote: dc.SelectObject (new CBrush(RGB(192, 192, 192)));
This is a resource leak. you need to create a brush as a variable, and when you call selectobject, you need to grab the brush it returns. Then you need to restore the original brush, and destroy the brush you created.
LighthouseJ wrote: dc.SelectObject (new CBrush (RGB(255, 255, 255)));
Ditto. I assume this is supposed to restore the original brush color, but you need to actually restore the original brush.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I actually did that originally but I got the aforementioned error because I was trying to free memory from another threads heap. I changed it like below and no error shows up so I guess it's cleared up but I have to clean up the code more because it was opened up to try and fix this with other methods.
CBrush * grey = new CBrush (RGB(192, 192, 192));<br />
CBrush * black = new CBrush (RGB(255, 255, 255));<br />
dc.SelectObject (grey);<br />
<br />
< drawing done here ><br />
<br />
dc.SelectObject(black);<br />
<br />
delete grey;<br />
delete black;
|
|
|
|
|
LighthouseJ wrote: I actually did that originally but I got the aforementioned error because I was trying to free memory from another threads heap.
Well, it's the way it needs to be done, you need to work out those threading issues, I guess..
LighthouseJ wrote: CBrush * grey = new CBrush (RGB(192, 192, 192));
CBrush * black = new CBrush (RGB(255, 255, 255));
dc.SelectObject (grey);
< drawing done here >
dc.SelectObject(black);
delete grey;
delete black;
This is wrong.
CBrush * grey = new CBrush (RGB(192, 192, 192));
CBrush * black = dc.SelectObject (grey);
< drawing done here >
dc.SelectObject(black);
delete grey;
You need to grab the brush that SelectObject returns, and put it back when you're done.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I was trying to capture the outgoing brush but when I delete it, I got the error saying the memory I was deallocating wasn't mine. So, I just don't delete the black brush? Isn't that leaking memory?
|
|
|
|
|
LighthouseJ wrote: I was trying to capture the outgoing brush but when I delete it, I got the error saying the memory I was deallocating wasn't mine.
Correct. You can't delete it, you need to select it back into the DC in order to avoid a leak.
LighthouseJ wrote: So, I just don't delete the black brush? Isn't that leaking memory?
No, because you don't create a black brush, and because the brush in question is left in the control of the DC, as it was at the start.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Have a look at CDC::SaveDC() ( There is also an excellent article by Joe Newcomer on this site about SaveDC(), look it up ) and also why not just use local GDI objects that go out of scope when you are done with them? saves having to mess around with new and delete.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
|
I'll read that tonight. I haven't optimized the program for space and efficiency yet but one thing I did was to put the grey brush into the child view to be created once on construction, then used repeatedly, and deleted on deconstruction. I also have to figure out a better flow to my program but that's on my shoulders. I'm trying to optimize drawing because it's definitely the slowest part of my program.
|
|
|
|
|
I know how to do that in visual c++ NET but I have to use visual c++ 6.0 only. so how can I convert byte array to image(or binary) that will insert data to sql database.
STDMETHODIMP CModels::AddPicture(IUnknown* pIUnkConnection , byte* byteImage)
{
_ConnectionPtr spIConnection;
CConnection connection;
connection.GetConnectionToDB(pIUnkConnection, &spIConnection);
_bstr_t bstrCommand = "INSERT INTO MODEL VALUES ('" First Picture "', "', ?????(byteImage)how can I can convert byte array to image???)";
THROW_COM_ERROR(spIConnection->Execute(bstrCommand, NULL, adExecuteNoRecords));
bytes[] convert to image(binary)
Remember I cant use C++ .NET at all
use Visual c++ 6.0 only
|
|
|
|
|
Using Visual C++ 6, running some C++ code which allocates & frees some memory, usually if I've got any problems with unallocated/unfreed memory I'll get access violations, exceptions, but this time I'm getting a heap error I've never seen before:
HEAP : dedicated (0000) free list element 6fa9ae8 is marked busy
What's the difference between this and an access violation / exception?
I think it means I'm running of of heap space, as it can happens at any memory allocation in my code, but it doesn't look that way from the amount of memory my program is using?
Any tips of finding out the cause of this?
|
|
|
|
|
Tam987654321 wrote: Using Visual C++ 6, running some C++ code which allocates & frees some memory...
Are you using the new and delete operators?
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
Thanks for trying to help, I managed to fix my code.
It was new & delete operators I was using, the problem was I was overrunning a buffer.
I discovered the cause by using _heapchk to check the status of the heap, I took the code from the following link and put it at different parts of my code to find out when the heap was getting corrupted.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt__heapchk.asp
|
|
|
|
|
Hi,
I am getting boolean value from store procedure.When flag is set, it fill value 255 otherwise 0. It should be 1/0. When i tried to declared varaible type bool no data is coming and it is showing garbage.Can you please help me.
Thank
|
|
|
|
|
simple:
suppose c is what you get from the stored proc and b is the boolean you want.
just do this: b = c & 1;
cast (c & 1) to bool if needed
|
|
|
|