Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Basically we have a series of COM objects, we are accessing quite nicely from .NET4.

But they all have an ability to access a logging object - to save away information, but of course it's a COM interface. So I tried to simulate it from an IDL file into the .NET4 host program, so it could pass down the object, and basically get the logging back into the main program to write to log4net. BUT all I get is casting failures and it sure looks like alot of other samples I have seen and very very confused am I.

I have been able to of course create the original COM logging object and pass it in, but then I have 2 mixed logs which of couse I am trying to consolidate into one. Including capturing the console output and trace output too, so hopefully the whole world is in that log4net file!!

And Ihave tried turning on/off almost everything I can dream of, just trying to make it change behaviour at all.

Here is the code accessing the COM object and trying to pass down the interface

C#
InternalLogger  logger = new InternalLogger();

BRIPTemplateCache oTemplateCache = new BRIPTemplateCache();
oTemplateCache.LoggingObject = logger;

AND FAILS with casting exception.


Here is the object defined in .NET host
C#
[ComVisible(true)]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
[Guid("727198A8-D1DB-11D2-9470-00104B96441E")]
[AutomationProxy(true)]
public interface ICTILog
{
    [DispId(1)]
    string appID { set; }

    [DispId(2)]
    string appName { get; set; }

    [DispId(3)]
    void close();

    [DispId(4)]
    int commitOnWrite { get; set; }

    [DispId(5)]
    int defaultSeverity { get; set; }

    [DispId(6)]
    int isOpen { get; }

    [DispId(7)]
    int isSuspended { get; }

    [DispId(8)]
    void open();

    [DispId(9)]
    void readInit(string appName);

    [DispId(10)]
    void readInitEx(string initLoocation, string appName, string appVersion);

    [DispId(11)]
    void resume();

    [DispId(12)]
    int severityFilter { get; set; }

    [DispId(13)]
    int stampAppID { get; set; }

    [DispId(14)]
    int stampSeverity{ get; set; }

    [DispId(15)]
    int stampTime{ get; set; }

    [DispId(16)]
    void suspend();

    [DispId(17)]
    void write(int severity, string msg);

    [DispId(18)]
    void writeDefSev(string msg);

    [DispId(29)]
    int stampThreadID { get; set; }
}

[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
class InternalLogger : ICTILog
{
    private string sappID;
    private string sappName;
    private int icommitOnWrite = 0;
    private int idefaultSeverity = 0;
    private int iisOpen = 0;
    private int iisSuspended = 0;
    private int iseverityFilter = 0;
    private int istampAppID = 0;
    private int istampSeverity = 0;
    private int istampTime = 0;
    private int istampThreadID = 0;

    public string appID {
        set { sappID = value; }
    }

    public string appName {
        get { return sappName; }
        set { sappName = value; }
    }

    public void close() { }

    public int commitOnWrite {
        get { return icommitOnWrite; }
        set { icommitOnWrite = value; }
    }

    public int defaultSeverity {
        get { return idefaultSeverity; }
        set{ idefaultSeverity = value; }
    }

    public int isOpen {
        get { return iisOpen; }
        set { iisOpen = value; }
    }

    public int isSuspended {
        get { return iisSuspended; }
        set { iisSuspended = value; }
    }

    public void open() { }

    public void readInit( string appName ) { }

    public void readInitEx( string initLoocation, string appName, string appVersion) { }

    public void resume() { }

    public int severityFilter {
        get { return iseverityFilter; }
        set { iseverityFilter = value; }
    }

    public int stampAppID {
        get { return istampAppID; }
        set { istampAppID = value; }
    }

    public int stampSeverity {
        get { return istampSeverity; }
        set { istampSeverity = value; }
    }

    public int stampTime {
        get { return istampTime; }
        set { istampTime = value; }
    }

    public void suspend() { }

    public void write(int severity, string msg) { }

    public void writeDefSev(string msg) { }

    public int stampThreadID {
        get { return istampThreadID; }
        set { istampThreadID = value; }
    }
}
Posted
Updated 20-Aug-13 19:13pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900