Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. COM
  4. Need Com Help - I'm a beginner

Need Com Help - I'm a beginner

Scheduled Pinned Locked Moved COM
comdata-structureshelplearning
4 Posts 2 Posters 8 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jkirkerx
    wrote on last edited by
    #1

    I have these 2 lines of code, if I remark them out, my function runs fine, but does not add the data to the metabase key. If I leave them in, I can't unload the Variant Array, and I get a CRT Heap Failure upon exiting the function. I sort of know what it does, it takes the new array entry and converts the type to VT_DISPATCH, and then copies the CLASS MimeMap into the array's last entry. I have worked hard to get the complete function to work, and it does, it generates the MimeMap Key, loads the data, but I can't exit the function clean, and call it again. If I need to post more, let me know.

    V_VT(&va.pa[cVariants]) = VT_DISPATCH;
    V_DISPATCH(&va.pa[cVariants]) = pME;
    ++cVariants;

    _ 1 Reply Last reply
    0
    • J jkirkerx

      I have these 2 lines of code, if I remark them out, my function runs fine, but does not add the data to the metabase key. If I leave them in, I can't unload the Variant Array, and I get a CRT Heap Failure upon exiting the function. I sort of know what it does, it takes the new array entry and converts the type to VT_DISPATCH, and then copies the CLASS MimeMap into the array's last entry. I have worked hard to get the complete function to work, and it does, it generates the MimeMap Key, loads the data, but I can't exit the function clean, and call it again. If I need to post more, let me know.

      V_VT(&va.pa[cVariants]) = VT_DISPATCH;
      V_DISPATCH(&va.pa[cVariants]) = pME;
      ++cVariants;

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      How many elements does va.pa own. The heap failure is probably occurring because you're exceeding the bounds of the array when you do ++cVariants.

      «_Superman_»  _I love work. It gives me something to do between weekends.

      _Microsoft MVP (Visual C++)

      Polymorphism in C

      J 2 Replies Last reply
      0
      • _ _Superman_

        How many elements does va.pa own. The heap failure is probably occurring because you're exceeding the bounds of the array when you do ++cVariants.

        «_Superman_»  _I love work. It gives me something to do between weekends.

        _Microsoft MVP (Visual C++)

        Polymorphism in C

        J Offline
        J Offline
        jkirkerx
        wrote on last edited by
        #3

        I thought about that. If the mime map key is empty at 0, I add an entry, the +CVariants becomes 1. In the For Loop SafeArrayPutElement, it loops once. so no existing data, add pME, va.pa = {pa=0x003a7200 DISPATCH = 0x017a8458 } vt = 9, cVariants = 0 the added data is the 0, first array entry, but makes the SafeArray Bound 1, because it can't be 0? So you don't think that my pME is distorting the va.pa?, I can't see the data, so I don't know. I'm in Antarctica here on this one, it's not a popular subject, and wrappers have been created to do the job in VB. I'm learning that super hard stuff has been replaced with high level wrappers by MS. Thanks for looking at my post, I really need to pull this off, and move on to my socket issue. I think I'm so close to finishing this function.

        if (NULL != pwszAddExtension && NULL != pwszAddType) {
        CComPtr<IISMimeType> pME;

        		// Build a CCom Pointer and Instance
        		hr = pME.CoCreateInstance(L"MimeMap");			
        		RETURN\_ON\_FAILURE(hr);
        		
        		hr = pME->put\_Extension(bstrAddExtension);
        		hr = pME->put\_MimeType(bstrAddType);
        		RETURN\_ON\_FAILURE(hr);						
        			
        		// Append pME to the array
        		//V\_VT(&va.pa\[cVariants\]) = VT\_DISPATCH;
        		//V\_DISPATCH(&va.pa\[cVariants\]) = pME;
        		//++cVariants;	<- You talkin about this- if 0, then add 1		
        			 
        		SAFEARRAYBOUND saBound = {cVariants, 0};
        		SafeArray sa(VT\_VARIANT, 1, &saBound); ,- the bound becomes 1
        
        		VARIANT varArray;
        		VariantInit(&varArray);
        
        		V\_VT(&varArray) = (VT\_VARIANT | VT\_ARRAY);
        		V\_ARRAY(&varArray) = sa.psa;
        		
        		for (i = 0; i < cVariants; ++i) {
        			hr = SafeArrayPutElement(sa.psa, &i, &va.pa\[i\]);
        			RETURN\_ON\_FAILURE(hr);				
        		}
        
        1 Reply Last reply
        0
        • _ _Superman_

          How many elements does va.pa own. The heap failure is probably occurring because you're exceeding the bounds of the array when you do ++cVariants.

          «_Superman_»  _I love work. It gives me something to do between weekends.

          _Microsoft MVP (Visual C++)

          Polymorphism in C

          J Offline
          J Offline
          jkirkerx
          wrote on last edited by
          #4

          Oh wow your a genius. Over all in the end, the cVariants value was wrong when the first array called va was created. It was too small, so the one you pointed out added a value that was not initialized, it ncreased the size of the array, in a space that was too small. So that's why the delete [] va crashed. So finally after week of messing with this, I broke the program down in 2, worked on the add mime until it was clean, and just added the code to read the current mimes. I put much weight on your suggestion, but did keep it in mind. Thanks Superman.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups