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. C#
  4. C# Delegates in vc++

C# Delegates in vc++

Scheduled Pinned Locked Moved C#
csharphelpc++wpfregex
2 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.
  • A Offline
    A Offline
    Anu_Bala
    wrote on last edited by
    #1

    Hi, Im using C# in VC++ for WPF. I create one Delegates in C# as follow

    public delegate void NameTab(string msg);
    public static event NameTab CallClick;

    private void Callbutton_Click(object sender, RoutedEventArgs e)
    {
    String msg = comboBox1.Text;
    CallClick(msg);
    }

    Im using in my VC++ code as follow

    Tabcontrol::SecondTab::CallClick += gcnew Tabcontrol::SecondTab::NameTab(OnCallClick);

    And OnCallClick fucntion is

    static void OnCallClick(CString msg)
    {
    }

    But it shows error error C3352: 'OnCallClick' : the specified function does not match the delegate type 'void (System::String ^)' Im using button click event handler and its woking perfectly.But this only shows error.As i want to get the text in combox,im passing that text as parametes and im uisng that text in vc++ code. pls help me.

    Anu

    T 1 Reply Last reply
    0
    • A Anu_Bala

      Hi, Im using C# in VC++ for WPF. I create one Delegates in C# as follow

      public delegate void NameTab(string msg);
      public static event NameTab CallClick;

      private void Callbutton_Click(object sender, RoutedEventArgs e)
      {
      String msg = comboBox1.Text;
      CallClick(msg);
      }

      Im using in my VC++ code as follow

      Tabcontrol::SecondTab::CallClick += gcnew Tabcontrol::SecondTab::NameTab(OnCallClick);

      And OnCallClick fucntion is

      static void OnCallClick(CString msg)
      {
      }

      But it shows error error C3352: 'OnCallClick' : the specified function does not match the delegate type 'void (System::String ^)' Im using button click event handler and its woking perfectly.But this only shows error.As i want to get the text in combox,im passing that text as parametes and im uisng that text in vc++ code. pls help me.

      Anu

      T Offline
      T Offline
      teejayem
      wrote on last edited by
      #2

      that is because your callback needs to accept a System.String datatype instead of CString. If you need to marshal String^ to Cstring just do the following.

      static void OnCallClick(String ^msg)
      {
      CString nativeString = msg;
      }

      And guess what! You may have noticed that you don't have to marshal System.String into a CString in your code. That is because of a little trick in cstringt.h

      #if defined(__cplusplus_cli)

      template <class SystemString>
      CStringT( SystemString^ pString ) :
      	CThisSimpleString( StringTraits::GetDefaultManager() )
      {
      	cli::pin\_ptr<const System::Char> pChar = PtrToStringChars( pString );
      	const wchar\_t \*psz = pChar;
      	\*this = psz;
      }
      

      this function handles the marshaling for you :)

      Don't be overcome by evil, but overcome evil with good

      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