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. unmanaged callback (for dll interaction)

unmanaged callback (for dll interaction)

Scheduled Pinned Locked Moved C#
c++helpquestion
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.
  • P Offline
    P Offline
    Pixinger77
    wrote on last edited by
    #1

    Hi, My problem is to create a delegate for the following callback definition (c++ syntax): typedef void (__stdcall *UnmanagedCallback)(std::wstring& WStringObject, const wchar_t* StringData, unsigned __int32 StringLength); I tried something like this: public delegate void UnmanagedCallbackDelegate(ref string stringObject, string stringData, UInt32 stringLength); or: public delegate void UnmanagedCallbackDelegate(ref string stringObject, [MarshalAs(UnmanagedType.LPWStr)]string stringData, UInt32 stringLength); The callback fired from the dll is a _stdcall. Someone has a clue what I do wrong? Thanks in advance... Uwe.

    T 1 Reply Last reply
    0
    • P Pixinger77

      Hi, My problem is to create a delegate for the following callback definition (c++ syntax): typedef void (__stdcall *UnmanagedCallback)(std::wstring& WStringObject, const wchar_t* StringData, unsigned __int32 StringLength); I tried something like this: public delegate void UnmanagedCallbackDelegate(ref string stringObject, string stringData, UInt32 stringLength); or: public delegate void UnmanagedCallbackDelegate(ref string stringObject, [MarshalAs(UnmanagedType.LPWStr)]string stringData, UInt32 stringLength); The callback fired from the dll is a _stdcall. Someone has a clue what I do wrong? Thanks in advance... Uwe.

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

      You can use the DllImportAttribute[^] to specify the CallingConvention[^], but I don't think .Net will marshal STL strings to a String. You would probably have to specify those parameters as an IntPtr, then convert the code from this[^] article to C# (it's shown in the "Converting String to std::string" section).

      Take care, Tom ----------------------------------------------- Check out my blog at http://tjoe.wordpress.com

      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