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. Dynamic event delegate and the 'this' pointer

Dynamic event delegate and the 'this' pointer

Scheduled Pinned Locked Moved Managed C++/CLI
databasedata-structuresdebugginghelpquestion
1 Posts 1 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
    Peter JC
    wrote on last edited by
    #1

    I create dynamic event delegates (see code at end of question), which call a common method. When an event is fired, my dynamic method is called and in turn calls the common method. My problem is that when in the common method the 'this' pointer is meaningless (as if it thinks its a static), so I can't access members of my class. I have a temporary work around where I build in the members to the dynamic method and pass them to the common method! however it still breaks in the debugger and I have to but gives the desired result. There is something not right with my dynamic method and if anyone can put me on the right track then that would be greatly appreciated. Thanks Peter. void EventHandler::CreateDynamicEventHandler() { System::Type ^ eventClass = m_eventSource->GetTarget()->GetType(); // Get event info and the type of delegate. array^ args; EventInfo ^ eventInfo = eventClass->GetEvent(m_eventName); System::Type ^ tDelegate = eventInfo->EventHandlerType; MethodInfo^ invoke = tDelegate->GetMethod( "Invoke" ); // The generated delegate will call a standard method (CommonEventHandler) // to pass the events data onto Jade. Get the method info for that method. array^ commonArgs = {System::String::typeid, array::typeid}; MethodInfo ^ methodInfo = EventHandler::typeid->GetMethod("CommonEventHandler", commonArgs); // Create dynamic method array ^ paramTypes = GetDelegateParameterTypes(tDelegate); DynamicMethod ^ dynamicMethod = gcnew DynamicMethod("Dyna", nullptr, paramTypes, ::EventHandler::typeid); // Generate method body ILGenerator ^ ilGen = dynamicMethod->GetILGenerator(); // Create a local variable 'args' int paramCount = paramTypes->Length; LocalBuilder ^ localObj = ilGen->DeclareLocal(array::typeid); // create object array of proper length ilGen->Emit(OpCodes::Ldc_I4, paramCount); ilGen->Emit(OpCodes::Newarr, System::Object::typeid); ilGen->Emit(OpCodes::Stloc_0); // Now put all arguments in the object array for (System::Int32 i= 0; iEmit(OpCodes::Ldloc_0); // Local variable - the array ilGen->Emit(OpCodes::Ldc_I4, i); // Index into array ilGen->Emit(OpCodes::Ldarg_S, b); // Value to save is in bth argument to this method if (paramTypes[i]->IsValueType) ilGen->Emit(OpCodes::Box, paramTypes[i]); // Box value types

    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