I've written a driver using the Ascom LocalServer template, and it works just fine so far. But I want to add an extended interface for use by a "private" app. I first added support for the IConform interface as a model for how to do this and that was also straightforward. But when I then added my own private interface - IbwExtTelescope - using the same type of "decorations" I saw on the IConform interface, the COM object can't be cast to (IbwExtTelescope). Here's a snippet of the code:
namespace ASCOM.bwAstroPhysics
{
[ComVisible(true)]
[Guid("21497dbb-2674-4287-bff5-6baf439738a0")]
public interface IbwExtTelescope
{
void SendBacklashCommand(int iCmdInx, int iSecs);
}
}
So here’s the test code:
Object oCom;
Object oType;
ASCOM.bwAstroPhysics.IbwExtTelescope oExtScope;
IConform oConform;
oType = Type.GetTypeFromProgID("ASCOM.bwAstroPhysics.Telescope");
oCom = Activator.CreateInstance(oType);
oConform = (IConform)oCom; // This works correctly
And one line later, this fails:
oExtScope = (ASCOM.bwAstroPhysics.IbwExtTelescope) oCom; // and this breaks
The error returned says: Unable to cast COM object of type 'System.__ComObject' to interface type 'ASCOM.bwAstroPhysics.IbwExtTelescope'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{328956A7-C95F-3EE5-9744-A189AA38DBDD}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
Here's what I have determined with debugging: 1) My private interface is registered - if I use the debugger inside the LocalServer.cs and Class.cs code, I can force a call on MarshalGetComInterface on my interface, and it is found. 2) I can cruise around in the Registry and find the GUID in the error message and things look right, at least superficially.
Some other info that might be relevant: 1) This is being done on my XP SP3 development system, Ascom 5.5 installed and running fine, everything up to date. I am working with Visual C# 2008 using VS Express. 2) I have not created or run an installer for my driver - so I don't know if there's something magic that would happen there.
It seems like IConform got some magical treatment done to it that I can't replicate - but I'm just guessing because I'm not very knowledgeable about COM. But since what I'm trying to do is likely to be a common desire, I thought maybe you would help me out. By the way, the driver templates work really well - I've been able to spend 99% of my time just thinking about the telescope mount and how to control it properly. This is the first time I've had to think much about COM or Windows weirdness. Nice job!
Thanks.
Bruce W.
