|
You secondary thread may possibly post messages to the primary one and let the latter do socket processing.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
...or you can stop using CSocket (it's really only a useful class for the most
basic socket application) and use CAsyncSocket instead.
If you'll be using the same socket from different threads, you'll want to use
events instead of window messages for socket notifications.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
AmitCohen222 wrote: if I understand correctly it is since the only thread allowed to use this socket is the one created it
Not exactly, it's got to do with a bug in MFC. See knowledge base Q193101[^] - I had a similar problem and calling AfxSocketInit() in each thread fixed it.
|
|
|
|
|
That bug appears only when linking statically, and is probably not the cause of the problem.
For a solution on using a CSocket object in a thread different from the thread that created it, see "How to pass a socket connection between threads in an MFC application in Visual C++" at http://support.microsoft.com/kb/175668[^]. Basically, you need surround the thread hand-off with calls to CAsyncSocket::Detach() and CAsyncSocket::Attach() .
Mike
|
|
|
|
|
Oh yes, I missed that point. You do need to detach the original socket.
|
|
|
|
|
plz help me with this code...
<br />
int a = 0;<br />
int p = 2;<br />
int q = 3; <br />
<br />
a += p ? q : 0;<br />
what does the last line mean?
i need to describe it into normal if-then-else form...
thanks all...
From Indonesia with love..!!
|
|
|
|
|
the form p ? q : 0 is
expr1 ? expr2 : expr3
means evaluate expr1. If it is not zero, the value of the whole thing is expr2; otherwise the value is expr3.
so, substituting 0 += 2 ? 3 : 0
since 2 ! = 0
0 += 3
a = 3
...
'g'
|
|
|
|
|
The code maybe translated into (see documentation [^]):
if ( p != 0 )
{
a = a + q;
}
BTW you really need a good C/C++ tutorial.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
yaa...
you may be right...
thank to you guys for the help...
From Indonesia with love..!!
|
|
|
|
|
Hi,
i am using CListCtrl in Icon-mode. I am setting the item positions manually with ListView_SetItemPosition32().
I am having a strange bug, y-positions between 0xf000 and 0xffff are not set properly !
Is this a known bug or am i doing something wrong ?
|
|
|
|
|
Could you please post the relevant code?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
The code is pretty easy, i did this inside my CListCtrl class:
...
ListView_SetItemPosition32(this->m_hWnd, 0, 0, 0xf100);
POINT p;
GetItemPosition(0, &p);
...
and you will see that p doesn't contain the values i set before!
|
|
|
|
|
Did you use of debugger?
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
Debugger doesn't help much, because the item-position is sent via SendMessage to ListCtrl.
So its something going wrong inside windows api and not a fault of mfc.
|
|
|
|
|
This simple code fails and there is no extended error message.
The BITMAP data is there and correct.
CBitmap *bmp = new CBitmap();
if(!bmp->CreateBitmapIndirect((BITMAP * ) m_Doc->m_lpBi))
{
.....
PS Ignore -> it is "->" in original!!!
Any constructive suggestion on how to debug this is appreciated.
Thanks for reading.
Cheers Vaclav
|
|
|
|
|
Did you install the CRT and MFC source code? If so, you can step into the MFC implementation code (so long as you're working with a Debug build) and find what Win32 call is failing. That might give you some more information.
Only thing I can think of, apart maybe from finding some sample code, to see if there's anything you're missing?
|
|
|
|
|
This fails in otherwise working MFC document / view program.
And no I cannot step into the API.
Thanks
|
|
|
|
|
May be GetLastError() can give you some hints. Just add @err,hr to the watch window to get the last error description.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Vaclav_Sal wrote: if(!bmp->CreateBitmapIndirect((BITMAP * ) m_Doc->m_lpBi))
I'm suspicious about that cast - why did you need to cast to a BITMAP*?
Based on the limited info, I have a feeling you're not passing the correct structure...
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark,
As always, you are correct!
BITMAP and BITMAPINFO are definitely different!
Here is my wrong code
if(!m_lpBmpInfo)
{
m_lpBmpInfo = (BITMAPINFO *)( new char[m_vfs]);
((LPBITMAPINFOHEADER)m_lpBmpInfo)-&gt;biSize = sizeof BITMAPINFOHEADER;
}
VERIFY(m_lpBmpInfo);
// document bitmap header pointer initialization - do only once in the class
if(!pDocument-&gt;m_lpBi)
{
pDocument-&gt;m_lpBi = (BITMAP *)( new char[m_vfs]);
((LPBITMAPINFOHEADER)pDocument-&gt;m_lpBi)-&gt;biSize = sizeof BITMAPINFOHEADER;
}
VERIFY(pDocument-&gt;m_lpBi);
As always - the de-reference symbol is shown as -&gt; should be "->"
Now I need to figure out what data is missing from BITMAP. Should be easy.
Thanks Mark
Have a great holidays.
Vaclav
|
|
|
|
|
If you need a HBITMAP from a BITMAPINFO or BITMAPINFOHEADER, you may
want to look into CreateDIBitmap() or CreateDIBSection().
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I have a simple base class that holds id's for use in sorting other classes. It is a non-templated class in an single hpp file ( indexedObject, see below )
class indexedObject
{
public:
indexedObject() : _mID(BAD_DB_ID) {}
indexedObject(dbID id) : _mID(id) {}
~indexedObject();
dbID getID(void);
void setID(dbID id);
bool operator<(const dbID& param) const;
bool operator>(const dbID& param) const;
bool operator==(const dbID& param) const;
bool operator!=(const dbID& param) const;
protected:
dbID _mID;
}; // indexedObject
inline indexedObject::~indexedObject() { _mID = BAD_DB_ID; }
inline dbID indexedObject::getID(void) { return _mID; }
inline void indexedObject::setID(dbID id) { _mID = id; }
inline bool indexedObject::operator<(const dbID& param) const
{
return (_mID < param);
}
inline bool indexedObject::operator>(const dbID& param) const
{
return (_mID > param);
}
inline bool indexedObject::operator==(const dbID& param) const
{
return (_mID == param);
}
inline bool indexedObject::operator!=(const dbID& param) const
{
return (_mID != param);
}
I have a templated class that inherits from the base class.
template <class _Ty> class fwdCurve : public indexedObject, public broadCaster
{
blah blah...
}
When I try to define setID in the derived class
template<class _Ty> void fwdCurve<_Ty>::setID(dbID id)
I get a C2244: indexedObject::setID : unable to match function definition to an existing declaration
I am able to work around this by declaring setID() in the derived class definition and explicitly calling the base class method but why is this happening?
I have VS 2005 with SP1 and hotfix KB930859 installed.
|
|
|
|
|
mjackson11 wrote: When I try to define setID in the derived class
template<class _ty=""> void fwdCurve<_Ty>::setID(dbID id)
I get a C2244: indexedObject::setID : unable to match function definition to an existing declaration
Yes - this is the way C++ works...you need a method declaration in the class before you can define it. The declaration in the base class does not change this.
mjackson11 wrote: I am able to work around this by declaring setID() in the derived class definition and explicitly calling the base class method but why is this happening?
If you just want to call the base classes implementation, then you need no method definition or declaration in the derived class.
What are you actually trying to accomplish?
|
|
|
|
|
Sorry, to be more specific, I tried to implement setID() in the derived class without putting setID in the class declaration. That's when it threw the error. If I define setID in the derived class declaration, when I implement it, it does not call the base class setID method. Seems like the compiler is defining them as two different methods instead of the derived class inhereting.
|
|
|
|
|
mjackson11 wrote: If I define setID in the derived class declaration, when I implement it, it does not call the base class setID method. Seems like the compiler is defining them as two different methods instead of the derived class inhereting.
Yep, that's the way most (if not all) OO languages work. The point is that if you do want to call the base classes method, you can very easily. However, if the language automatically called the base classes methods and you didn't want that to happen, you're stuffed.
Anyway - in conclusion, what you've described is the way C++ is meant to work.
|
|
|
|