473,395 Members | 2,468 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Accessing ATL COM DLL object from VB.NET using delegate (asynchronous)

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.BeginInvoke()). 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("TEST COM 1.0 Type Library")
]
library TestComModuleLib
{
importlib("stdole32.tlb");
importlib("stdole2.tlb");
[
uuid(7635E876-D811-4895-8D0D-B7700CCE1D9E),
helpstring("TestCOM Class")
]

coclass TestCOM
{
interface I_TestInterface1;
interface I_TestInterface2;
};
};

C++:
=============================
class ATL_NO_VTABLE CTestCOM :
public CComObjectRootEx<CComMultiThreadModel>,
public CComCoClass<CTestCOM, &CLSID_TestCOM>,
public I_TestInterface1,
public I_TestInterface2,
public ISupportErrorInfo
{

public:

CTestCOM();

DECLARE_REGISTRY_RESOURCEID(IDR_TESTCOM)

BEGIN_COM_MAP(CTestCOM)
COM_INTERFACE_ENTRY(I_TestInterface1)
COM_INTERFACE_ENTRY(I_TestInterface2)
COM_INTERFACE_ENTRY(ISupportErrorInfo)
END_COM_MAP()

DECLARE_PROTECT_FINAL_CONSTRUCT()

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 TestComModuleLib.TestCOM = New
TestComModuleLib.TestCOM
Private m_TestInterface1 As TestComModuleLib.I_TestInterface2 =
m_TestComModule

Friend Delegate Sub Test_Delegate()

Private Sub ButtonTest_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles m_ctlButtonTest.Click

Dim tdTest As New Test_Delegate(AddressOf Test_Method)

tdTest.BeginInvoke(Nothing, Nothing) ' Does not work!! Reference to
m_TestInterface2 crashes app.
'tdTest.Invoke() ' Works just fine, but this is synchronous which I
don't want!!

End Sub

Private Sub Test_Method()

'
' m_TestInterface2 is garbage when this method is invoked by
BeginInvoke( ).
' m_TestInterface2 is fine and works correctly when this method is
invoked by Invoke( ).
'
If (m_TestInterface2 .TestMethod()) Then
...
End If

End Sub

End Class

Sep 20 '08 #1
0 759

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Ondrej Sevecek | last post by:
Hello, what is the difference between "event" and the only use of delegate? Why one should note events with "event" keyword when the functionality seems the same as with pure delegates? When I...
4
by: Coot | last post by:
I've been running many tests of the Asynchronous Delegate technique and I find that although BeginInvoke() does queue the method delegate onto a worker thread, it always does so on the _same_...
5
by: Matthias Steinbart | last post by:
Hi there, I'm trying to access an SQL Server through an SqlConnection within a worker thread. This doesn't seem to work. If I call the Open() method, nothing happens on the Server and no...
6
by: Sharon | last post by:
How to catch an asynchronous delegate invocation exception? The code: --------------------------------------- String message = “my message”; foreach( MyDelegate handler in...
3
by: Oscar Thornell | last post by:
Hi, I am thinking about doing all my logging asynchronously using a delegate. The main resaon for this would be performance and responsiveness of the application (an ASP.NET app). //Exampel...
3
by: Arv Carsen | last post by:
Im a beginner with C#, but as I try to access a textbox from a thread I get the error message : "An unhandled exception of type 'System.InvalidOperationException' occurred in...
21
by: alistair_henderson | last post by:
Morning All, I have some code for a website which uses 'window.open' to simulate modal dialog boxes. I use the window.closed property to decide if the window object exists at various points. ...
14
by: Mohamed Mansour | last post by:
Hey there, this will be somewhat a long post, but any response is appreciated! I have done many PInvoke in the past from C++ to C#, but I did PInvoke within C# not C++/CLI. Can someone explain...
0
by: Roger Stoller | last post by:
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...
1
by: puzzlecracker | last post by:
Below is the example that I mercilessly copied from Jon's article. In this example, I do not understand how his AsyncResult was able to retrieve delegates. In other words, using AsyncResult...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.