Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / March 2005

Tip: Looking for answers? Try searching our database.

CallBack in C# from VC++

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Suyambulingam T S M - 30 Mar 2005 06:06 GMT
Hi,

I have a C# Exe and a VC++ ATL com dll.
Now I have added the the VC++ ATL com dll to my C# Exe using Add reference.
I can able to call a function in VC++ dll from my C# code.

I have another function in my C# code which has to be called from VC++ something
like a callback.

Let me explain it clearly.
VC++...

#import "D:\\ComCalling\\CSharpExe\\obj\\Debug\\CSharpExe.tlb"no_namespace
IComTestPtr g_CSharpPtr;

STDMETHODIMP CTest::SetValue(BSTR bstrValue)
{
    AFX_MANAGE_STATE(AfxGetStaticModuleState())
    CString csProgId = bstrValue;
    MessageBox ( NULL, csValue, "Title", MB_OK );
    //Now I wanted to call a callback function in C# as something like as shown below...
       //CreateInstance always creates a new instance, I wanted just a callback to the running C# exe which initiated this dll.
    HRESULT hr = g_CSharpPtr.CreateInstance ( __uuidof ( Form1 ) );

    if ( hr == 0 )
    {
        CString csTemp ( "Message From C# Exe" );
        g_CSharpPtr->Display ( csTemp.AllocSysString ( ) );
    }
    return S_OK;
}

C# code...
    public delegate bool CallBack ( );
    public interface IComTest
    {
        void Display ( string sMessage );
    }
    [ClassInterface ( ClassInterfaceType.None )]
    public class Form1 : System.Windows.Forms.Form, IComTest
    {
        public void Display ( string sMessage )
        {
            MessageBox.Show ( sMessage );
        }
        private void button1_Click(object sender, System.EventArgs e)
        {
            TestClass obj = new TestClass ( );
            obj.SetValue ( "Form1" );
The following two lines of code might be the solution, but I don't no how to pass a function pointer to the VC++ dll.
        //    CallBack objCallBack = new CallBack ( CallBackFunction );
        //    obj.SetCallBackPointer ( objCallBack );
        }

       }

Can anyone please help me out to achieve the goal.

Expecting your kind co-operation.

Thanks in advance
Egghead - 30 Mar 2005 14:18 GMT
Can you do a event at the VC++?

> Hi,
>
[quoted text clipped - 64 lines]
>
> <Id>m8f+yd7NJ02QDYBRvG/90Q==</Id>

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.