CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2008
    Posts
    78

    Get Function Address

    Hello All,

    I have imported a .dll into my C# project. One of the function in dll is:

    extern "C" __declspec(dllexport) void SetCallbackProcAddr(long lProcAddress)
    {
    g_CallbackProc = (decodePacket)lProcAddress;
    }

    which takes address of function from client project.

    In my client project, I am having :

    namespace Client
    {

    Class useDLL
    {
    [DllImport("exampleDLL.dll", EntryPoint = "SetCallbackProcAddr", ExactSpelling = false, CharSet = CharSet.Unicode, SetLastError = true)]
    public static extern unsafe void SetCallbackProcAddr(long* apPointer);

    //And I would like to pass below's function address to above function

    public void CallBack(IntPtr apData, int aDataSize)
    {

    }

    //Function test is called from main
    public void test()
    {
    Client.SetCallbackProcAddr(????????); //What should replace ?????????
    }
    //Has someone any idea how should I pass on address of CallBack function )

    }
    }

    I am new to C# and want first to import my projects in form of dll. example.dll is one of the projects which is using c++ and c files.

    Can someone be of help?

    Thanks and regards,
    Ricky

  2. #2
    Join Date
    Mar 2004
    Location
    33°11'18.10"N 96°45'20.28"W
    Posts
    1,808

    Re: Get Function Address

    try using a delegate.

  3. #3
    Join Date
    Mar 2008
    Location
    IRAN
    Posts
    811

    Re: Get Function Address

    yes delegate is like c++ function pointer
    Please rate my post if it was helpful for you.
    Java, C#, C++, PHP, ASP.NET
    SQL Server, MySQL
    DirectX
    MATH
    Touraj Ebrahimi
    [toraj_e] [at] [yahoo] [dot] [com]

  4. #4
    Join Date
    Aug 2008
    Posts
    78

    Re: Get Function Address

    Thanks Toraj and MadHatter. It is working now.

    Am using delegate now and to get memory address I had to use

    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
    public unsafe delegate void callbackDelegate(in param)


    regards,
    Ricky

  5. #5
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104

    Re: Get Function Address

    Ricky, please use CODE tags in future, when you post code
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured