|
class base_w32thread{
protected:
HANDLE _handle;
DWORD _dwTID;
base_w32thread():_handle(0), _dwTID(0L){}
virtual ~base_w32thread()=0;
public:
bool start(LPSECURITY_ATTRIBUTES psecattrs = NULL, DWORD dwCreateFlags = 0L);
operator HANDLE(){ return _handle; }
protected:
virtual void run()=0;
virtual void onEndThread(){}
static long WINAPI threadfnc( LPARAM lp);
};
threadfnc is the callback that is sent as the argument to CreateThread() below
bool base_w32thread::start(LPSECURITY_ATTRIBUTES psecattrs, DWORD dwCreateFlags){
assert( !_handle);
if( _handle)
return false;
_handle = ::CreateThread( psecattrs, 0,
(LPTHREAD_START_ROUTINE)threadfnc, this, dwCreateFlags, &_dwTID);
return (_handle)?true:false;
}
Then in the callback function there is no "this" pointer so we have sent the object pointer as the User Parameter to CreateThread and we cast it to the correct type
long WINAPI base_w32thread::threadfnc( LPARAM lp){
assert( lp);
base_w32thread* pThis = (base_w32thread*)lp;
if( pThis)
pThis->run();
pThis->_handle = 0L;
pThis->onEndThread();
return 0L;
}
Hope that helps
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
Thanks a lot. I'll try my best.
|
|
|
|
|
|
Just curious... is CALLBACK exaactly the same ad __stdcall? Can I use them interchangeably?
|
|
|
|
|
I had a problem with CALLBACK functions in MFC when i made my process/windows viewer
someone on CodePrject showed me a way to get around this, ill
declare one function as
static BOOL CALLBACK myfunc( LPARAM lParam );
and one as (you can use the same name if you like VC++ will pick the right one )
BOOL myfunc2( LPARAM lParam );
when call your callback call the static one with the lparam as "this"
ie. EnumWindows( myfunc, (LPARAM) this);
then have your static function call the second
BOOL CALLBACK myfunc( LPARAM lParam )
{
CMyDialog * me = (CMyDialog*) lParam;
return me->myfunc2();
}
|
|
|
|
|
What is the proper way to define a function that contains a class pointer as an arguement (because I am having very bad compile errors all over the place)
Is this the correct way:
void MyFunction(char*, char*, CClass*);
or
void MyFunction(char*, char*, class CClass*);
The former gives me a syntax error eg. identifyer CClass
The later gives me compile error when writing a differnt function such as
void MyFunction2(char*, char*, CClass::CSubClass*);
void MyFunction2(char*, char*, class CClass::cSubClass*);
Every time I change one way of doing it, I screw the code up somewhere else.
Can I get some help on this one? Thanks
|
|
|
|
|
void MyFunction(char* c1, char* c2, CClass* theObject);
void MyFunction2(char* c1, char* c2, CSubClass* theObject);
Note that if CSubClass extends CClass then you can pass a CSubClass* as the argument to CClass*
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
class CClass; // OR: #include "Class.h"
void MyFunction(char*, char*, CClass*);
|
|
|
|
|
Ok, thanks for the reply...I must omit "class" before the class.
NOw on to the compile errors, I don't understand them because I am including the header file that contains the class definition.
Isn't this enough?
|
|
|
|
|
what are the errors now ?
compile error ?
what is the description of the error ?
what is the line giving the error ?
TOXCCT >>> GEII power
|
|
|
|
|
that is right. Do not use the word class before variable declarations, only before the class declaration.
class B1
int i;
B1 b; // B1 is a type like int is a type
Your compile errors should be discernable. Take a break and then look at them again.
To make it more fun, Java has a "Class" type and this can be used in declaring a variable such as Class somvarthatwillrefertoaclasslater; //
|
|
|
|
|
Anonymous wrote:
Java has a "Class" type and this can be used in declaring a variable such as Class somvarthatwillrefertoaclasslater;
are you sure it is not a declaration before a definition instead of a type ?! (in C++, it is like that...)
TOXCCT >>> GEII power
|
|
|
|
|
Thanks for the replies guys. The error line reads:
error C2061: syntax error : identifier 'cDataFile'
Where cDataFile is a class defined in another header file which I have included in this header file
The function definition (part of another class)
void Save(cDataFile*);
So I'm stumped
|
|
|
|
|
First, make sure that cDataFile is spelled correctly (including capitalization, I am suspicious of your lowercase 'c').
Second, when your function uses a pointer to a class, as you did, you only need to forward include the class in the header file. Then put the #include in the .cpp file (not the .h file)
i.e.
class cDataFile;
class CYourClass
{
void Save(cDataFile*);
};
|
|
|
|
|
Thanks for the continued help...I seem to be a bit confused though...the spelling is correct (I always use a lowercase c for classes)
Here is my file structure/layout:
Header1.h
---------
class cDataFile
{
...
};
----------
Header2.h
---------
#include "Header1.h"
class cSomeClass
{
public:
void SaveSomeFile(cDataFile*); <---- This is were I get the error
};
----------
Could you please explain what you said before in this semi-diagramatical way? Thanks.
|
|
|
|
|
Could someone please guide me in writing a DDE server program that will write information to an excel file.i should be able to write this program in VC++.
|
|
|
|
|
hello, I was just wondering is it possible to include a dll in the resources of a exe and then when the exe starts maybe copy them in the exe's directory(programaticly) and use them from there(I mean so that the exe can load the required functions from these dlls).
Or can dll functions of dlls inclouded as resources be called from the exe, I don't think they can.
Thank you for your time.
please reply
|
|
|
|
|
You can include the DLL as resource, extract it at runtime and then do anything you like with the DLL, like LoadLibrary , GetProcAddress etc
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
You can do that, although it's somewhat of a pain. You simply add the DLL as a custom resource at build-time. At run-time, you get the binary data for that resource and save it to file, then you can LoadLibary on the DLL and run its functions.
"Fish and guests stink in three days." - Benjamin Franlkin
|
|
|
|
|
Actually it's pretty easy. I'll share my code with you (isn't that the purpose of this forum? )
<br />
UINT dll_size;<br />
void* dll = NULL;<br />
void* LoadDatFromResource(HINSTANCE hModule);<br />
dll = LoadDatFromResource(hInstance);<br />
<br />
void ExtractFile()<br />
{<br />
if(dll == NULL)<br />
{<br />
return;<br />
}<br />
<br />
FILE *outfile;<br />
if (outfile = fopen("file.dll", "wb"))<br />
{<br />
fwrite(dll, 1, dll_size, outfile);<br />
fclose(outfile);<br />
}<br />
}<br />
<br />
void* LoadDatFromResource(HINSTANCE hModule)<br />
{<br />
HRSRC hResInfo;<br />
HGLOBAL hRes;<br />
<br />
hResInfo = FindResource((HMODULE)hModule,MAKEINTRESOURCE(IDR_ID_DLL),"ID_DLL");<br />
if(hResInfo == 0)<br />
{<br />
return NULL;<br />
}<br />
<br />
hRes = LoadResource((HMODULE)hModule,hResInfo);<br />
if(hRes == 0)<br />
{<br />
return NULL;<br />
}<br />
<br />
LPVOID pDatabase = ::LockResource(hRes);<br />
if(pDatabase == 0)<br />
{<br />
return NULL;<br />
}<br />
<br />
dll_size = SizeofResource((HMODULE)hModule, hResInfo);<br />
<br />
return pDatabase;<br />
}
dammit, where are the tabs gone in the code?
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hi,
I want to add to my program something similar to the Microsoft Office paperclip guy and the popup balloon messages (hopefully in a way that is not as annoying . I'm not sure where to start looking. Is this a standard control? If yes, what is it and if not, how might I go about implementing one like what controls/classes might I need. I'm kinda lost.
Thanks for any input!
|
|
|
|
|
|
Thanks! I'll try not to be annoying in my program LOL
|
|
|
|
|
herbert_chow wrote:
I want to add to my program something similar to the Microsoft Office paperclip guy
No, you don't. You will incur much wrath; look at the reaction the Office paperclip has gotten over the years.
Well ok, if you must do it, that character is called the Microsoft Agent.
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
Windows troubleshooting: Reboot first, ask questions later.
|
|
|
|
|