all groups > dotnet interop > march 2005 >
You're in the

dotnet interop

group:

CallBack in C# from VC++


CallBack in C# from VC++ Suyambulingam T S M via .NET 247
3/29/2005 9:06:03 PM
dotnet interop:
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
--------------------------------
From: Suyambulingam T S M

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

Re: CallBack in C# from VC++ Egghead
3/30/2005 1:18:12 PM
Can you do a event at the VC++?

"Suyambulingam T S M via .NET 247" <anonymous@dotnet247.com> wrote in
message news:%230s7sYONFHA.2680@TK2MSFTNGP09.phx.gbl...
[quoted text, click to view]

AddThis Social Bookmark Button