How to pass reference parameter to unmanaged dll

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



Answer this question

How to pass reference parameter to unmanaged dll

  • nfreelan

    engsrini wrote:
    but it shows me the error"Unable to find an entry point named 'check' in DLL 'samp.dll'."

    The function may be exported with a mangled name. Use a tool such as Depends.exe or Dumpbin.exe to see the exported entrypoint name.


    engsrini wrote:
    is there any way to call a unmanaged dll's function(which has reference parameter) from managed code without using DLL import

    No



  • Charlie545587

    Something like

    public __gc class YourClass {

    public:

    void check(UInt32& c)
    {
    c=20;
    }

    };



  • Cong Li

    My main objective is to get the data from a VC++(.NET) DLL using reference parameter, is it possible to write managed code in VC++(.NET) so that i will just add a reference to that dll, create a object for the class and access the dll's function using the object.

    since the older dll are in VC++ (which has lot of structure and unions) i have to create (wrapper) VC++ dll to access the older s, and i will the call the functions in the older dll using this wrapper in c# (since c# doesn't support unions)

    Do u understand my position

    Thanks and regards,

    Srini



  • Yingshen

    engsrini wrote:
    My main objective is to get the data from a VC++(.NET) DLL using reference parameter, is it possible to write managed code in VC++(.NET) so that i will just add a reference to that dll, create a object for the class and access the dll's function using the object.

    Yes that's possible. Then you don't need the DllImport method on the C# side.



  • David Prentice

    Thanks mattias,

    Still i am in a quit confusion how to write managed code VC++(. net), can u please show me how the method that i mentioned above will be in the managed C++. also refer me a link or site where i can learn the managed c++ programming

    Thanks n Regards,

    Srini



  • How to pass reference parameter to unmanaged dll