|
Thanks Ryan,
I have done heap of hunting on this problem which basically boiled down to creating a Socket in one thread and then trying to use it in another thread.
MFC does not allow sockets to be passed between threads or so it appears. I don't know if this is a bug as suggested by their bug fix "Q193101"
"SYMPTOMS
When using MFC sockets in secondary threads in a statically linked MFC Visual C++ 6.0 application, an unhandled exception occurs.
CAUSE
The reason for the unhandled exception is that an object of type CMapPtrToPtr pointer, pointed to by m_pmapSocketHandle, is never created."
I will keep trying.
cheers
Will Beattie
|
|
|
|
|
whybotha69 wrote:
MFC does not allow sockets to be passed between threads or so it appears. I don't know if this is a bug as suggested by their bug fix "Q193101"
No other MFC object that relies on a Windows HANDLE can be passed between threads, so I assume sockets are the same, ie. I believe this is the correct behaviour, not a bug.
The KB article only shows how to prevent the unhandled exception error that occurs. It doesn't say that sockets can be used in multiple threads. I'm certain that a MFC socket can only be used in one thread.
Did you try their solution to prevent the error?
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
Hi Ryan,
Yes I tried their fix .. no luck. My code works as required in Release but Asserts when in Debug mode.
As to MFC Sockets and multithreading the jury is undecided. This article has a section near the bottom called "CSocket Objects and Multithreading".
http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/dnarpic/html/msdn_wsockets.asp
Thanks Will
|
|
|
|
|
whybotha69 wrote:
creating a Socket in one thread and then trying to use it in another thread.
Hi, I hope you know that in order to use the MFC's socket object between two threads you should do a Detach() on the object which will give you a handle of type SOCKET, and then Attach() using that handle in the other thread. Which is basically:
- Call Detach() on the object in order to obtain the SOCKET handle
- Delete the detached object
- Create the (CSocket or CAsyncSocket) object in the second thread
- Attach the SOCKET handle to the newly created object using Attach()
The bug mentioned in Q193101 is not about this exactly, it's about creating and using sockets objects in secondary threads.
|
|
|
|
|
Im new to C++ i wanna teach my self, anyone got any tutorials that a simple to understand but also quick to learn and usful tutorials, coz im looking into making a mod for a game, so i need to know code in that area
cheers
ps i dotn care what version of Microsoft C++ it is
Half Life 2 Modification:
New Dawn 0.01% Complete
|
|
|
|
|
|
Is it possible to:
LPDIRECTDRAWSURFACE lpSpriteSurface[];
Then as the region map dictates that a certain creature type is in the area...
Check to see if the pointer is valid...and if not, create it and load it with the frames of animation required by that creature type.
If the pointer is valid, then just return it to the SpriteManager as that sprites source surface.
Do I have to dictate the number of array elements ?
LPDIRECTDRAWSURFACE[MaxNumberOfSpriteSurfaces];
and then initialise them ?
for (int i=0; i
|
|
|
|
|
Anonymous wrote:
Is it possible to:
LPDIRECTDRAWSURFACE lpSpriteSurface[];
No, you will need to specify the size, however you can use a vector to track these as you create new LPDIRECTDRAWSURFACE objects. To do it as you have listed you would also have to use {} to specify the values of the individual objects prior to your semi-colon.
-Nick Parker
|
|
|
|
|
The size of an array must be known at compile time, so this is ok
LPDIRECTDRAWSURFACE lpSpriteSurface[MaxNumberOfSpriteSurfaces];
if MaxNumberOfSpriteSurfaces is a constant or #define.
--Mike--
"So where does that leave us? Well, it leaves us right back where we started, only more confused than before." -- Matt Gullett
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
|
|
|
|
|
i know that using netmessagebuffersend api can do it in windows NT/2000/XP.
but how can i do that in windows 98?
thanks.
Thanks for reply!
|
|
|
|
|
http://www.codeproject.com/useritems/FakeSend.asp[^]
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
thank you.
and i have done it!
|
|
|
|
|
You're welcome
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
I have displayed Unicode strings in CEdit derived controls successfully but now when I want to display the same string in a CRichEdit control, it displays a '?' character for each unicode character. I think richedit control takes only ascii characters by default.
Is there any way to let rich edit control accept unicode strings.
I can't even copy the string from edit control and paste into the richedit control. It still displays alot of '?' characters.
Example:
<br />
wchar_t strUnicode[10];<br />
strUnicode[0] = 0xfebd;<br />
strUnicode[1] = '\0';<br />
<br />
GetEditCtrl().SetWindowText (strUnicode);
<br />
GetRichEditCtrl().SetWindowText (strUnicode);
|
|
|
|
|
Please read this code and the question asked at the end.
class Point
{
private:
int x, y;
public:
Point();
Point(int x, int y); //constructor
int getX(); // getter
int getY(); // and
void setX(int x); // setters
void setY(int y); // functions
bool operator==(Point p) const; //overloaded == operator
~Point(); // destructor
};
class Box
{
private:
Point points[40];
public:
Point findPoint(Point p); //what should be the prototype of this function
};
Point Box::findPoint(Point p)
{
Point pTemp;
for(int i=0; i<40; ++i)
{
pTemp = points[i];
if( pTemp == p )
return pTemp;
}
return; // what to return here ?????????????
}
Look at the findPoint function. The responsibility of this function is to search in arrary
for the Point given and if function finds this Point, return it, otherwise if function does
not find the Point given it should return NULL. But I am unable to do it. I can achieve this
by changing the prototype of function like this
Point *findPoint(Point p);
butt I dont want to do this because it will break the conecpts of OOP and give access to
private data memeber.
The problem is if I return by value then I cant return NULL, so in user class or function,
I can not know whether the Point is found or not. and if I return the pointer, then I give
direct access to private data member.
Anybody help please !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
|
Why are you returning a 'Point' anyway?
If it's found, they've already supplied the point in the first place, so the return result doesn't give them anything new except another point that matches the one they supplied.
Maybe a 'bool HasPoint( Point point )' method may suit your needs, or you could return an integer index into the array (and -1 if it doesn't exist)?
If you really do want to return a point for some reason then how about:
<br />
class Box<br />
{<br />
private:<br />
Point points[40];<br />
<br />
public:<br />
bool FindPoint( Point search, Point &result );<br />
};<br />
n!
|
|
|
|
|
Thanks for the reply and reminding me my mistake.
Now consider the situation.
what if findPoint function now has this prototype
Point Box::findPoint(int x)
{
Point pTemp;
for(int i=0; i<40; ++i)
{
pTemp = points[i];
if(pTemp.getX() == x)
return pTemp;
}
return; // what to return here.
}
The purpose of the findPoint function is to find a Point which has its x data member equal to x provided. So, what to return
if the if condition not satisfied.
|
|
|
|
|
Ahh ok, then I'd pass in a reference to be filled in and return a bool.
<br />
bool Box::FindPoint( int x, Point &result ) const<br />
{<br />
for ( int i = 0; i < 40; ++i )<br />
{<br />
if ( points[i].GetX() == x )<br />
{<br />
result = points[i];<br />
return true;<br />
}<br />
}<br />
return false;<br />
}<br />
n!
|
|
|
|
|
Can we not use Java style here like this
this code fragment is of JAVA language
Point findPoint(int x);
so, in this case we can return null (cause null is a keyword in java) and also user defined types are reference types in java. My question now is
isnt there any alternative in C++ to this JAVA style other than provided by you???
|
|
|
|
|
All objects in Java are reference types, you're not returning by reference you're returning by value here. C++'s class model is different to Java, the closest built in primitive to a Java reference (which may be null, as you said) is a pointer (C++ references may not legally be null), which you said you'd like to avoid.
The alternatives I can think of at the moment are:
Throw an exception, of course, but that's a bit heavy handed for a failed search
Return an integer index (with -1 meaning not found) and provide an index operator.
Write a RefResult templated wrapper and return one of those, but that doesn't give you anything more than you'd get returning a pointer (except more code).
My previous suggestion (returning bool).
I can only say that C++ isn't Java and if you prefer the Java style then use Java?
n!
|
|
|
|
|
Thank you very much "n!"
I have decided to use your earliest suggestion (return bool). Your replies were really very much informative to me. I was really confusing Java and C++ memory management. This confusion is lowered very much by your replies.
Thank you.
|
|
|
|
|
You can do several things. First I would change it to:
bool findPoint( Point& ptFound, Point p );
Another option is to keep your original code and set the returned Point to a value that would never occur in practice. eg. -1,-1. Then you could write:
IsPointValid( ptFound = findPoint( point ) )
You can and should also make the function const. You can also return a const ptr, which doesn't break your OOP rule. Solution 3. Use const wherever possible.
There you - pick 1.
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
Hi , hwo can i get a drive size,
Please reply,
Thanks
|
|
|
|
|
|
Have I lost my mind or is there no profiler in the Visual Studio .NET IDE?
If it is there, where is it? If not, does anyone know of a good one?
Thanks!
Marcus Spitzmiller
"Why must life be so hard? Why must I fail at every attempt at masonry?" - Homer
|
|
|
|