|
I need have my controlling thread function for a second thread as a member function of a class. From what I've found out, this means that the function must be declared staticly. There was a good discussion about this previosly HERE. However what I need, is to be able to access the class's non-static member variables, which the above linked topic discusses, but does not provide a solution. Is this possible?
|
|
|
|
|
Well, yes - the usual trick is to pass a pointer to the class as the LPVOID parameter of the threadproc function. Then, inside your class, you can cast it as a pointer to the class and you have access. Kind of like making calls with an explicit this pointer, but it works.
|
|
|
|
|
|
Usually I implement it as follows:
class CMyClass
{
static UINT _MyThread( LPVOID pParam )
void MyThread();
void StartThread();
};
UINT CMyClass::_MyThread( LPVOID pParam )
{
reinterpret_cast<CMyClass*>(pParam)->MyThread();
return 0;
}
void CMyClass::MyThread()
{
}
void CMyClass::StartThread()
{
AfxBeginThread( _MyThread, reinterpret_cast<void*>(this) );
} Regards,
Thomas
I am a signature virus!
Help me spread and copy me to your sig!
|
|
|
|
|
Where can I find the C++ source code (MFC or ATL) of an ActiveX control that supports OLE Drag and Drog?
|
|
|
|
|
I am writing an application that makes extensive
use of an unlimited undo / redo mechanism, and I've also added the ability for my users to delete files off the hard drive through my gui. I am using the following code to delete a file and send it to the
recycling bin:
SHFILEOPSTRUCT OpInfo;
OpInfo.hwnd = ::AfxGetMainWnd()->m_hWnd;
OpInfo.wFunc = FO_DELETE;
OpInfo.pFrom = FilenameStringRaw;
OpInfo.pTo = NULL;
OpInfo.fFlags = FOF_ALLOWUNDO | FOF_FILESONLY | FOF_NOCONFIRMATION |
FOF_SILENT | FOF_NOERRORUI;
int result = ::SHFileOperation(&OpInfo);
MHogDeleteArray(&FilenameStringRaw);
Now that all works fine. The problem is---how do I let the user UNDO the
delete programmatically? The flag FOF_ALLOWUNDO suggests that this
should be possible, but I can't figure out how. Been looking everywhere.
Thanks.
Matus
====================================
Check out Aephid Photokeeper, the POWERFUL digital
photo album solution at http://www.aephid.com
|
|
|
|
|
http://www.msdn.microsoft.com/msdnmag/issues/01/04/c/c0104.asp
Good Luck.
Carlos Antollini.
|
|
|
|
|
Thanks, but unfortunately, this msdn article does exactly what I've already done...
I know how to send files to the recycling bin no problem, but I'm still clueless how to get them BACK.
I've found the SHGetSpecialFolderLocation() api function, which I was hoping that perhaps, by specifying CSIDL_BITBUCKET as the nFolder parameter, I would be able to get a path to the hidden recycling bin directory. But even if I could access it, how would I know what the name of the file was after it was deleted? (I'm sure Microsoft renames it so that you can delete files with the same name and still recover them.)
this sucks.
swine
|
|
|
|
|
Hi,
I have a doubt, though it might seem silly to many. But, please help.
My doubt is in the following code
class Base
{
protected:
int i;
public:
Base(){ printf("Base Constructor\n");}
void MyPrint(){ printf("Value of i(Base) = %d",i); }
};
class Derv: public Base
{
public:
Derv(){ i = 20; }
};
//a global function
void GlobalPrint(Base objB) { objB.MyPrint(); }
void main()
{
Derv Objd;
Base Objb = Objd;
ObjB.MyPrint(); // in this case what happens is that the base class version of MyPrint is called. But the value of "i" is a junk
}
// but if my main is something like this
void main()
{
Derv Objd;
GlobalPrint(Objd); // in this case the base class verion of MyPrint is called inside the
// global function. but the value of i is 20.
}
Can u please explain whats happening. I thought in the first implmentation also an implicit conversion should take place and value of i should be 20. But its not. So please help me
Regards,
Ganesh.M.Ramaswamy
|
|
|
|
|
I have tried this with my VC++ 6.0 compiler and it works just fine!
I see no difference between the two secnarios! In each case you're using the copy constructor to instatiate the objects, even in your GlobalPrint function, the object is being passed by value and this implies that a new object is being constructed using the copy ctor. And the Copy Ctor is the default provided by the compiler!
Check your code... maybe you have something else that is causing the problem!
|
|
|
|
|
Does anybody know how to fix this error in Visual C++? I'm getting it on one of my functions in the class view. The function implementation exists and is in the header obviously. I tried rebuilding the class wizard file in hopes it would reassociate but it didn't work. It was working for a while then just stopped. Thanks for the help.
Jamie
|
|
|
|
|
There r two problem due to which I faced the same issues. First is that the Visual C++ compiler sometimes deletes the CPP file from the back.
Another is that in the funcion above there can be an extra closing bracket which causes the Wizard not to get the function.
Third problem can occur due to the type of parameters. That I can hopefully tell if I see the code.
|
|
|
|
|
I often play the game "Quake3". When I looked at the game-files I saw that there were also normal *.c files
here a piece of code from one of these files:
[code]
//===========================================================================
#include "game.h"
#include "match.h"
//entered the game message
MTCONTEXT_ENTERGAME
{
//enter game message
NETNAME, " entered the game" = (MSG_ENTERGAME, 0);
} //end MTCONTEXT_ENTERGAME
//initial team command chat messages
MTCONTEXT_INITIALTEAMCHAT
{
//help someone (and meet at the rendezvous point)
"(", NETNAME, ")", PLACE, ": help "|" meet ", TEAMMATE, " near "|" at ", "the "|"checkpoint "|"waypoint "|"", ITEM = (MSG_HELP, ST_NEARITEM);
[/code]
these files seem to be loaded at runtime by quake3.
Now my question?
How is it possible to load source-files at runtime and execute their code?
thanks in advance
|
|
|
|
|
To do this would require that the destination machine has a C++ compiler available to it. This Quake file looks to me like a data file, which is a different kettle of fish entirely.
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|
|
Carmack (the creator of Quake3) took LCC (a free open source C compiler) and used it as the base of an interpreter. The game code is loaded at startup and runs interpreted inside of a virtual machine inside of Quake3. It's a lot like Java but using C as the starting point. I think Carmack said it incurrs about a 10% performance hit which is acceptable and allows Quake3 to be ported easily to multiple platforms. Since the game logic is portable you can write a mod for the PC version and it will work automatically on Mac and Linux. This also allows him to exclude a lot of stuff from the language like access to local files on your PC. The game code runs in a sort of sand box with limited system interaction. You can also take the game logic code and compile it nativly on each system. For the PC you'd end up with a .DLL that's loaded at run time. You can get back your 10% speed drop this way but of course the DLL isn't portable to other platforms.
If you hunt down his .plan files you can read all about it.
|
|
|
|
|
Thanks for the detailed answer.
does it mean that these files are being compiled during gameplay with lcc?
Where can I find the .plan-files you mentioned?
How difficult do you think is it to realize something comparable in my own apps?
thanks
|
|
|
|
|
MFC code (or Win32 code that works in MFC) that checks if there is a CD-ROM installed!
/*
BETA
*/
|
|
|
|
|
Move through all drives and call the win32 function GetDriveType(DRIVE_CDROM) on each drive.
This should work.
Gero Gerber
|
|
|
|
|
DWORD dwDriveMask = GetLogicalDrives();
char szDir[4];
szDir[1] = TEXT(':');
szDir[2] = TEXT('\\');
szDir[3] = 0;
/* enumerate all logical, fixed drives */
for(int i=0; i<max_drives; dwdrivemask="">>= 1, i++)
{
// if logical drive exists
if (dwDriveMask & 0x01)
{
szDir[0] = TEXT('A') + i;
if (GetDriveType(szDir) == DRIVE_CDROM)
{
//do whatever you like to do
}
}
}
|
|
|
|
|
I have my program in the system tray or invisible from anything.
I want to press eg. F12 then for eg. a message box appears!
I know code for this when the app is in FOCUS! but when it's invisible... may be you
wrtiting in Word, and then you want to press F12 and TADA (Something happens!)!
MFC CODE!!
/*
BETA
*/
|
|
|
|
|
Try SetWindowsHookEx.
Afaik no MFC code to do this.
|
|
|
|
|
I am writing a program to customize your desktop using the Windows Plus! Settings. The only way I could find to do so is to change the registry settings manually and then do a ChangeDisplaySettings with CDS_UPDATEREGISTRY as a flag.
This 'tricks' the settings into being active. There's got to be a better way to do this! Anyone know how to change these settings more efficiently? Does there exist an API that allows you to refresh your display without making a "ChangeDisplaySettings" type change?
OS: Windows NT
Thanks!
|
|
|
|
|
I'm attempting to use a bitmap of a grey shaded sphere as sort of a stamp. I would like to draw to a CDC and PatBlt it to get a shaded sphere of the desired color. I'm running into problems with the number of colors displayed (about 20). I've played around with the CDC's palette but can't get any different results. Any suggestions?
|
|
|
|
|
Is it possible to insert a normal menu in a dialog window ??
I only got it working for an SDI or MDI application.
Thanx for any help,
Wolfgang
|
|
|
|
|
I had the exact same question. Someone sent me some of their code when they had to do the same thing. I never used it because I found a better way to make my app, but if you give me your e-mail, I can forward the code to you.
- John
- johnu@emersonprocess.com
|
|
|
|