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. How to pass reference parameter to unmanaged dll

How to pass reference parameter to unmanaged dll

Scheduled Pinned Locked Moved C#
csharpc++helptutorialquestion
3 Posts 3 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
    Sriinii
    wrote on last edited by
    #1

    Hi I have a function in unmanaged(VC++) dll which is accepting a refernce parameter void check(UInt32& c) { c=20; } I want to call this function from my managed code(C#) so i used the following code class Program { [DllImport("samp.dll")] public static extern void check(ref UInt32 c); static void Main(string[] args) { UInt32 s = 0; check(ref s); Console.WriteLine(s.ToString ()); Console.ReadLine(); } } but it shows me the error"Unable to find an entry point named 'check' in DLL 'samp.dll'." is there any way to call a unmanaged dll's function(which has reference parameter) from managed code without using DLL import?? if yes please send me a sample code. Thanks in advance Srini

    M 1 Reply Last reply
    0
    • S Sriinii

      Hi I have a function in unmanaged(VC++) dll which is accepting a refernce parameter void check(UInt32& c) { c=20; } I want to call this function from my managed code(C#) so i used the following code class Program { [DllImport("samp.dll")] public static extern void check(ref UInt32 c); static void Main(string[] args) { UInt32 s = 0; check(ref s); Console.WriteLine(s.ToString ()); Console.ReadLine(); } } but it shows me the error"Unable to find an entry point named 'check' in DLL 'samp.dll'." is there any way to call a unmanaged dll's function(which has reference parameter) from managed code without using DLL import?? if yes please send me a sample code. Thanks in advance Srini

      M Offline
      M Offline
      Marc 0
      wrote on last edited by
      #2

      You can try using out:

      [DllImport("samp.dll")]
      public static extern void check(out ref UInt32 c);

      Dunno if it works though (maybe only out, no ref?) ...


      "..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.." -- Mark McCormick


      || Fold With Us! || Pensieve || VG.Net ||

      R 1 Reply Last reply
      0
      • M Marc 0

        You can try using out:

        [DllImport("samp.dll")]
        public static extern void check(out ref UInt32 c);

        Dunno if it works though (maybe only out, no ref?) ...


        "..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.." -- Mark McCormick


        || Fold With Us! || Pensieve || VG.Net ||

        R Offline
        R Offline
        Ravi Bhavnani
        wrote on last edited by
        #3

        I believe both out and ref will work, but ref will cause the compiler to complain if the parameter hasn't been initialized before calling check(). /ravi My new year's resolution: 2048 x 1536 Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)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