Solved

Unexpected Run-Time stuff

Posted on 2000-04-11
7
339 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

705 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

19 Experts available now in Live!

Get 1:1 Help Now