CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Threaded View

  1. #1
    Join Date
    Nov 2008
    Posts
    10

    Callback function from c++ DLL

    I have found many examples that I thought may help but I cannot get my head around callback functions from the c++ DLL.

    I have the following code

    global.cs
    Code:
    	[DllImport("my.dll")]
    	unsafe public static extern UInt16 RegisterDetectCallback(void* detectCallbackFunction);
    In my own code I have tried a few things but basically want the following functionality

    program.cs
    Code:
    public void DetectCallback()
    {
        // some functionality...
    }
    
    private void button1_Click(object sender, EventArgs e)
            {
                    //various code...
                    UInt16 result = DLLFunctions.RegisterDetectCallback(DetectCallback());
            }
    I have tried a few things without success, can anybody point me in the right direction please? i know the above is incorrect as the DLL requires a pointer and i'm trying to pass a function, but hopefully the intention is clear.

    Also is it possible to do this without unsafe code? without changing the c++, or is this a requirement when passing functions as parameters in this way?

    Thanks

    Matt
    Last edited by barrow_matt; November 12th, 2008 at 12:16 PM.

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