none
My own COM program has an Error?

    Question

  • Hi,

    i will write a com program with a few Parameter...

    In the Interface Parameter                
           string  MyServideName      
           string  MyBagBatch         
           string  MyDatum            
           string  MyUser             
           string  MyPassword         
           string  MyPort             
                                      
    Out of the interface Paramater             
           string  outUpdated         
           string  outBagWeight       
           string  outBagDesignation  
           string  outBagType         
           string  outBagBagStatus    
           string  outBagBatch        
           string  outDate            
           string  outFehlerNr        
           string  outFehlerMeldung   

    The first progam taest for build a simple program have a bug, but what bug?

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    using System.Runtime.InteropServices;
    using Microsoft.Win32;
    using System.ServiceModel.Security;
    using System.Globalization;
    
    namespace CobCSharpOLE.Funktion001
    {
        [Guid("B214FB6D-676F-479B-893B-F72B03CE5F07")]
        [ComVisible(true)]
        [ClassInterface(ClassInterfaceType.AutoDual)]
        [ProgId("CobCSharpOLE.Funktion001")]
    
        public class Funktion001
        {
    
            public Funktion001()
            {
                 
                //Initialisierung
            }
    
            ~Funktion001()
            {
            //...
            }
    
    
            
             [DispId(3)]
            public string Logon(string password)
            {
                 return "10000";
           }
     
            [DispId(4)]
            public string Logoff()
            {
                 return "10000";
            }
     
            [DispId(2)]
            public string WriteData(string data)
            {
                return data;
            }
    
    
        }
    
    }
    

    Can anyone help me?

    Visual Studio 2012/2013/2015  / x86

    Best Regards

    Bernd

    Monday, April 24, 2017 8:16 AM

Answers

  • Your Funktion001 class isn't implementing your interface so it won't work properly for you. A client won't be able to target the CobCSharpOLE interface and use an instance of your COM class. Once you've added the interface to the class then try it again. If it still doesn't work then provide the steps you're using to generate the .TLB and the exact error it returns.

    Michael Taylor
    http://www.michaeltaylorp3.net

    • Marked as answer by Bernd Riemke Sunday, July 2, 2017 5:45 PM
    Tuesday, April 25, 2017 7:15 PM
    Moderator

All replies

  • I have now this code...

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    using System.Runtime.InteropServices;
    using Microsoft.Win32;
    using System.ServiceModel.Security;
    using System.Globalization;
    
    namespace CobCSharpOLE.Funktion001
    {
        [ComVisible(true)]
        [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
        [Guid("CD22D6D9-8B1E-4E29-A5A5-EB21A2E9C2DB")]
    
        public interface CobCSharpOLE
        {
            // From the Caller
            [DispId(1)]
            string IServideName     { get; set; }
            [DispId(2)]
            string IBagBatch        { get; set; }
            [DispId(3)]
            string IDatum           { get; set; }
            [DispId(4)]
            string IUser            { get; set; }
            [DispId(5)]
            string IPassword        { get; set; }
            [DispId(6)]
            string IPort            { get; set; }
    
            // Back tu the Caller
            [DispId(7)]
            string OUpdated         { get; set; }
            [DispId(8)]
            string OBagWeight       { get; set; }
            [DispId(9)]
            string OBagDesignation  { get; set; }
            [DispId(10)]
            string OBagType         { get; set; }
            [DispId(11)]
            string OBagBagStatus    { get; set; }
            [DispId(12)]
            string OBagBatch        { get; set; }
            [DispId(13)]
            string ODate            { get; set; }
            [DispId(14)]
            string OFehlerNr        { get; set; }
            [DispId(15)]
            string OFehlerMeldung   { get; set; }
    
        }
    
    
        [ComVisible(true)]
        [ProgId("CobCSharpOLE")]
        [Guid("B214FB6D-676F-479B-893B-F72B03CE5F07")]
        [ClassInterface(ClassInterfaceType.AutoDual)]
    
        public class Funktion001
        {
    
            string IServideName { get; set; }
            string IBagBatch { get; set; }
            string IDatum { get; set; }
            string IUser { get; set; }
            string IPassword { get; set; }
            string IPort { get; set; }
    
            string OUpdated { get; set; }
            string OBagWeight { get; set; }
            string OBagDesignation { get; set; }
            string OBagType { get; set; }
            string OBagBagStatus { get; set; }
            string OBagBatch { get; set; }
            string ODate { get; set; }
            string OFehlerNr { get; set; }
            string OFehlerMeldung { get; set; }
    
           public Funktion001()
           {
               
              //Insert code here.
           }
    
    
           ~Funktion001()
            {
                 //Aufräumen
            }
            
           //Methode mit parameter und Rückgabe
           [DispId(1)]
           public string LeseBag(string IServideName)
           {
               return "10000";
           }
     
        }
    
    }
    

    But i can not build a tlb file?

    Error:

    Can not find e Element

    ?

    Monday, April 24, 2017 10:59 AM
  • Your Funktion001 class isn't implementing your interface so it won't work properly for you. A client won't be able to target the CobCSharpOLE interface and use an instance of your COM class. Once you've added the interface to the class then try it again. If it still doesn't work then provide the steps you're using to generate the .TLB and the exact error it returns.

    Michael Taylor
    http://www.michaeltaylorp3.net

    • Marked as answer by Bernd Riemke Sunday, July 2, 2017 5:45 PM
    Tuesday, April 25, 2017 7:15 PM
    Moderator