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. Managed C++/CLI
  4. gcroot and ArrayList

gcroot and ArrayList

Scheduled Pinned Locked Moved Managed C++/CLI
questiondata-structures
5 Posts 2 Posters 0 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.
  • S Offline
    S Offline
    sGrabert
    wrote on last edited by
    #1

    Hello, this question may come from a very wrong approach:wtf:, feel free to suggest a better way to solve this :-D I want to store a global dynamic list of structs inside a managed code dll. First I create the array list

    gcrootSystem::Collections::ArrayList\* parameters;
    parameters=new System::Collections::ArrayList();

    But i get a very weired exception during runtime: Handle has not been initialized when creating the ArrayList. How can I initialize this variable the correct way? Thx for your time..

    M 1 Reply Last reply
    0
    • S sGrabert

      Hello, this question may come from a very wrong approach:wtf:, feel free to suggest a better way to solve this :-D I want to store a global dynamic list of structs inside a managed code dll. First I create the array list

      gcrootSystem::Collections::ArrayList\* parameters;
      parameters=new System::Collections::ArrayList();

      But i get a very weired exception during runtime: Handle has not been initialized when creating the ArrayList. How can I initialize this variable the correct way? Thx for your time..

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      Is that code verbatim? If so, shoiuldn't you be using gcnew instead of new? (__gc new in managed extensions) Mark

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      S 1 Reply Last reply
      0
      • M Mark Salsbery

        Is that code verbatim? If so, shoiuldn't you be using gcnew instead of new? (__gc new in managed extensions) Mark

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        S Offline
        S Offline
        sGrabert
        wrote on last edited by
        #3

        Thank you for the answer, I'm fairly new to this topic (gcroot). This is the new code according to your suggestion. parameters=__gc new System::Collections::ArrayList(); But still, the same exception is raised when I try to create the ArrayList... Any idea? :-D

        M 1 Reply Last reply
        0
        • S sGrabert

          Thank you for the answer, I'm fairly new to this topic (gcroot). This is the new code according to your suggestion. parameters=__gc new System::Collections::ArrayList(); But still, the same exception is raised when I try to create the ArrayList... Any idea? :-D

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          hmmm it worked for me on VS2005... Where is this code located? The gcroot<> line is at global scope - outside of any method/function, right? What about the parameters= line? Where's that at? Where does the exception get thrown? Mark

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          S 1 Reply Last reply
          0
          • M Mark Salsbery

            hmmm it worked for me on VS2005... Where is this code located? The gcroot<> line is at global scope - outside of any method/function, right? What about the parameters= line? Where's that at? Where does the exception get thrown? Mark

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            S Offline
            S Offline
            sGrabert
            wrote on last edited by
            #5

            Yes, the gcroot<> line is at global scope. I wrote an ManagedCode-DLL based on a .NET-Assembly that is dynamically linked by a standard MFC application. The gcroot variable is created during DLL initialization (called via a procedure). Hopefully this will help you.. Currently I am working on a different approach (linked list class) to solve my problem. This seems to be the best solution as gcroot more like a "dirty" fix for something that can be solved in a more correct way, i suppose. ;) Thanks for your time

            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