none
COM object from .net class RRS feed

  • Question

  • I have a dll ulx.dll that has the following .net classes defined. I have decorated the classes as best I can tell I am supposed to.

    namespace mytestnamespace
    {
    	[ComVisible(true)]
    	[Guid("CCAAB1A5-8E1D-403B-B603-E63418A4FB17")]
    	public interface IXXTeaEngine
    	{
    		string test();
    	}
    
    	[ClassInterface(ClassInterfaceType.AutoDual)]
    	[ComVisible(true)]
    	[Guid("8A4EF21E-73CE-48E3-8EA6-931FEC2D399B")]
    	public class XXTEAEngine : IXXTeaEngine
    	{
    		public string test()
    		{
    			return "11";
    		}
         }
    }

    How do I freaking register and use this? I want to call it from visual basic with the following small program.

    Dim obj 
    set obj = CreateObject("ULX.XXTeaEngine")
    
    retval = obj.test()
    
    WScript.Echo retval
    

     

    I'm a bit lost here. Any help would be appreciated.


    Allen Anderson - Architect http://www.richercomponents.com - (WinForm And Asp.net Controls)
    Thursday, March 31, 2011 12:59 AM

Answers

  • Hello Allen,

     

    1. To be able to successfully create an object in VB script using a specific progID, e.g. "ULX.XXTeaEngine" :

    set obj = CreateObject("ULX.XXTeaEngine")

    you need to add the ProgIdAttribute to the XXTEAEngine class :

        [ClassInterface(ClassInterfaceType.AutoDual)]
        [ComVisible(true)]
        [Guid("8A4EF21E-73CE-48E3-8EA6-931FEC2D399B")]
        [ProgId("ULX.XXTeaEngine")]  
        public class XXTEAEngine : IXXTeaEngine
        {
            public string test()
            {
                return "11";
            }
        }

     

    2. If the ProgIdAttribute is not used, the default progID generated by the C# compiler is based on the namespace and the name of the class. Hence the default progID for "XXTEAEngine" would be "mytestnamespace.XXTEAEngine".

    2.1 You can look up this progID value from the generated TLB file (using OLEView). You will see it listed as an IDL custom attribute for the XXTEAEngine coclass :

    [
      uuid(8A4EF21E-73CE-48E3-8EA6-931FEC2D399B),
      version(1.0),
      custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, "mytestnamespace.XXTEAEngine")
    ]
    coclass XXTEAEngine{
     ...
     ...
     ...
    }

    2.2 Or you can see it from the registry :

    [HKEY_CLASSES_ROOT\CLSID\{8A4EF21E-73CE-48E3-8EA6-931FEC2D399B}\ProgId]
    @="mytestnamespace.XXTEAEngine"

     

    - Bio.

    • Marked as answer by eryang Monday, April 11, 2011 3:15 AM
    Thursday, March 31, 2011 3:42 AM
  • Hello Allen,

     

    1. If you intend to use your object in a 32-bit client app (e.g. a client built with Visual Basic 6.0), set the C# project's target platform to "x86". 

    2. To do this, go to the project properties via menu item "Project"|"Properties".

    3. Go to the "Build" section.

    4. Set the "Platform target" selection to "x86".

    5. The "Any CPU" selection usually defaults to "x64" so make sure you do not select this.

     

    - Bio.

     

    • Marked as answer by eryang Monday, April 11, 2011 3:15 AM
    Thursday, March 31, 2011 6:45 AM

All replies

  • You've got the namespace/naming wrong:

     

    namespace mytestnamespace { public class XXTEAEngine ...

    Which would be:

        ULX.mytestnamespace.XXTEAEngine

    Not:
       ULX.XXTeaEngine



    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Thursday, March 31, 2011 1:31 AM
    Moderator
  • Hi Reed, thanks a bunch for the help.  I changed those and went back through the steps

    regasm /u ulx.dll
    regasm /regfile ulx.dll
    ulx.reg    (ran this from command prompt and accepted it into the registry)
    regasm /tlb ulx.dll
    regasm /codebase ulx.dll

    After all of that, I tried instancing it with the ULX.mytestnamespace.XXTEAEngine with

    Dim obj
    set obj = CreateObject("ULX.mytestnamespace.XXTEAEngine")
    retval = obj.test()
    WScript.Echo retval


    and it gave me the

    "ActiveX component can't create object"  0x800A01AD  error again. 


    One other note, I installed COM explorer and it says 'File Version: 4.0.40305.0', File Location: mscoree.dll (which doesn't make sense), Status: WARNING: Path Not defined (File should be in system path).


    any ideas?

     


    Allen Anderson - Architect http://www.richercomponents.com - (WinForm And Asp.net Controls
    Thursday, March 31, 2011 2:54 AM
  • Hello Allen,

     

    1. To be able to successfully create an object in VB script using a specific progID, e.g. "ULX.XXTeaEngine" :

    set obj = CreateObject("ULX.XXTeaEngine")

    you need to add the ProgIdAttribute to the XXTEAEngine class :

        [ClassInterface(ClassInterfaceType.AutoDual)]
        [ComVisible(true)]
        [Guid("8A4EF21E-73CE-48E3-8EA6-931FEC2D399B")]
        [ProgId("ULX.XXTeaEngine")]  
        public class XXTEAEngine : IXXTeaEngine
        {
            public string test()
            {
                return "11";
            }
        }

     

    2. If the ProgIdAttribute is not used, the default progID generated by the C# compiler is based on the namespace and the name of the class. Hence the default progID for "XXTEAEngine" would be "mytestnamespace.XXTEAEngine".

    2.1 You can look up this progID value from the generated TLB file (using OLEView). You will see it listed as an IDL custom attribute for the XXTEAEngine coclass :

    [
      uuid(8A4EF21E-73CE-48E3-8EA6-931FEC2D399B),
      version(1.0),
      custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, "mytestnamespace.XXTEAEngine")
    ]
    coclass XXTEAEngine{
     ...
     ...
     ...
    }

    2.2 Or you can see it from the registry :

    [HKEY_CLASSES_ROOT\CLSID\{8A4EF21E-73CE-48E3-8EA6-931FEC2D399B}\ProgId]
    @="mytestnamespace.XXTEAEngine"

     

    - Bio.

    • Marked as answer by eryang Monday, April 11, 2011 3:15 AM
    Thursday, March 31, 2011 3:42 AM
  • I have looked at the progid in the registry and it is set correctly but I am still failing to instance this from visual basic with the ActiveX can't create object error.

    Is it possible that on windows 7 64 bit there is something different I am supposed to do in registering this?  Is there some place I can send this test project for someone to see if I am just doing something stupid?

    thanks


    Allen Anderson - Architect http://www.richercomponents.com - (WinForm And Asp.net Controls)
    Thursday, March 31, 2011 6:36 AM
  • Hello Allen,

     

    1. If you intend to use your object in a 32-bit client app (e.g. a client built with Visual Basic 6.0), set the C# project's target platform to "x86". 

    2. To do this, go to the project properties via menu item "Project"|"Properties".

    3. Go to the "Build" section.

    4. Set the "Platform target" selection to "x86".

    5. The "Any CPU" selection usually defaults to "x64" so make sure you do not select this.

     

    - Bio.

     

    • Marked as answer by eryang Monday, April 11, 2011 3:15 AM
    Thursday, March 31, 2011 6:45 AM
  • I've got a similar issue. I have a C# DLL that I want to use from a VB6 program on Windows 7 64

    I cannot find the "Platform Target" option anywhere in the property pages. I'm trying to do this from vs2003 because I'm working on legacy code.

    Monday, May 14, 2012 6:26 PM