|
|
I have a TCP server which starts a thread that loops to accept connections. The funtion the "Acceptor" is spawned from then uses WaitForSingleObject() to wait for the acceptor to return for any reason (there is actually first a suicideEvent which is triggered when user pressed CTRL-c and that even is also waited for with WaitForSingleObject(), then a flag is set to let the acceptor know that it needs to exit). This way, it works fine cause i can close the handle to the acceptor thread once WaitForSingleObject returned. But then...
The Acceptor spins every new connection off into its own clientthread. I keep a list of thread handles in a vector. So when a new thread is created, i add the handle to the vector. Now the problem is... I read on MSDN that the right way to actually terminate a thread is to let it return or call ExitThread and then to use CloseHandle() to remove it from memory.. cause if not all handles are closed, it won't be removed from memory, and i think that would be a gigantic problem for a tcp server since that way, everytime a connection is lost, the memory the thread took up is wasted and stays allocated. Cause my problem is i don't know how/when to use CloseHandle now... When a client thread terminates, i have no way to see it did this... I thought about using WaitForSingleObject or WaitForMultipleObjects again but.. i don't see how its possible to implement this because the acceptor can't be waiting to see which threads have finished...
I'll provide a basic sketch of my code (very much simplified):
void StartServer()
{
}
DWORD WINAPI Acceptor(void*)
{
}
DWORD WINAPI Clientthread(void*)
{
}
I hope i made the problem clear... i really have tried to think of several solutions but they all did not turn out well in the end. If anyone has any suggestions, please let me know.
Many thanks
Kuniva
--------------------------------------------
|
|
|
|
|
If you don't need to wait on the thread's handle, just close it straight after you create it.
|
|
|
|
|
When I build any new VC++ application, the File Save dialog, Print dialog, etc. prompts are in German.
e.g. "Save Changes to Untitled" becomes "Anderung in Unbenannt speichem" ... "untitled.txt" becomes "Unbenannt.txt"
Did I accidently select this somewhere ? or has a dll been replaced by a German version ? ...
(This is not a project setting since it affects any project I build even freshly downloaded Microsoft sample programs)
Any help to get this back into English would be much appreciated.
|
|
|
|
|
The answer ...
This was caused by the file mfc42loc.dll being present in c:\windows\system ... it was the german language version. For English systems this file should not be present.
It is interesting to delete this file since any application that uses mfc42.dll also loads this file and locks it against deletion. So need to come up in DOS mode to delete it.
|
|
|
|
|
for 16 bits or higher bitmap, doc says there is no color table inside bitmap file.
my Q is: where is its color table for those kinds of bitmaps? it should be in system, how to access it?
thx
includeh10
|
|
|
|
|
There's no palette in these cases: colors are given in RGB format, with more or less bits devoted to each color channel depending on the number of bits per pixel. Check the docs for BITMAPINFOHEADER for further info.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
How can I programmatically force a full screen console window in C?
There, wasn't hard was it.
"werewnt we going to run off and start a convent on as islandf]" -David Wulff, again on MSN while plastered...
Jonathan 'nonny' Newman
Homepage [www.nonny.com] [^]
Bob Chum Dev site [^]
|
|
|
|
|
I've googled this Usenet article[^] down, which does the trick by simulating the ALT-ENTER keystrokes. It is Delhpi, but easily translatable to C++.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Cheers, I'd already found a fake Alt Enter sequence on another site. But thanks anyway
"werewnt we going to run off and start a convent on as islandf]" -David Wulff, again on MSN while plastered...
Jonathan 'nonny' Newman
Homepage [www.nonny.com] [^]
Bob Chum Dev site [^]
|
|
|
|
|
I posted this problem before, but no one can help me...plz it's urgent!
Hi, in my MFC app I have a template class like this:
<br />
template < class BASE ><br />
class CBWnd : public BASE {<br />
public:<br />
CBWnd(){};<br />
CBWnd(LPCTSTR s, CWnd *p):BASE(s, p){};<br />
CBWnd(UINT n, CWnd *p):BASE(n, p){};<br />
CBWnd(LPCTSTR s):BASE(s){};<br />
CBWnd(UINT n):BASE(n){}; <br />
};<br />
When I derive a class from an MFC one a make this:
<br />
class CMyButton : public CBWnd < CButton > {};<br />
<br />
class CMyDialog : public CBWnd < CDialog > <br />
{<br />
CMyDialog(LPCTSTR s, CWnd *p):CBWnd< CDialog >(s, p){};<br />
};<br />
In the contructors of CMyButton and CMyDialog I need to pass the parameters (for example the template ID and the parent window of derived a dialog) to the base class (CDialog, CButton and so on...that's why all constructors).
This code works fine on Visual Studio 6 but doesn't compile on Visual Studio 2003 because this compiler check all the CBWnd constructors (VS6 check only the used ones...)and if there isn't an implementation in the other classes (CMyButton, CMyDialog ecc...)
of the called one it generates an error...
Plz help me!
|
|
|
|
|
What is an error?
When I look into yours CBWnd(LPCTSTR s, CWnd *p):BASE(s, p){}; I see it should be failing on CButton -- CButton doesn't have CButton(s, p) constructor overload...
|
|
|
|
|
Ummm... I don't have a MSVC 7.0 compiler handy, but what you say seems like a gross bug in it --only actually called member functions should be instantiated. It'd be great if you could reproduce the error in a simple program (hopefully, whitout any MFC mess, just bare classes and constructors).
In the meantime, you can try the following:
template <class BASE>
class CBWnd : public BASE {
public:
CBWnd(){};
template <typename T0> CBwnd(const T0& t0):BASE(to){}
template <typename T0,typename T1> CBwnd(const T0& t0,const T1&t1):BASE(t0,t1){}
template <typename T0,typename T1,typename T2> CBwnd(const T0& t0,const T1& t1,const T2& t2):BASE(t0,t1,t2){}
};
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi,
From my MFC program I want to pipe XML data to the internet explorer. To make it clear, if I press a button an Internet Explorer window will pop up and where I'll show the XML generated from my program.
How do I do that?
Please help
Binayak
|
|
|
|
|
You don’t necessarily have to directly integrate your program with IE to display XML. One solution is to write the XML data into a file. Then start the iexplore.exe process and give it the filename of your XML file as a parameter. IE will come up with your XML data displayed.
Lorenz Prem
Microsoft Corporation
|
|
|
|
|
I just finished writing a class which should allow you to use a CArchive with a CBlockingSocket class. The same way CArchive works with CSocket, except this one is built on CBlockingSocket which doesn't implement 16-bit functions like CSocket.
Has anyone else tried this or have any knowledge on it? If so, are there any caviates with doing it this way? I've posed my code below for your paruzal:
The class name is CBlockingSocketFile and it emulates functionality in a CFile object. Basically so you can serialize to a CArchive and have it be transmitted across TCP/IP.
Here's the header file:
#define BLOCK_SOCK_TIMEOUT 15
class CBlockingSocketFile : public CFile
{
DECLARE_DYNAMIC(CBlockingSocketFile)
public:
CBlockingSocketFile(CBlockingSocket *pNewSocket);
virtual ~CBlockingSocketFile();
public:
CBlockingSocket * pSocket;
virtual UINT Read(void * pBuffer, UINT nBytes);
virtual void Write(const void* pBuffer, UINT nBytes);
virtual void Close();
private:
virtual BOOL Open(LPCTSTR lpszFileName, UINT nOpenFlags, CFileException* pError = NULL);
virtual CFile* Duplicate() const;
virtual DWORD GetPosition() const;
virtual LONG Seek(LONG lOff, UINT nFrom);
virtual void SetLength(DWORD dwNewLen);
virtual DWORD GetLength() const;
virtual void LockRange(DWORD dwPos, DWORD dwCount);
virtual void UnlockRange(DWORD dwPos, DWORD dwCount);
virtual void Flush();
virtual void Abort();
};
And here's the source file:
IMPLEMENT_DYNAMIC(CBlockingSocketFile, CFile);
CBlockingSocketFile::CBlockingSocketFile(CBlockingSocket *pNewSocket)
{
if(pNewSocket == NULL) {
DEBUG_LOG("CBlockingSocketFile constructor: NULL pointer assignment.");
AfxThrowUserException();
}
pSocket = pNewSocket;
}
CBlockingSocketFile::~CBlockingSocketFile()
{
}
UINT CBlockingSocketFile::Read(void *pBuffer, UINT nBytes)
{
return pSocket->Receive((char *)pBuffer, (const int)nBytes, BLOCK_SOCK_TIMEOUT);
}
void CBlockingSocketFile::Write(const void *pBuffer, UINT nBytes)
{
pSocket->Write((const char*)pBuffer, (const int)nBytes, BLOCK_SOCK_TIMEOUT);
}
void CBlockingSocketFile::Close()
{
pSocket->Close();
}
BOOL Open(LPCTSTR lpszFileName, UINT nOpenFlags, CFileException* pError = NULL)
{
return false;
}
CFile* Duplicate(){return NULL;}
DWORD GetPosition(){return 0;}
LONG Seek(LONG lOff, UINT nFrom){return 0;}
void SetLength(DWORD dwNewLen){}
DWORD GetLength(){return 0;}
void LockRange(DWORD dwPos, DWORD dwCount){}
void UnlockRange(DWORD dwPos, DWORD dwCount){}
void Flush(){}
void Abort(){}
Any input would be much appreciated
Mike Ellertson
|
|
|
|
|
he he, ok I'm embarrased. I had the first code post jacked up... fault slip of the mind
Here's the corrected source file:
IMPLEMENT_DYNAMIC(CBlockingSocketFile, CFile);
CBlockingSocketFile::CBlockingSocketFile(CBlockingSocket *pNewSocket)
{
if(pNewSocket == NULL) {
DEBUG_LOG("CBlockingSocketFile constructor: NULL pointer assignment.");
AfxThrowUserException();
}
pSocket = pNewSocket;
}
CBlockingSocketFile::~CBlockingSocketFile()
{
}
UINT CBlockingSocketFile::Read(void *pBuffer, UINT nBytes)
{
return pSocket->Receive((char *)pBuffer, (const int)nBytes, BLOCK_SOCK_TIMEOUT);
}
void CBlockingSocketFile::Write(const void *pBuffer, UINT nBytes)
{
pSocket->Write((const char*)pBuffer, (const int)nBytes, BLOCK_SOCK_TIMEOUT);
}
void CBlockingSocketFile::Close()
{
pSocket->Close();
}
BOOL CBlockingSocketFile::Open(LPCTSTR lpszFileName, UINT nOpenFlags, CFileException* pError){ return false; }
CFile* CBlockingSocketFile::Duplicate() const {return NULL;}
DWORD CBlockingSocketFile::GetPosition() const {return 0;}
LONG CBlockingSocketFile::Seek(LONG lOff, UINT nFrom){return 0;}
void CBlockingSocketFile::SetLength(DWORD dwNewLen){}
DWORD CBlockingSocketFile::GetLength() const {return 0;}
void CBlockingSocketFile::LockRange(DWORD dwPos, DWORD dwCount){}
void CBlockingSocketFile::UnlockRange(DWORD dwPos, DWORD dwCount){}
void CBlockingSocketFile::Flush(){}
void CBlockingSocketFile::Abort(){}
Mike Ellertson
|
|
|
|
|
Hi
When i insert component like the MicrosoftBrowser, the studio automatically creates a wrapper class for the control, and in this wrapper class there is a function call:
CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID)
does anyone know what this does? Since i would like to implement this in pure win32api without any intervention from Microsoft Visual studio or wizard! Any constructive suggestion are highly appreciated.
Regard,
|
|
|
|
|
I want get a associated icon from a file system (for example c:\test.doc") using SHGetFileInfo function and save it in a file (for ex "C:\myicon.ico").
But GlobalSize and GlobalLock returns 0 (invalid value!!!).
I've read an IconPro example (in vs6example.exe) but I didn't found a good solution!
Please give me a good idea!
Tnk you
/******MY CODE*****/
CString nomefile = "c:\\test.doc";
HICON hGen32Icon;
HIMAGELIST hSysImageList;
SHFILEINFO shfi;
int fh;
UINT uiSize;
DWORD dwSize;
LPVOID lpGMem;
OFSTRUCT of;
hSysImageList = (HIMAGELIST)SHGetFileInfo
(nomefile,
0,
&shfi,
sizeof (SHFILEINFO),
SHGFI_SYSICONINDEX | SHGFI_SMALLICON);
hGen32Icon = ImageList_GetIcon (hSysImageList,
shfi.iIcon,
ILD_NORMAL);
dwSize = GlobalSize(hIcon); /*Don't work*/
lpGMem = GlobalLock(hIcon); /*Don't work*/
fh = OpenFile ("c:\\myicon.ico", &of, OF_WRITE | OF_CREATE);
if (fh == -1) // If NOT opened successfully.
{
MessageBox("Unable to create file", NULL, MB_OK );
}
uiSize = _lwrite(fh, (LPSTR)lpGMem, (UINT)dwSize);
_lclose(fh);
|
|
|
|
|
Enza wrote:
dwSize = GlobalSize(hIcon); /*Don't work*/
lpGMem = GlobalLock(hIcon); /*Don't work*/
What is hIcon ? I assume this is supposed to be hGen32Icon . GlobalSize() is probably failing because hGen32Icon is not a global variable memory object.
|
|
|
|
|
sorry, the HICON is hGen32Icon...
How I can declare a global variable memory object?
tnk
|
|
|
|
|
I have software that "Commits" 2KB with every call to fopen(). I have tried the following with the following results:
<br />
<br />
if (fp = fopen(filename, "cwt"), fp != NULL)<br />
{<br />
}<br />
else<br />
perror( ... );<br />
<br />
<br />
<br />
if (h = _open(filename, _O_CREAT|_O_TRUNC|_O_WRONLY|_O_TEXT), h != -1)<br />
{<br />
}<br />
else<br />
perror( ... );<br />
<br />
Any thoughts? Thanks ...
|
|
|
|
|
jmf314159 wrote:
if (fp = fopen(filename, "cwt"), fp != NULL)
{
What is this??
I'd like to think the majority of people would write:
if ( (fp = fopen(filename, "cwt")) != NULL )
open/fopen etc. will fail if the file is marked r/o and you are trying to write to it or create it. Or if the file is locked by another process, or the path is invalid etc. You can test errno for specific details of the error.
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
Thanks for telling me what you would like to think.
I thought I had made clear that ...
(a) the anomaly was induced by the addition of the 'c' switch, and
(b) perror(), which maps errno to text, reported "no error" even though fopen() returned NULL.
This suggests that the problem was not file attributes, file locking, and/or file specification, and that further interrogating errno would achieve little. Thanks anyway.
|
|
|
|
|
jmf314159 wrote:
Thanks for telling me what you would like to think.
Its comments like this that realy make me wonder why I spend time trying help my fellow programmers sometimes.
"c" can't be the first character in the mode string. A quick bit of digging showed this.
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|