Exposing .Net events as COM events
Paul Schauble <[email protected]> Mon, 22 Jun 2009 23:37:16 -0700
| Newsgroups | gmane.comp.windows.devel.dotnet.advanced |
|---|---|
| Message-ID | <C4F16ABFD2953540A2928DCF7972779902B5811B@ELSCA-EXB-AV1.ticketmaster.corp> |
I hope someone can give me a hand.
I have an application that takes extensions. Extensions are called using
standard COM and talks back to the application by firing standard COM
events. I am now trying to write an extension in c# using VS2008 and
.Net framework 2.0. The skeleton source is attached below.
What happens is this
- Application creates this object. Works.
- App calls QueryInterface for IConnectionPointContainer.
Works.
- App calls FindConnectionPoint passing the GUID of the event
interface. This fail with HRESULT 0x80040200. This code means that the
specified event interface is not found.
I added code to the application to call EnumConnectionPoints to see what
connection points the extension object thinks it supports. There are
none. It's acting like the source interface is not defined.
I've found lots of samples of exposing .Net events to com. They all look
like this source.
Hopefully, someone can spot what I've done wrong. Any help would be very
much appreciated.
Thanks,
++PLS
namespace PCIExtension.TestBarCodeReader
{
// This interface duplicates the IPCIExternalEvents interface
// defined in the PCI type library
[
Guid("9FC477F2-612E-4D5F-ABF1-BB02CB5E82CF"),
InterfaceType(ComInterfaceType.InterfaceIsIDispatch),
ComVisible(true)
]
public interface IPCIExternalEvents
{
[DispId(0x1)]
void PCIAction
(
int readerIndex,
int action,
string message1,
string message2
);
}
[
Guid("8609574E-2CCA-4d26-9403-EF6CACC14D48"),
ProgId("PCIExtension.TestBarCodeReader"),
ClassInterface(ClassInterfaceType.None),
ComSourceInterfaces(typeof(IPCIExternalEvents)),
ComVisible(true)
]
public class TestBarCodeReader :
IPCIExternalDevice
{
int readerIndex;
BarCodeForm form;
void IPCIExternalDevice.ContinueTransaction(string data)
{
return; // noop for us
}
TPCIExternalDeviceType IPCIExternalDevice.DeviceType
{
get { return TPCIExternalDeviceType.tpedtBarCodeReader; }
}
void IPCIExternalDevice.Initialize(int readerIndexA, string
initString)
{
System.Diagnostics.Debugger.Break();
readerIndex = readerIndexA;
String msg = "Index: " + readerIndex.ToString() + "\r\n"
+ "Initialize: " + initString;
MessageBox.Show(msg, myself + " Initialize",
MessageBoxButtons.OK);
form = new BarCodeForm();
form.BarCodeData += OnBarCodeData;
}
void IPCIExternalDevice.SetHost(string sysId)
{
return; // Noop
}
void IPCIExternalDevice.SetParamaters(string sysId, string
parameters)
{
return; // Noop
}
void IPCIExternalDevice.StartTransaction(string Type, string
Date, string Time, string Amount)
{
return; // Noop
}
void IPCIExternalDevice.StopTransaction()
{
return; // Noop
}
void OnBarCodeData(string data)
{
PCIAction(readerIndex, (int)TPCIExternalAction.tccaBarCode,
data, "");
}
public delegate void
PCIActionEventHandler
( int readerIndex,
int action,
string message1,
string message2
);
public event PCIActionEventHandler PCIAction;
public TestBarCodeReader()
{
readerIndex = 0;
form = null;
}
}
}
CONFIDENTIALITY NOTICE:
This message contains information which may be confidential or privileged. If you are not the intended recipient, be aware that any disclosure, copying, distribution or use of the contents of this information is prohibited. If you have received this transmission in error, please notify me immediately by telephone.
===================================
View archives and manage your subscription(s) at http://peach.ease.lsoft.com/archives