Debug Assertion Failed! 
Author Message
 Debug Assertion Failed!

Hi All!
I get a Debug Assertion Failed! for the below code and I am wondering How to fix
this?
lprasentryname++; this line causes it.

RASENTRYNAME *lprasentryname = new RASENTRYNAME[sizeof(RASENTRYNAME)];
DWORD lpcb, lpcEntries, error;

lprasentryname->dwSize = sizeof(RASENTRYNAME);
error = RasEnumEntries(NULL, NULL, lprasentryname, &lpcb, &lpcEntries);
for(int i = 0;i < (int)lpcEntries;i++)
{
   m_list.AddString(lprasentryname->szEntryName);
   lprasentryname++;//causes error

Quote:
}



Mon, 05 May 2003 03:00:00 GMT  
 Debug Assertion Failed!
Could be wrong here, but I'm not thrilled with the first line of code,
either...

You're declaring the buffer to be big enough to hold the number of elements
equal to the size of the item, i.e. if the structure is 10 bytes, you're
allocating space for 10 entries...  Like the MSDN example, allocate enough
for 1, make the call to see how many entries there are, allocate the
appropriate memory, and go.  I've cut the example in below...

if cb > sizeof(RASENTRYNAME), your code will croak every time.

Good luck - John

// ###############################
lpRasEntryName = (LPRASENTRYNAME)GlobalAlloc(GPTR, sizeof(RASENTRYNAME));
lpRasEntryName->dwSize = sizeof(RASENTRYNAME);
if ((nRet = RasEnumEntries(NULL, NULL, lpRasEntryName, &cb, &cEntries))
    == ERROR_BUFFER_TOO_SMALL)
{
    lpRasEntryName = (LPRASENTRYNAME)GlobalAlloc(GPTR, cb);
    lpRasEntryName->dwSize = sizeof(RASENTRYNAME);

Quote:
}

// Calling RasEnumEntries to enumerate the phone-book entries
nRet = RasEnumEntries(NULL, NULL, lpRasEntryName, &cb, &cEntries);

if (nRet != ERROR_SUCCESS)
{
    printf("RasEnumEntries failed: Error %d\n", nRet);

Quote:
}

else
{
    printf("Phone-book entries in the default phone book:\n\n");
    for(i=0;i < cEntries;i++)
    {
        printf("%s\n",lpRasEntryName->szEntryName);
        lpRasEntryName++;
    }
Quote:
}

// ###############################


Hi All!
I get a Debug Assertion Failed! for the below code and I am wondering How to
fix
this?
lprasentryname++; this line causes it.

RASENTRYNAME *lprasentryname = new RASENTRYNAME[sizeof(RASENTRYNAME)];
DWORD lpcb, lpcEntries, error;

lprasentryname->dwSize = sizeof(RASENTRYNAME);
error = RasEnumEntries(NULL, NULL, lprasentryname, &lpcb, &lpcEntries);
for(int i = 0;i < (int)lpcEntries;i++)
{
   m_list.AddString(lprasentryname->szEntryName);
   lprasentryname++;//causes error

Quote:
}



Mon, 05 May 2003 03:00:00 GMT  
 Debug Assertion Failed!
Is that what is causing the error or do I got the de{*filter*} set up wrong? The code
compiles and works with BCB, it also compiles with visual C# but causes the
de{*filter*} error. I was just wondering why it does this?
If I change the lines from this
for(int i = 0;i < (int)lpcEntries;i++)
{
   m_list.AddString(lprasentryname->szEntryName);
   lprasentryname++;//causes error

Quote:
}

to this
for(int i = 0;i < (int)lpcEntries;i++)
{
   m_list.AddString(lprasentryname[i]szEntryName);
Quote:
}

the de{*filter*} has no problem?


Mon, 05 May 2003 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Debug Assertion Failed in Microsoft Visual C++ v5.0 Debug Library

2. Debug Assertion Failed in Microsoft Visual C++ v5.0 Debug Library

3. Debug Assertion Failed!

4. Debug Assertion Failed

5. Debug assertion failed in dbgheap.c

6. free() causes: "Debug Assertion Failed"

7. Debug Assertion Failed!

8. Debug Assertion Failed - VisualStudio SP5

9. Debug Assertion Failed - problem/solution

10. Debug Assertion failed!

11. Debug Assertion failed!

12. Debug Assertion failed

 

 
Powered by phpBB® Forum Software