Click here to Skip to main content
15,891,409 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Now i cannot set the call back function pointer to C# COM DLL.
Callback function made by MFC.

Please advise me how to set.

C++(MFC) code
C++
]
delegate bool CallBack(int hwnd, int lParam);

class CMyDlg : public CDialog
{

Init()
{
    cpi = NULL;
    CoInitialize(NULL);
    HRESULT hr = CoCreateInstance(CLSID_InterfaceImplementation,
        NULL, CLSCTX_INPROC_SERVER,
        IID_IManagedInterface, (LPVOID*)&cpi);
    retval = 0;
    if (FAILED(hr))
    {
        printf("Couldn't create the instance!... 0x%x\n", hr);
    }
    else
    {
        CallBack^ myCallBack = gcnew CallBack(&Report);
        cpi->SetCallback( myCallBack );
    }
}

static bool Report(int hwnd, int lParam)
    {
       return true;
    }
}    ;


C# COM DLL code
C#
namespace DLL_COM_TEST
{
    public delegate bool CallBack(int hwnd, int lParam);

    public interface IDLL_COM_TESTInterface
    {
        void Execute();
        void SetCallback(CallBack funcCB);
    }
    
    public class IDLL_COM_TESTImplementation: IDLL_COM_TESTInterface
    {
        CallBack funcCB_E;
        public void SetCallback(CallBack funcCB)
        {
            funcCB_E = funcCB;
        }
        public void Execute()
        {
             funcCB_E(1111, 1);
         }
    }


Error is here
CSS
error C3756: 'CallBack': Definition of delegate will conflict with existing symbol .
Please check 'CallBack' 
'myCallBack' is not defined
error C2061: error 'CallBack'
error C2065: 'myCallBack' : is not defined


Best regards
Posted
Comments
Richard MacCutchan 16-Jul-15 3:56am    
Why are you trying to mix C++/CLI code inside an MFC dialog?
Member 9991638 16-Jul-15 4:35am    
Thank you for message.
Now , I don't understand how to Establish.

My aim is just want to call the callback function of the MFC from C# COM DLL.

reference is here.
https://msdn.microsoft.com/ja-jp/library/d186xcf0(v=vs.110).aspx
Richard MacCutchan 16-Jul-15 5:04am    
That reference is about calling an unmanaged DLL from C#. Not what you are doing. And I do ont think you can mix CLR with MFC.
Member 9991638 16-Jul-15 19:37pm    
>That reference is about calling an unmanaged DLL from C#.
Yes , I want to use changing mix CLR with MFC from mix CLR with MFC.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900