|
CPallini wrote: And what is the error code in the 'buggy' version?
I could not get the error code. Only the 64-bit release-build got error code from this API call, not the debug-build. So I was not able to view the debug messages with DebugView. And when I added the message string for message box, the error would not come out.
Maxwell Chen
|
|
|
|
|
You can, of course: you don't need to locally allocate a CString to show a DWORD value (you may set a global variable value, for instance).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Now it is very interesting. GetLastError() = 0 when SetupDiEnumDeviceInfo fails.
Maxwell Chen
|
|
|
|
|
Yes, that's really interesting.
Anyway, are you sure you didn't make any other API call before calling GetLastError ?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
CPallini wrote: Anyway, are you sure you didn't make any other API call before calling GetLastError ?
No.
Here is the latest code for testing.
bool SetupDi::EnumDevInfo(DWORD dwIndex, SP_DEVINFO_DATA* pDeviceInfoData)
{
if(!m_hDevInfo) {
TRACE(_T("SetupDi::EnumDevInfo, m_hDevInfo is NULL. \n"));
return false;
}
if(!pDeviceInfoData) {
TRACE(_T("SetupDi::EnumDevInfo, pDeviceInfoData is NULL. \n"));
return false;
}
m_dwErrCode = 0;
memset(pDeviceInfoData, 0, sizeof(SP_DEVINFO_DATA));
pDeviceInfoData->cbSize = sizeof(SP_DEVINFO_DATA);
BOOL bRet = SetupDiEnumDeviceInfo(m_hDevInfo, dwIndex, pDeviceInfoData);
if(!bRet) {
TRACE(_T("SetupDi::EnumDevInfo, SetupDiEnumDeviceInfo(index: %d) failed (0x%08X). \n"),
dwIndex, m_dwErrCode = GetLastError());
AfxMessageBox("SetupDiEnumDeviceInfo");
}
return (TRUE == bRet);
}
bool CPccCfgApp::FindSMBusHost()
{
SetupDi DevInfo;
if(!DevInfo.GetClassDevs(SetupDi::eDC_System, _T("PCI"), true, true, true, false, false)) {
TRACE(_T("CFindDeviceDlg::FindDevice, GetClassDevs failed. \n"));
return false;
}
DWORD dwIndex = 0;
SP_DEVINFO_DATA spDevInfoData;
while(1) {
if(!DevInfo.EnumDevInfo(dwIndex, &spDevInfoData)) {
TRACE(_T("CFindDeviceDlg::FindDevice, EnumDevInfo failed. \n"));
AfxMessageBox(_T("CFindDeviceDlg::FindDevice, EnumDevInfo failed."));
CString s;
s.Format(_T("Error = 0x%08X"), DevInfo.m_dwErrCode);
AfxMessageBox(s);
break;
}
}
Maxwell Chen
|
|
|
|
|
I would remove the TRACE macro and try again.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
CPallini wrote: I would remove the TRACE macro and try again.
Now the GetLastError() = 0x103 ( ERROR_NO_MORE_ITEMS ).
Maxwell Chen
|
|
|
|
|
Hi CPallini,
The issue is resolved. The detailed information is here[^].
Maxwell Chen
|
|
|
|
|
 Sam Varshavchik replied me in the "C++ professionals group" forum on LinkedIn. Based on his information, I resolved this issue.
The below was his comment.
Modern CPUs have no "memory alignment" issues. In the worst case scenario, the CPU will burn a few extra cycles fetching an adjacent memory word, to execute the instruction or fetch the data. No impact on the application, except for it taking a few ticks of the clock to complete.
Memory alignment issues were often an issue with older CPUs, such as the earlier versions of the Motorola 68K CPU family, where attempting to fetch a word at an odd address caused a trap. Modern CPUs just deal with this by burning more fuel, no harm done. Whatever your problem really is, a "memory alignment" issue would be on the bottom of my list of suspects.
The symptoms being described -- adding a debug statement making an apparent error go away -- often happen as a result of subtle memory corruption; such as wild pointer dereferencing, using memory after it's been freed, etc... Adding some debug statements does not really fix anything, it merely masks the bug. Many times, effects of memory corruption are very sensitive to the layout and the internal arrangement of the code in the final executable. Often, one might think that adding an innocuous debug statement magically fixes their problem, only to see things come crashing down hard, after making some other innocent change to some completely unrelated part of the same application.
There is no universal answer how to fix this, or where the problem is. Roll up your sleeves, it's old-fashioned debug time.
I often found a lot of value in a memory instrumentation and usage checker. For MS-Windows, your apparent platform, Purify is a popular tool for pin-pointing where things go astray. On Linux, I find valgrind to be indispensable, and worth every penny of its no-cost. Very often it began screaming at me about bugs in my code that I didn't even know about, yet!
Of course instrumenting code changes its runtime behavior, and might also have unpredictable results that depend on the timing of its execution -- especially with multithreaded applications. Can't win them all.
I do not have the IBM Rational Purify tool (IBM asked me to register a user account), but I downloaded and installed the 30-day trial version of Intel Parallel Inspector 2011. It reported about 30 memory errors: most of them were in the built-in source code of Visual C++ 2010, but one occurrence was in my project source code. I looked some lines back before this line, initialized a DWORD variable with value 0 (the DWORD dwFilter in the code snippet below), and this issue is resolved.
The below is the related code snippet.
bool SetupDi::GetClassDevs(SetupDi::DeviceClass DevClass, PCTSTR sEnumerator,
bool bAllClasses, bool bPresent, bool bProfile,
bool bDefault, bool bInterface)
{
const GUID* pGuid = NULL;
switch(DevClass)
{
case eDC_System:
pGuid = &GUID_DEVCLASS_SYSTEM;
break;
default:
break;
}
DWORD dwFilter = 0;
if(bAllClasses) {
dwFilter |= DIGCF_ALLCLASSES;
}
if(bPresent) {
dwFilter |= DIGCF_PRESENT;
}
if(bProfile) {
dwFilter |= DIGCF_PROFILE;
}
if(bInterface) {
dwFilter |= DIGCF_DEVICEINTERFACE;
}
if(bDefault && bInterface) {
dwFilter |= DIGCF_DEFAULT;
}
m_hDevInfo = SetupDiGetClassDevs(pGuid, sEnumerator, NULL, dwFilter);
if(!m_hDevInfo) {
TRACE(_T("SetupDi::GetClassDevs, SetupDiGetClassDevs failed (0x%08X). \n"), GetLastError());
}
return (NULL != m_hDevInfo);
}
Maxwell Chen
|
|
|
|
|
OK, so it was a 'surviving the realease build' issue. I'm happy you finally won.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I am currently reviewing many programs I wrote for Windows 2003/2000 where I call the NetServerEnum Function to enumerate all the servers in a domain. Calling the NetServerEnum Function is dependant on the Computer Browser Service (NETBIOS) running on a Domain Controler in the specified domain. In Windows 2003, this service was on by default.
In a Windows 2008 built domain, Microsoft has decided to disable the Computer Browser Service (NETBIOS) on all windows 2008 machines. This means that if your domain controller is windows 2008, the NetServerEnum Function will not work at all. Enabling the computer Browser Service on the Windows 2008 Domain Controller and setting it to Automatic will solve the issue.
In a quest to update my code to avoid having to start services on domain controllers, does anyone have, or know of another function that can enumerate servers on a windows 2008 based domain that is not based on Netbios calls. I am prgramming in VC++.
thanks in advance
|
|
|
|
|
search the AD for computers?
All DC's have a 'RID Set' child
|
|
|
|
|
Hello i was just wondering if this can be done?, i want to be able to see the windows that overlapped by my window.
Thanks 
|
|
|
|
|
I'm sure it can be done, don't know if there's any libraries that can already do this for you (may be), but if you want to do it yourself you'll have to override the OnPaint() method.
|
|
|
|
|
thanks
but how to do that myself i know that using NULL brush on the WM_PAINT draws the window transparent but just it does that draws a no fill rect, so i can see the back of the window but just the moment it gets drawed, so i am thinking of using a timer but that is not efficient can someone they me how i can do it myself without libraries?
|
|
|
|
|
OnPaint() is the method that the MFC infrastructure calls to draw the screen, that would be the appropriate override for this, if you do it there, it should do it the same every time, if you need to get the screen redrawn at any time, just invalidate it and MFC will once again go to OnPaint() to redraw.
|
|
|
|
|
Have you looked at the WM_ERASEBKGND and/or WM_CTLCOLORDLG messages?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
M not sure this is your requirement or not
add this in onpaint
this->ShowWindow(SW_HIDE);
this will hide the entire dialog
|
|
|
|
|
|
The second link is what i needed thanks 
|
|
|
|
|
Glad to be of assistance!
Sometimes it's just knowing what to look for...
Iain.
I am one of "those foreigners coming over here and stealing our jobs". Yay me!
|
|
|
|
|
Hello,
I finished an update for an Visual C++ application. The version before works without problems, and I did no change at my compiler Settings.
But on all Computers cxcept of my Development machine, I get the following exception:
Unhandled exception 0xE0434F4D (UNKNOWN TYPE) caught at address 0x7697B727 in the thread 4532.
-> Registers:
EAX = 0x0018F220, EBX = 0xE0434F4D, ECX = 0x00000001, EDX = 0x00000000,
ESI = 0x0018F2A8, EDI = 0x0033B290, EBP = 0x0018F270, ESP = 0x0018F220,
EFlags = 0x00000212, CS = 0x0023, SS = 0x002B, DS = 0x002B, ES = 0x2B, FS = 0x0053, GS = 0x002B
-> Last error: 0x000000B7
-> Call stack (thread 4532):
KERNELBASE(?) : RaiseException(0xE0434F4D,0x00000001,0x00000001,0x0018F2A8,0x84CD36CD) + 88 bytes
-> Call stack (thread 3568):
ntdll(?) : ZwWaitForMultipleObjects(0x04CFFE18,0x04CFFE8C,0x00000000,0xFFFFFFFF,0x00000000) + 21 bytes
-> Call stack (thread 3608):
ntdll(?) : ZwWaitForSingleObject(0x00000208,0x000007D0,0x00000000,0x76711141,0x0548FCFC) + 21 bytes
-> Call stack (thread 3864):
ntdll(?) : ZwWaitForMultipleObjects(0x00000000,0x0776FFD4,0x773A9F02,0x003A26E8,0x7032659A) + 21 bytes
-> Call stack (thread 4300):
ntdll(?) : ZwWaitForWorkViaWorkerFactory(0x00389F98,0x0786FFD4,0x773A9F02,0x00389F98,0x70C2659A) + 18 bytes
-> Call stack (thread 4600):
ntdll(?) : ZwWaitForWorkViaWorkerFactory(0x00389F98,0x079AFFD4,0x773A9F02,0x00389F98,0x70DE659A) + 18 bytes
-> Call stack (thread 3496):
ntdll(?) : NtDelayExecution(0x0000EA60,0x00000000,0x07AEFF78,0x7682580C,0x0000EA60) + 21 bytes
-> Computer configuration:
OS type: WIN32 NT
OS version: major 6, minor 1, build 7600
Number of processors: 2
Processor type: GenuineIntel, stepping 10, model 7, instruction family 6
Processor name: Intel(R) Core(TM)2 Duo CPU T6500 @ 2.10GHz
Processor features: FPU, MMX, SSE, SSE2, CLFLUSH, RDTSC, CMPXCHG8B, CMOV
More processor features: VME, DE, PSE, MSR, PAE, MCE, APIC, SEP, MTRR, PGE, MCA, PAT, PSE36, FXSR, DS, SS, TM
I have no idea where I could start searching the problem. Can somebody help me?
Thank You,
Johannes
|
|
|
|
|
I was making exercise 4.23 from C++ essentials and ended up with this code:
#include <iostream>
#include <stdarg.h>
using namespace std;
double Sum (int n, double val ...)
{
va_list args;
double value = val;
double result = 0;
va_start(args, val);
for(int i=0;i<n;i++)
{
result+= value;
va_arg(args, double);
}
va_end(args);
return result;
}
int main()
{
double n = Sum(3, 2, 2, 2);
cout << "Result: " << n;
return 0;
}
It compiles fine and when i do the call "Sum(3, 2, 2, 2)" it just prints "Result: 6" but when i call "Sum(3, 2.1, 2.0, 2.0)" it prints "Result: 6.3" while it should print 6.1, right? What am i doing wrong? D: thanks! btw, the solutions the book provides aren't working...
|
|
|
|
|
I have two questions for you:
1.
by what magic is value going to track the values in the list, you only assign it once, outside the loop?
2.
don't you think you should be able to find the answer yourself, with Google and everything at your disposal?
It never hurts to look up the reference information, e.g. in MSDN[^].
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
LOL! that's an embarrassing mistake D: I see I do understand it but just made some stupid mistake >.> of course it should be
value = va_arg(args, double); instead of just
va_arg(args, double)
thanks anyways 
|
|
|
|
|