|
Have a look at the book "Visual C++ Windows Shell Programming" by Dino Esposito (Wrox Press). It's probably out of print but you should be able to get it still. Chapter 10 covers exactly this.
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"
|
|
|
|
|
Do you know where I can download those contents?
Thank you!
|
|
|
|
|
You can't legally download the book - it's copyrighted.
You can download the code examples that go with the book from http://www.wrox.com/dynamic/books/download.aspx[^]. Scroll to the bottom of the page and choose the book title.
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"
|
|
|
|
|
You are so kind!
I appreciate your help very much!
Thanks
|
|
|
|
|
Hi all,
I have a problem with an acknowledged MSDN Bug - being... using sockets in a multithread program. SP5 supposedly fixed the bug (?) but I still get asserts when using either version of the VC++ Debug libraries.
Is there new Debug libraries available or can I just modify the sockcore.cpp file and rebuild it ?
cheers
Will Beattie
whybotha69@hotmail.com
|
|
|
|
|
You can rebuild the MFC source files (there is info in MSDN on how to do this properly), but it might be easier to try to work around the bug. Did the KB article give information on how to work around the bug?
Just a tip. If you do rebuild the source files, don't put the new version in your Windows/System folder - other programs may break because of the fix. The same goes for the Release version if you rebuild that as well. If you have to distribute a modified version of the MFC library, store it in the same folder as your program.
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"
|
|
|
|
|
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???
|
|
|
|