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. Type check wont work properly

Type check wont work properly

Scheduled Pinned Locked Moved Managed C++/CLI
questiontoolshelp
3 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.
  • P Offline
    P Offline
    Polity4h
    wrote on last edited by
    #1

    Alright, im working on a Plugin script in my application. Every plugin got saved in a seperated Dll with a main class: public ref class Plugin : public PluginInterface::IPlugin IPlugin is a abstract class with some basic info like Name, Date, Descryption and a few virtual methods, Initialize and so on. Now my load function: void cPlugins::AddPlugin(System::String ^FileName) { Assembly^ PluginAssembly = Assembly::LoadFrom(FileName); for each (Type^ PluginType in PluginAssembly->GetTypes()){ if (PluginType->IsPublic){ if (!PluginType->IsAbstract){ Types::AvailablePlugin^ NewPlugin = gcnew Types::AvailablePlugin(); NewPlugin->Instance = dynamic_cast(Activator::CreateInstance(PluginAssembly->GetType(PluginType->ToString()))); if ((NewPlugin != nullptr)&&(NewPlugin->Instance!=nullptr)){ NewPlugin->AssemblyPath = FileName; NewPlugin->Instance->Host = this; NewPlugin->Instance->Initialize(); if (!this->AvailPlugins) this->AvailPlugins = gcnew Types::AvailablePlugins(); this->AvailPlugins->Add(NewPlugin); } } } } } or at least, code above is something like that. i tried to many different things. The definition of AvailablePlugin is like this, public ref class AvailablePlugin { public: IPlugin^ Instance; String^ AssemblyPath; }; Now, for some or other reason, He wont give me a valid class. << Means, that the when i do a typecheck, he just says its a total different type. dynamic_cast(Activator::CreateInstance(***)) wont agree with it. How can i make this work? can anyone help? Thanks already

    2 1 Reply Last reply
    0
    • P Polity4h

      Alright, im working on a Plugin script in my application. Every plugin got saved in a seperated Dll with a main class: public ref class Plugin : public PluginInterface::IPlugin IPlugin is a abstract class with some basic info like Name, Date, Descryption and a few virtual methods, Initialize and so on. Now my load function: void cPlugins::AddPlugin(System::String ^FileName) { Assembly^ PluginAssembly = Assembly::LoadFrom(FileName); for each (Type^ PluginType in PluginAssembly->GetTypes()){ if (PluginType->IsPublic){ if (!PluginType->IsAbstract){ Types::AvailablePlugin^ NewPlugin = gcnew Types::AvailablePlugin(); NewPlugin->Instance = dynamic_cast(Activator::CreateInstance(PluginAssembly->GetType(PluginType->ToString()))); if ((NewPlugin != nullptr)&&(NewPlugin->Instance!=nullptr)){ NewPlugin->AssemblyPath = FileName; NewPlugin->Instance->Host = this; NewPlugin->Instance->Initialize(); if (!this->AvailPlugins) this->AvailPlugins = gcnew Types::AvailablePlugins(); this->AvailPlugins->Add(NewPlugin); } } } } } or at least, code above is something like that. i tried to many different things. The definition of AvailablePlugin is like this, public ref class AvailablePlugin { public: IPlugin^ Instance; String^ AssemblyPath; }; Now, for some or other reason, He wont give me a valid class. << Means, that the when i do a typecheck, he just says its a total different type. dynamic_cast(Activator::CreateInstance(***)) wont agree with it. How can i make this work? can anyone help? Thanks already

      2 Offline
      2 Offline
      2bee
      wrote on last edited by
      #2

      Is this line correct? NewPlugin->Instance = dynamic_cast(Activator::CreateInstance(PluginAssembly->GetType(PluginType->ToString()))); I can't see the type your are casting to? Probably a typo in your post. Wasn't it dynamic_cast < type-id > ( expression ) I guess you are using , don't you?

      P 1 Reply Last reply
      0
      • 2 2bee

        Is this line correct? NewPlugin->Instance = dynamic_cast(Activator::CreateInstance(PluginAssembly->GetType(PluginType->ToString()))); I can't see the type your are casting to? Probably a typo in your post. Wasn't it dynamic_cast < type-id > ( expression ) I guess you are using , don't you?

        P Offline
        P Offline
        Polity4h
        wrote on last edited by
        #3

        yes i am, as i already said, that piece of code is all messed up :)

        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