Hello.
I have developed a COM object using ATL. It seems to work fine when
accessing it from VB.NET most of the time.
However, I want to use a delegate in VB to asynchronously run a method in
one of the interfaces in my COM module (using Delegate.BeginI nvoke()). The
interface seems to be "junk" when accessing it from the delegated VB method.
When called synchronously from the same thread using the Delegate.Invoke (),
it seems to work fine.
Anyone want to take a crack at helping me on this? I'd be very greatful.
Thanks!
- Roger
=============== ==============
The object is defined as follows:
=============== ==============
IDL:
=============== ==============
[
uuid(0C3D816E-4413-456E-BEE1-A13DC7E60BE7),
version(1.0),
helpstring("TES T COM 1.0 Type Library")
]
library TestComModuleLi b
{
importlib("stdo le32.tlb");
importlib("stdo le2.tlb");
[
uuid(7635E876-D811-4895-8D0D-B7700CCE1D9E),
helpstring("Tes tCOM Class")
]
coclass TestCOM
{
interface I_TestInterface 1;
interface I_TestInterface 2;
};
};
C++:
=============== ==============
class ATL_NO_VTABLE CTestCOM :
public CComObjectRootE x<CComMultiThre adModel>,
public CComCoClass<CTe stCOM, &CLSID_TestCOM> ,
public I_TestInterface 1,
public I_TestInterface 2,
public ISupportErrorIn fo
{
public:
CTestCOM();
DECLARE_REGISTR Y_RESOURCEID(ID R_TESTCOM)
BEGIN_COM_MAP(C TestCOM)
COM_INTERFACE_E NTRY(I_TestInte rface1)
COM_INTERFACE_E NTRY(I_TestInte rface2)
COM_INTERFACE_E NTRY(ISupportEr rorInfo)
END_COM_MAP()
DECLARE_PROTECT _FINAL_CONSTRUC T()
HRESULT FinalConstruct( );
void FinalRelease();
public:
...
};
=============== ==============
The VB.NET code is as follows:
=============== ==============
Public Class TestClass
Inherits System.Windows. Forms.Form
Windows Forms Designer generated code
Private m_TestComModule As TestComModuleLi b.TestCOM = New
TestComModuleLi b.TestCOM
Private m_TestInterface 1 As TestComModuleLi b.I_TestInterfa ce2 =
m_TestComModule
Friend Delegate Sub Test_Delegate()
Private Sub ButtonTest_Clic k(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles m_ctlButtonTest .Click
Dim tdTest As New Test_Delegate(A ddressOf Test_Method)
tdTest.BeginInv oke(Nothing, Nothing) ' Does not work!! Reference to
m_TestInterface 2 crashes app.
'tdTest.Invoke( ) ' Works just fine, but this is synchronous which I
don't want!!
End Sub
Private Sub Test_Method()
'
' m_TestInterface 2 is garbage when this method is invoked by
BeginInvoke( ).
' m_TestInterface 2 is fine and works correctly when this method is
invoked by Invoke( ).
'
If (m_TestInterfac e2 .TestMethod()) Then
...
End If
End Sub
End Class
I have developed a COM object using ATL. It seems to work fine when
accessing it from VB.NET most of the time.
However, I want to use a delegate in VB to asynchronously run a method in
one of the interfaces in my COM module (using Delegate.BeginI nvoke()). The
interface seems to be "junk" when accessing it from the delegated VB method.
When called synchronously from the same thread using the Delegate.Invoke (),
it seems to work fine.
Anyone want to take a crack at helping me on this? I'd be very greatful.
Thanks!
- Roger
=============== ==============
The object is defined as follows:
=============== ==============
IDL:
=============== ==============
[
uuid(0C3D816E-4413-456E-BEE1-A13DC7E60BE7),
version(1.0),
helpstring("TES T COM 1.0 Type Library")
]
library TestComModuleLi b
{
importlib("stdo le32.tlb");
importlib("stdo le2.tlb");
[
uuid(7635E876-D811-4895-8D0D-B7700CCE1D9E),
helpstring("Tes tCOM Class")
]
coclass TestCOM
{
interface I_TestInterface 1;
interface I_TestInterface 2;
};
};
C++:
=============== ==============
class ATL_NO_VTABLE CTestCOM :
public CComObjectRootE x<CComMultiThre adModel>,
public CComCoClass<CTe stCOM, &CLSID_TestCOM> ,
public I_TestInterface 1,
public I_TestInterface 2,
public ISupportErrorIn fo
{
public:
CTestCOM();
DECLARE_REGISTR Y_RESOURCEID(ID R_TESTCOM)
BEGIN_COM_MAP(C TestCOM)
COM_INTERFACE_E NTRY(I_TestInte rface1)
COM_INTERFACE_E NTRY(I_TestInte rface2)
COM_INTERFACE_E NTRY(ISupportEr rorInfo)
END_COM_MAP()
DECLARE_PROTECT _FINAL_CONSTRUC T()
HRESULT FinalConstruct( );
void FinalRelease();
public:
...
};
=============== ==============
The VB.NET code is as follows:
=============== ==============
Public Class TestClass
Inherits System.Windows. Forms.Form
Windows Forms Designer generated code
Private m_TestComModule As TestComModuleLi b.TestCOM = New
TestComModuleLi b.TestCOM
Private m_TestInterface 1 As TestComModuleLi b.I_TestInterfa ce2 =
m_TestComModule
Friend Delegate Sub Test_Delegate()
Private Sub ButtonTest_Clic k(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles m_ctlButtonTest .Click
Dim tdTest As New Test_Delegate(A ddressOf Test_Method)
tdTest.BeginInv oke(Nothing, Nothing) ' Does not work!! Reference to
m_TestInterface 2 crashes app.
'tdTest.Invoke( ) ' Works just fine, but this is synchronous which I
don't want!!
End Sub
Private Sub Test_Method()
'
' m_TestInterface 2 is garbage when this method is invoked by
BeginInvoke( ).
' m_TestInterface 2 is fine and works correctly when this method is
invoked by Invoke( ).
'
If (m_TestInterfac e2 .TestMethod()) Then
...
End If
End Sub
End Class