Solved

Unexpected Run-Time stuff

Posted on 2000-04-11
7
378 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to convert MFC APP to Win32 APP. 19 133
Header of docx file 17 145
How can i compile this github project?? 2 104
Which Linux flavors will this run on? 6 116
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

752 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