Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 385
  • Last Modified:

Unexpected Run-Time stuff

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
Nusse
Asked:
Nusse
  • 5
  • 2
1 Solution
 
nietodCommented:
>> 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
 
nietodCommented:
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
 
NusseAuthor Commented:
Adjusted points from 50 to 75
0
Independent Software Vendors: 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!

 
NusseAuthor Commented:
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
 
nietodCommented:
>> 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
 
nietodCommented:
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
 
nietodCommented:
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

Independent Software Vendors: 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!

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now