Solved

Unexpected Run-Time stuff

Posted on 2000-04-11
7
374 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
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP.net build a IF/Then Walkthrough Guide 1 279
Embarcadero WebBroker REST server endpoint parameters 2 96
c++, dynamic object by json 1 60
VS2015 Redefinition errors 4 89
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

756 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