Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. COM
  4. Dumb COM Interop question

Dumb COM Interop question

Scheduled Pinned Locked Moved COM
comcsharpsysadminhelpquestion
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    steve_hocking
    wrote on last edited by
    #1

    Hi, I'm pretty new to all this interop stuff, and I've come up against a bit of an obstacle. In my method I'm trying to return an instance of another class from C# assembly. Great! Except it doesn't work. :( I keep getting Error 5 "Object variable or with block not set" in my VB client. Here's some sample code I knocked together to demonstrate... C# COM Server using System; using System.Runtime.InteropServices; namespace COMReturnTest { [Guid("883EF833-3874-4831-9757-B44E987E80DF")] [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)] public interface _ReturnType { string TestString { get; } int TestInt { get; } } [Guid("29B3F02E-27A6-4535-8835-62D23BA2DA1E")] [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)] public interface _TestClass { COMReturnTest._ReturnType StringEmptyTest(); COMReturnTest._ReturnType StringNullTest(); COMReturnTest._ReturnType StringSetTest(); System.String StringReturn(); } [Guid("01A699E1-05ED-404e-A5B9-7C2735F97268")] [ClassInterface(ClassInterfaceType.None)] [ProgId("COMReturnTest.ReturnType")] public class ReturnType : COMReturnTest._ReturnType { #region class members private string _teststring = String.Empty; private int _testint = 0; #endregion #region class constructors public ReturnType(string TestString, int TestInt) { _teststring = TestString; _testint = TestInt; } #endregion #region _ReturnType Members public string TestString { get { return _teststring; } } public int TestInt { get { return _testint; } } #endregion } [Guid("73FB94E2-23EA-4e2c-A366-B234415FB4FE")] [ClassInterface(ClassInterfaceType.None)] [ProgId("COMReturnTest.TestClass")] public class TestClass : COMReturnTest._TestClass { public TestClass() { } #region _TestClass Members public COMReturnTest._ReturnType StringEmptyTest() { COMReturnTest.ReturnType rt = new COMReturnTest.ReturnType(String.Empty, 100); return rt; } public COMReturnTest._ReturnType StringNullTest() { COMReturnTest.ReturnType rt = new COMReturnTest.ReturnType(null, 100); return rt; } //[return: MarshalAs(System.Runtime.InteropServices.UnmanagedType.IDispatch)] public COMReturnTest._ReturnType StringSetTest() { COMReturnTest.ReturnType rt = new COMReturnTest.ReturnType("bugger", 100); return rt; } public String StringReturn() { return "Buggeration!!!"; } #endregion } }

    S 1 Reply Last reply
    0
    • S steve_hocking

      Hi, I'm pretty new to all this interop stuff, and I've come up against a bit of an obstacle. In my method I'm trying to return an instance of another class from C# assembly. Great! Except it doesn't work. :( I keep getting Error 5 "Object variable or with block not set" in my VB client. Here's some sample code I knocked together to demonstrate... C# COM Server using System; using System.Runtime.InteropServices; namespace COMReturnTest { [Guid("883EF833-3874-4831-9757-B44E987E80DF")] [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)] public interface _ReturnType { string TestString { get; } int TestInt { get; } } [Guid("29B3F02E-27A6-4535-8835-62D23BA2DA1E")] [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)] public interface _TestClass { COMReturnTest._ReturnType StringEmptyTest(); COMReturnTest._ReturnType StringNullTest(); COMReturnTest._ReturnType StringSetTest(); System.String StringReturn(); } [Guid("01A699E1-05ED-404e-A5B9-7C2735F97268")] [ClassInterface(ClassInterfaceType.None)] [ProgId("COMReturnTest.ReturnType")] public class ReturnType : COMReturnTest._ReturnType { #region class members private string _teststring = String.Empty; private int _testint = 0; #endregion #region class constructors public ReturnType(string TestString, int TestInt) { _teststring = TestString; _testint = TestInt; } #endregion #region _ReturnType Members public string TestString { get { return _teststring; } } public int TestInt { get { return _testint; } } #endregion } [Guid("73FB94E2-23EA-4e2c-A366-B234415FB4FE")] [ClassInterface(ClassInterfaceType.None)] [ProgId("COMReturnTest.TestClass")] public class TestClass : COMReturnTest._TestClass { public TestClass() { } #region _TestClass Members public COMReturnTest._ReturnType StringEmptyTest() { COMReturnTest.ReturnType rt = new COMReturnTest.ReturnType(String.Empty, 100); return rt; } public COMReturnTest._ReturnType StringNullTest() { COMReturnTest.ReturnType rt = new COMReturnTest.ReturnType(null, 100); return rt; } //[return: MarshalAs(System.Runtime.InteropServices.UnmanagedType.IDispatch)] public COMReturnTest._ReturnType StringSetTest() { COMReturnTest.ReturnType rt = new COMReturnTest.ReturnType("bugger", 100); return rt; } public String StringReturn() { return "Buggeration!!!"; } #endregion } }

      S Offline
      S Offline
      steve_hocking
      wrote on last edited by
      #2

      Of course after about twenty hours looking at this I discovered what the error was immediately after posting!!! :doh: steve_hocking wrote: _Private Sub Command3_Click() On Error GoTo Command3_Click_Err Dim tc As COMReturnTest.TestClass Dim rt As COMReturnTest.ReturnType Set tc = New COMReturnTest.TestClass_ **SET** _rt = tc.StringSetTest Command3_Click_Err: MsgBox "An error occurred" + vbCrLf + vbCrLf + "Error: 0x" + Hex(Err.Number) + vbCrLf + _ "Description: " + Err.Description + vbCrLf + "Source: " + Err.Source End Sub_ You need to SET objects in wonderful vb... :doh: Thanks anyway, I'm just getting me coat, if you can call a taxi for me... :-O

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups