Solved

Unexpected Run-Time stuff

Posted on 2000-04-11
7
352 Views
Last Modified: 2008-02-26
Hello

Both these Q's involve VC++ 6.x in WinNT.


Question 1:
Why do I get the following errors (when calling some MAPI function):
First-chance exception in SomeExe.exe (RPCRT4.DLL): 0x000006BA: (no name).
First-chance exception in exSIMUS.exe (RPCRT4.DLL): 0x000006BA: (no name).


Question 2:
Whats wrong with the following code?
int nr_of_propVals = 6;
MAPIAllocateBuffer(nr_of_propVals * sizeof(LPSPropTagArray), (LPVOID*) &tagArray);
tagArray->cValues = nr_of_propVals;
tagArray->aulPropTag[0] = PR_SUBJECT;
tagArray->aulPropTag[1] = PR_MESSAGE_FLAGS;
tagArray->aulPropTag[2] = PR_DISPLAY_TO;
tagArray->aulPropTag[3] = PR_DISPLAY_CC;
tagArray->aulPropTag[4] = PR_DISPLAY_BCC;
tagArray->aulPropTag[5] = PR_SENDER_EMAIL_ADDRESS;
.
.
.
MAPIFreeBuffer(tagArray);

When the last line of the code above is run the following msgs appear in the debug window. What do I do wrong?
HEAP[SomeExe.exe]: Heap block at ae20b0 modified at ae20d8 past requested size of 20
HEAP[SomeExe.exe]: Invalid Address specified to RtlFreeHeap( ae0000, ae20b8 )

0
Comment
Question by:Nusse
  • 5
  • 2
7 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 75 total points
ID: 2704491
>> Why do I get the following errors (when calling
>> some MAPI function):
>> First-chance exception

They aren't errors.  The occur when code in the OS detects a problem (a problem that is sort of expected and that can be handled)  The code throws an exception (just like in C++) to allows the exception handler to handle the problem.  Your application should work fine in these cases.

continues
0
 
LVL 22

Expert Comment

by:nietod
ID: 2704516
In

MAPIAllocateBuffer(nr_of_propVals * sizeof(LPSPropTagArray), (LPVOID*) &tagArray);

It would be nice to know what LPSProTagArray and tagArray are.

But it looks like you are allocating space for an array of 6 LPSProgTagArrays, but then you are treating the memory allocated, as if it is a strcuture of some sort, that has a pointer to an array.   Tha would be a problem.  

I can probably be more precise if you post some more details.


FYI the EE rues state that you shoudl only ask 1 question per EE question.  (unless teh questions are very closely related, and these are not.)  Otherwise problems tend to arrise....
0
 

Author Comment

by:Nusse
ID: 2731185
Adjusted points from 50 to 75
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:Nusse
ID: 2731186
Does it leak memory? I believe it does. It can, of course, be any of my other var's thar are leaking, but the 'tagArray' is my most probable suspect at the moment. Any idea how I should fix this problem?

/Nusse   ps.  see below  ds.

>FYI the EE rues state that you shoudl only ask 1 question per EE question.  (unless teh questions are very closely related, and these are not.)  Otherwise problems tend to arrise....

Sorry, I thought they were. They tend to arise from the same function (close to each other in that function).


>It would be nice to know what LPSPropTagArray and tagArray are.

They are MAPI structures. tagArray is defined as "LPSPropTagArray tagArray;". What LPSPropTagArray is exactly I am WAY too lazy to describe here (look in the MSDN).
A SPropTagArray is an array(:-) that holds PropTags. A PropTag (Property Tag, I think) consists of a few tags for MAPI use. Example: PR_EMAIL_ADDRESS, PR_ADDR_TYPE and so forth. Each tag has (should have) a corresponding entry in a MS-Exchange server 5.5.
I use the above array(tagArray) to retrieve the info that I want from the Exchange Server.
0
 
LVL 22

Expert Comment

by:nietod
ID: 2731711
>> Sorry, I thought they were. They tend to
>> arise from the same function (close to each
>> other in that function).
They probably aren't related, but I guess you didn't know that.  (and they coudl be.)   The way you worded the question though it seemed you knew then weren't.  Not a big deal, just try to avoid it if possible--obviously if you don't underand the problems, you can't always tell.

continues
0
 
LVL 22

Expert Comment

by:nietod
ID: 2731725
okay I udnerstand the allocation now.  The problem is that you are not allocating the wrong number of bytes.  The structure you are allocating is a CPropTagArray.  It begins with a count of the number of items in the array and this is followed by an array of the specified number of items.  Now in C/C++ you can't really define such a structure. i.e one that has an array that has an unspecified number of items.  (We get around this by ysiung dynamically allocated memory though.)  But for the C/C++ to be happt, the definition includes a single entry in the array, but when you allcoate space you need to leave room for the right number of items.   (and you did not)  

continues
0
 
LVL 22

Expert Comment

by:nietod
ID: 2731755
ideally the size you woudl need is the size of the count plus product of the size of the each item in the array and the number of items in the array.  Given

typedef struct _SPropTagArray
{
     ULONG      cValues;
     ULONG      aulPropTag[MAPI_DIM];
}

this would be

size = sizeof(ULONG) + n *(sizeof(ULONG));

where n is the number of entries you need.  The first sizeof() is for the count and the 2nd is for each item in the array.  This formula would probalby work, but might not.  The problem is that the compiler is allowed to place padding beween items in a structure, so the structure might need additional storage space we didn't allow for.  (Actually we can be certain it doesn't at the moment, but as the OS changes it could...) so to be safe you should allocate enoug space for the whole structure )(not just the cout), plus enough space for the array.  You can take into account that the whole structure has space for 1 array item already, so this really means you need to allcoate space for the whole structure plus the 1 less than the space for the array,  Like

size = sizeof(SPropTagArray) + (n-1)*sizeof(ULONG)

Again the first part (before +) allocates room for the whole structure which includes space for 1 array item.  The second part allocates space for all the array items after the first.

makes sense?  

FYI your formula was always a 4 bytes short because it didn't take into account the size of the initial count.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now