|
hxhl95 wrote: I have a process handle and I wish to detect if that handle is one to my app.
Call GetProcessId() , and then call EnumWindows() to find the matching process id.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
error C2065: 'GetProcessId' : undeclared identifier , even though I've included windows.h. Does the fact that I'm using VC++ 6.0 make a difference?
|
|
|
|
|
hxhl95 wrote: Does the fact that I'm using VC++ 6.0 make a difference?
Only if you need to define _WIN32_WINNT . Look in winbase.h for the appropriate value (if any).
See here for more.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
winbase.h doesn't contain a definition of GetProcessId . I tried defining it manually with DWORD WINAPI GetProcessId(__in HANDLE ProcessHandle) , but then I get an unresolved external symbol error, even though I'm obviously including kernel32.lib...
|
|
|
|
|
hxhl95 wrote: winbase.h doesn't contain a definition of GetProcessId.
You need to install the Platform SDK.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
I have.
|
|
|
|
|
So are you looking in C:\Program Files\Microsoft SDK\include\winbase.h instead of C:\Program Files\Microsoft Visual Studio\VC98\Include\winbase.h? If you add #include <winbase.h></winbase.h> to the top of a file, right-click it and select Open, which of the two files opens?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
I did
#include <C:\Program Files\Microsoft Platform SDK\Include\winbase.h><br /> just in case, and it's still giving me an undeclared error. When I open the file the SDK file opens, and I can see the definition of GetProcessId in the file. However the compiler just doesn't find it.
|
|
|
|
|
I'm out of suggestions at this point. This compiles fine for me:
#include <windows.h>
void main( void )
{
GetProcessId(0);
}
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Okay. I'll just try a different approach if I can't get this working by tomorrow.
Thanks a lot for your help
|
|
|
|
|
I have been surfing the web trying to find a solution and I've tried some of them and still can't compile. It is a standard VS generated DlgClass and I just want to launch the worker which is prototyped up top as global. I've tried casting ExecuteThread every way possible pretty much in the thread launch function. Any obvious solutions?
void ExecuteThread(LPVOID lParam)
void CVisualEmulatorDlg::OnBnClickedRun()
{
HWND hWnd = GetSafeHwnd();
CWinThread *pThread = AfxBeginThread(ExecuteThread, hWnd, THREAD_PRIORITY_NORMAL);
}
void ExecuteThread(LPVOID lParam)
{
MessageBox( (HWND)lParam, (LPCWSTR)"Thread Start", (LPCWSTR)"Secondary Thread", MB_OK );
return;
}
|
|
|
|
|
You haven't been reading your documentation!!!
Try this.
UINT __cdecl ExecuteThread( LPVOID pParam );
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
The reason I ended up trying void, along with any other things is that UNIT dosn't show up as a data type. Is there a header that needs to be included? Having trouble researching it because everything that comes back is about unit testing.
From one page it looked like UNIT meant use, int, long, or short, but tried and non of those worked. Tried with and without the __cdecl as well.
Never come across the UNIT before and wishing right now I never had. Code looks basically the same. Any ideas?
void CVisualEmulatorDlg::OnBnClickedRun()
{
HWND hWnd = GetSafeHwnd();
CWinThread *pThread = AfxBeginThread(ExecuteThread, hWnd, THREAD_PRIORITY_NORMAL);
}
UNIT __cdecl ExecuteThread(LPVOID lParam)
{
MessageBox( (HWND)lParam, (LPCWSTR)"Thread Start", (LPCWSTR)"Secondary Thread", MB_OK );
}
|
|
|
|
|
typo typo typo typo
Its UINT not UNIT.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Wow.. sorry guys. Pretty embarased right now...but that fixed it.
Thanks a lot.
|
|
|
|
|
Killiconn wrote:
void ExecuteThread(LPVOID lParam)
Are you missing the ';' behind the function declaration.
By the way what are the compilation errors that you get?
The possible solutions for C2665 are
* Supply a conversion operator.
* Use explicit conversion.
but can't really say if they help you in resolving your problem
You need to google first, if you have "It's urgent please" mentioned in your question.
_AnShUmAn_
|
|
|
|
|
Your worker thread function definition is wrong, check out here[^]
The function should not return void, the function signature should be as follows:
UINT __cdecl MyControllingFunction( LPVOID pParam );
|
|
|
|
|
I am currently writing a multi-threaded application using C++ and MFC. I am trying to write some code to keep track of my memory allocations (new) and my memory frees (delete). I have written aclass called MemoryChecker that is suppose to do this. To store the list of pointers that are allocated,
I am using STL which is not thread safe. To make it thread safe, I put a call to WaitForSingleObject
around the body of the function. I would expect to make this thread safe. Inside the member function
deleteItem, there is a static variable. It is initialized to true but later set to false. Before it is set to false, there is an assert statement that checks that the value is still true. However,
that assert statement is failing (sometimes). Therefore, I am thinking my lock is not working properly.
<br />
void<br />
MemoryChecker::deleteItem( void *ptr )<br />
{<br />
if ( WaitForSingleObject(mutexDeleteHandle, INFINITE) == WAIT_OBJECT_0 ) {<br />
if ( ptr == 0 ) {<br />
ReleaseMutex(mutexDeleteHandle);<br />
returneturn;<br />
}<br />
static bool go = true;<br />
bool found = false;<br />
NewList::iterator it = newList.begin();<br />
while ( it != newList.end() ) {<br />
if ( it->ptrValue == ptr ) {<br />
found = true;<br />
break;<br />
}<br />
it ++;<br />
}<br />
if ( found == false )<br />
found = true;<br />
else {<br />
assert( found );<br />
newList.erase( it );<br />
}<br />
assert( go );<br />
go = false;<br />
ReleaseMutex(mutexDeleteHandle);<br />
}<br />
}
I should also tell you that I create the lock, in another thread, with the following call:
mutexDeleteHandle = CreateMutex( NULL, FALSE, NULL );
Please note that the second parameter in CreateMutex is to specify who owns the lock and the
lock may not be owned by the thread making the call to WaitForSingleObject.
I am hoping that somebody here can tell me what I am doing wrong.
Thanks
Bob
modified on Thursday, March 19, 2009 6:26 PM
|
|
|
|
|
Your 'go' variable is static, it will be set to true once, so after you do 'go = false' it will remain false in following calls too.
p.s: Please put all of your code between <pre> and </pre> tags to make it easier to read.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Thanks for the response. You are 100% right. I am not awake today. I need to reinitialize the go flag every time to make it a valid test.
Now for your second point. I put the code between <pre> and </pre> but it did not preserve the white spacing. I do not know why. Any ideas?
Bob
|
|
|
|
|
Sorry, I see one small <pre> tag, and a large, only-half-there <code> tag.
|
|
|
|
|
blug,
Thanks for the response. I am not sure. Before I include code, I click on the formatting option code block. That is the option just to the left of inline code and to the right of BIG. Maybe, I should click on inline code and paste my code in there. Not Sure.
Bob
|
|
|
|
|
I am currently developing a multi-threaded application using C++ and MFC. Each thread calls new and delete to allocate and free memory. I am wondering if this is ok. In particular, if I have a routine that does the following, is it thread safe?
<br />
void<br />
WorkerClass::genRandomNumbers( double *randomNumbers, int count )<br />
{ <br />
double *ranList = new double[6];<br />
<br />
<br />
delete []ranList;<br />
}<br />
I am thinking that if two different threads are executing this routine at the same time, one might be allocating memory and the other freeing memory. Is that ok? One possibility is that Microsoft has put locks in there code to make sure that new and delete are thread safe. I have been unable to find documentation saying that they have or have not done this. I am hoping somebody out there can enlighten me on this issue.
Thanks
Bob
|
|
|
|
|
BobInNJ wrote: I am thinking that
My advice is not to use your own thinking about how multi-threading works. I strongly urge you to find some material designed to explain or teach multi-threading concepts and study it.
If this is something you decide to do, I can tell you that back when was starting out with threading I found this book[^] (the chapters on threading) very helpful. It was the first edition and I can't verify for you that the new editions contain the same material.
|
|
|
|
|
Perfectly safe. Unless you allocate something static. like
void
WorkerClass::genRandomNumbers( double *randomNumbers, int count )
{
static int i =0;
i = blahaha
}
He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus
|
|
|
|