|
Is there a way to check if 2 handles refer to the same object?
|
|
|
|
|
Peter Weyzen wrote:
A pseudo handle? What's that?
Read the entire remarks section, which explains it quite succinctly. The key being the last paragraph:
"The pseudo handle need not be closed when it is no longer needed. Calling the CloseHandle function with this handle has no effect. If the pseudo handle is duplicated by DuplicateHandle, the duplicate handle must be closed."
Frankly, I've been doing serious multithreaded programming for years and have never used either call.
|
|
|
|
|
I have used GetCurrentThreadId to detect if I am calling a routine from a specific thread. If not, then the call is thunked over to the proper thread.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
[emote]Hangs head in shame[/emote]
Sigh, I missed that. Stupid me.
But the good news is that the last argument of _beginthreadex can be used to return the thread ID of the created thread. Then you can use GetCurrentThreadId and compare against the value returned in the last parameter from _beginthreadex.
Sorry about the mistake. I'll go play in traffic now.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Hello,
My app is almost complete.. I went to compile it at level 4 and I get a warning "warning C4706: assignment within conditional expression" Here is the only code in my program that gives me any warnings at level 4.. How could I rewrite the following to get rid of the warning?? (I understand the warning but I am unsure of a way to rewrite the while statement...)
Any help would be greatly appreciated!
CFile fileRead;
if(fileRead.Open(m_strCurrentDir+"clients.ini",CFile::modeRead))
{
char cBuf[1024];
UINT uBytesRead = 0;
while(uBytesRead = fileRead.Read(cBuf, sizeof(cBuf)-1)) <- HERE
{
cBuf[uBytesRead] = NULL;
strBuff += CString(cBuf);
}
fileRead.Close();
}
Thanks!!
Rob
|
|
|
|
|
while((uBytesRead = fileRead.Read(cBuf, sizeof(cBuf)-1)) != 0)
This lets the compiler know you aren't crazy and that "=" is what you wanted.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Great! Thanks.. I figured it would probably be something easy like that
Thanks again,
Rob
|
|
|
|
|
How can I change the background color of my CTabCtrl ?
I have tried to change the brush in the CMyDlg::OnCtlColor function of my dialog, but it doesn't work!
Daniel
---------------------------
Never change a running system!
|
|
|
|
|
I have found a method!
I have created my own derived CTabCtrl class and overided the OnEraseBkgnd(CDC* pDC) function:
BOOL CMyTabCtrl::OnEraseBkgnd(CDC* pDC)
{
CBrush backBrush(RGB(255, 0, 0));
CBrush* pOldBrush = pDC->SelectObject(&backBrush);
CRect rect;
pDC->GetClipBox(&rect);
pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(), PATCOPY);
pDC->SelectObject(pOldBrush);
return TRUE;
}
Daniel
---------------------------
Never change a running system!
|
|
|
|
|
hey all, just curious if anybody knows how to kill these warnings...
they only show up in my release build, and doesnt stop the program from working...the .exe compiles and runs fine, but still i'd like the release version to compiles 0 errors, 0 warnings before i declare it finished
Deleting intermediate files and output files for project 'cBoogieTest - Win32 Release'.
--------------------Configuration: cBoogieTest - Win32 Release--------------------
Compiling resources...
Compiling...
StdAfx.cpp
Compiling...
cBoogieTest.cpp
FileInfo.cpp
Generating Code...
Linking...
LINK : warning LNK4089: all references to "ADVAPI32.dll" discarded by /OPT:REF
LINK : warning LNK4089: all references to "SHELL32.dll" discarded by /OPT:REF
LINK : warning LNK4089: all references to "comdlg32.dll" discarded by /OPT:REF
cBoogieTest.exe - 0 error(s), 3 warning(s)
|
|
|
|
|
|
You can ALWAYS ignore this warning.
You usually can't simply remove the DLLs from your list. They are still needed in the initial link pass and will generate a fatal error if not there.
The solution is to add "/IGNORE:4089" to the "Command Line" link options.
|
|
|
|
|
The linker is saying that you included the import libs for those three DLLs in your link options, however your code does not call anything in those DLLs. It is harmless, but the correct way to remove the warning is to remove those LIBs from the linker options (since they are unneeded anyway).
--Mike--
If it doesn't move and it should: WD-40. If it moves and it shouldn't: duct tape.
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
|
VirtualAlloc allows you to reserve memory pages without committing physical memory. It is useful for writing allocators where the following conditions are met:
- the memory needs to be contiguous OR you must be able to have that memory available
- the maximum size is known in advance
- the maximum size is fairly large
- the minimum size is relatively small
- the growth of the data to the maximum size is not quick or guaranteed (if guaranteed, and you don't want to use the heap, use GlobalAlloc.)
|
|
|
|
|
|
That is about right. VA/VF were never intended for general allocations.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Short answer; yes.
Long answer; if you examine your needs, it is very unlikely you'd need VirtualAlloc. GlobalAlloc will usually work fine for large, simple (i.e. not classes/structs requiring constructors/destructors) allocations.
Note: Large means megabytes.
Also note that you could overload new for the classes in question.
Note concerning performance. Doing lots of new's/delete's can be extremely slow. Before leaping to replace it, examine your basic algorithms. In one case, a fellow worker had created a class which created hundreds of other classes which created hundreds of other classes. It took a while to allocate everything and over 40 seconds to destruct the mess (which caused the service to time out). By simple changing a few things, I reduced this to a few seconds. By changing the core algorithm, it could have been reduced to a few dozen milliseconds, all still using new/delete.
|
|
|
|
|
Another thing VA/VF allows you to do is reserve large portions of the virtual address space without actually creating the pages. Thus you can allocate 300MB of memory and create the pages manually as you need more of this block of memory. This reduces the stress on the page management system and can improve performance.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Well, without knowing much of anything about VirtualAlloc I can tell you that new does two things automatically for you:
- Allocates just the needed block of memory for your object (or array of objects) in the heap.
- Calls the object's constructor.
The "VirtualAlloc function reserves or commits a region of pages in the virtual address space of the calling process." You have to pass the amount of memory explicitly and no constructor is called.
Regards,
Alvaro
Well done is better than well said. -- Benjamin Franklin
(I actually prefer medium-well.)
|
|
|
|
|
Can anyone help me to get the CPU usage by PDH functions?
Thanks in advance,
Dudi
|
|
|
|
|
How can I convert a string (char* ) to a integer or a float with error checking?
I want to convert a string to a integer or a float:
<br />
"1" --> int 1<br />
If the string is something like that "%"&"/ssdd" I want to know that --> ERROR!
Daniel
---------------------------
Never change a running system!
|
|
|
|
|
static _Convert ConvertLong (
const char *pszValue, long *plValue)
{
errno = 0;
char *pszEnd = NULL;
long lReturn = strtol (pszValue, &pszEnd, 10);
if (pszEnd)
{
while (isspace (*pszEnd))
pszEnd++;
if (pszValue == pszEnd || *pszEnd != 0)
return Convert_Invalid;
}
if (errno == ERANGE)
{
if (lReturn < 0)
return Convert_Underflow;
else
return Convert_Overflow;
}
*plValue = lReturn;
return Convert_Ok;
}
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Thanks !!!
Daniel
---------------------------
Never change a running system!
|
|
|
|
|
Here's some old code of mine that checks if a string value is numeric according to how you need it. For example, if you don't want it to be negative, you pass the Unsigned flag; if it can have a decimal point, you pass it the Decimal flag; etc. Notice that it assumes that a decimal point is a dot.
enum NumericFlag
{
Unsigned,
Signed,
Decimal,
SignedDecimal
};
bool IsNumeric(const char* szValue, NumericFlag flag ) const
{
assert(szValue);
int nLen = strlen(szValue);
for (int iPos = 0, nDecimalPos = -1; iPos < nLen; iPos++)
{
char c = szValue[iPos];
if (isdigit(c))
continue;
if (c == '-' && iPos == 0 && (flag & Signed))
continue;
if (c == '.' && nDecimalPos < 0 && (flag & Decimal))
{
nDecimalPos = iPos;
continue;
}
return false;
}
return !!nLen;
}
Regards,
Alvaro
Well done is better than well said. -- Benjamin Franklin
(I actually prefer medium-well.)
|
|
|
|