none
An unhandled exception of type 'System.Runtime.InteropServices.SEHException' occurred in ComConsoleTrial4App.exe. External component has thrown an exception. RRS feed

  • Question

  • Hi, I'm new to creating & consuming COM components. I created a COM component using C#.Net 2010 and tried consuming it using VisualC++2010. The c#.net project was a class library. I created it, installed in GAC and registered it using REGASM. All these worked fine. In the consuming VC++2010 application's debug folder i was able to create the respective ".tlh" file also. Till this everything works fine (as said in the dev article). When i tried running the VC++2010 application im getting "An unhandled exception of type 'System.Runtime.InteropServices.SEHException' occurred  in ComConsoleTrial4App.exe. External component has thrown an exception." I'm not able to figure out why this is and wat is the fix for that.. pls help me rectifying it.. I have inserted the code block of both, the class library and the consuming application(VC++2010)

    Code of class library (which im converting as COM component)

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;
    
    namespace NewApptrial4com
    {
      public interface ApptryclassInt
      {
        void Displaymessage();
      }
      public class Apptryclass
      {
        public void Displaymessage()
        {
          MessageBox.Show("Apptryclass");
        }
      }
    }
    

     

    Code of the consuming VC++2010 application

    // ComConsoleTrial4App.cpp : Defines the entry point for the console application.
    //
    
    #include "stdafx.h"
    #import "C:\\Users\\xxx\\Documents\\Visual Studio 2010\\Projects\\NewApptrial4com\\NewApptrial4com\\bin\\Release\\NewApptrial4com.tlb"
    
    using namespace NewApptrial4com;
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    	// Initialize COM.
      HRESULT hr = CoInitialize(NULL);
    	// Create the interface pointer.
    	ApptryclassIntPtr iObj(__uuidof(Apptryclass));	
    	iObj->Displaymessage();
    	CoUninitialize();
    	
    	return 0;
    }
    

     

    Code of the .tlh file

    // Created by Microsoft (R) C/C++ Compiler Version 10.00.30319.01 (4ab4e2e5).
    //
    // c:\users\mmanickam\documents\visual studio 2010\projects\comconsoletrial4app\comconsoletrial4app\debug\apptrial4com.tlh
    //
    // C++ source equivalent of Win32 type library C:\\Users\\mmanickam\\Documents\\Visual Studio 2010\\Projects\\Apptrial4Com\\Apptrial4Com\\bin\\Release\\apptrial4com.tlb
    // compiler-generated file created 04/21/11 at 09:17:34 - DO NOT EDIT!
    
    #pragma once
    #pragma pack(push, 8)
    
    #include <comdef.h>
    
    namespace Apptrial4com {
    
    //
    // Forward references and typedefs
    //
    
    struct __declspec(uuid("132f699a-3315-468d-a9bf-c669f0656c8d"))
    /* LIBID */ __Apptrial4com;
    struct __declspec(uuid("79eb0b45-13ec-39ca-8381-a3bb5d48854d"))
    /* dual interface */ Apptrial4ComInt;
    struct /* coclass */ Apptrial4com;
    struct __declspec(uuid("7b906789-57a8-320e-b0ce-ba9d74d62bcf"))
    /* dual interface */ _Apptrial4com;
    
    //
    // Smart pointer typedef declarations
    //
    
    _COM_SMARTPTR_TYPEDEF(Apptrial4ComInt, __uuidof(Apptrial4ComInt));
    _COM_SMARTPTR_TYPEDEF(_Apptrial4com, __uuidof(_Apptrial4com));
    
    //
    // Type library items
    //
    
    struct __declspec(uuid("79eb0b45-13ec-39ca-8381-a3bb5d48854d"))
    Apptrial4ComInt : IDispatch
    {
      //
      // Wrapper methods for error-handling
      //
    
      HRESULT Displaymessage ( );
    
      //
      // Raw methods provided by interface
      //
    
       virtual HRESULT __stdcall raw_Displaymessage ( ) = 0;
    };
    
    struct __declspec(uuid("c42ca1b2-62b4-3cc9-ac84-e2922f445e91"))
    Apptrial4com;
      // [ default ] interface _Apptrial4com
      // interface _Object
      // interface Apptrial4ComInt
    
    struct __declspec(uuid("7b906789-57a8-320e-b0ce-ba9d74d62bcf"))
    _Apptrial4com : IDispatch
    {};
    
    //
    // Wrapper method implementations
    //
    
    #include "c:\users\mmanickam\documents\visual studio 2010\projects\comconsoletrial4app\comconsoletrial4app\debug\apptrial4com.tli"
    
    } // namespace Apptrial4com
    
    #pragma pack(pop)
    
    

     

    Note: in the assembly info i have set the com visible property as true and also set the keyfilename attribute to strong name.

    the link i have referred:

    http://support.microsoft.com/kb/828736#top

    Thursday, April 21, 2011 4:04 PM

Answers

  • Hello firingnow,

     

    1. >> When i tried using regsvr32 im getting "module was loaded but entry point dllregisterserver was not found" with i tried regsvr32 for tlb file im getting "module may not be compatible with the version of winidows ur using"...

    1.1 Regsvr32 is meant for unmanaged COM servers (e.g. written in C++ via ATL).

    1.2 Your newapptrial4com.dll is written in C# and so it is a managed DLL. You must use Regasm to register this DLL.

    1.3 Also regsvr32 is not meant to be used on .TLB files.

     

    2. >> The OS im having is "windows server 2008R2" and .Net framework 4.0. based on these details can you provide me some soln??

    2.1 I'm not familiar enough with Windows Server 2008 to be sure of any restrictions. It could also be that regasm.exe failed due to you not having administrator privileges.

    2.2 If possible, test newapptrial4com.dll and ComConsoleTrial4App.exe in another OS that does not impose too much security restructions, e.g. Windows XP.

    2.3 Make sure that newapptrial4com.dll is build for 32-bit and then register it using Regasm.exe.

     

    Best of luck,

    Bio.

     

    • Marked as answer by Paul Zhou Friday, April 29, 2011 3:08 AM
    Wednesday, April 27, 2011 4:31 PM

All replies

  • Hello firingnow,

     

    1. Resolution.

    1.1 To resolve the issue, please perform the following modification :

    old code :

    namespace NewApptrial4com
    {
      public interface ApptryclassInt
      {
        void Displaymessage();
      }
      public class Apptryclass
      {
        public void Displaymessage()
        {
          MessageBox.Show("Apptryclass");
        }
      }
    }

    new code :

    namespace NewApptrial4com
    {
        public interface ApptryclassInt
        {
            void Displaymessage();
        }

        // Indicate that Apptryclass implements
        // the ApptryclassInt interface.
        public class Apptryclass : ApptryclassInt
        {
            public void Displaymessage()
            {
                MessageBox.Show("Apptryclass");
            }
        }
    }

    1.2 That is, append the Apptryclass declaration with ": ApptryclassInt". This indicates that Apptryclass implements the ApptryclassInt interface.

     

    2. Detailed Explanation.

    2.1 The exception most likely occurred (in the client code) when the Displaymessage() method was called :

    int _tmain(int argc, _TCHAR* argv[])
    {
     // Initialize COM.
      HRESULT hr = CoInitialize(NULL);
     // Create the interface pointer.
     ApptryclassIntPtr iObj(__uuidof(Apptryclass)); 
     // Error probably happened on next line.
     iObj->Displaymessage();  
     CoUninitialize();
     
     return 0;
    }

    This is because "iObj" (a _com_ptr_t smart pointer object) internally contained a NULL pointer. 

     

    2.2 It contained a NULL pointer because the ApptryclassInt interface instantiation process failed. This instantiation process occurred at the following line :

     // Create the interface pointer.
     ApptryclassIntPtr iObj(__uuidof(Apptryclass));

    The above line means :

    2.2.1 Create a COM object with a CLSID which is equal to __uuidof(Apptryclass).

    2.2.2 If 2.2.1 was successful, QueryInterface() this COM object for its ApptryclassInt interface.

    2.2.3 If 2.2.2 was successful, store the returned ApptryclassInt interface pointer inside iObj.

    In your case, point 2.2.3 failed.

     

    2.3 This is because : with the Apptryclass C# class defined as in the old code shown in point 1.1 :

    public class Apptryclass
    {
      ...
    }

    Apptryclass does not implement the ApptryclassInt interface.

     

    2.4 However, with Apptryclass defined as follows :

    public class Apptryclass : ApptryclassInt
    {
      ...
    }

    Apptryclass implements ApptryclassInt. 

    Hence when a QueryInterface() is performed on a COM object which is implemented by Apptryclass, the QueryInterface() will succeed.

     

    - Bio.

     


    Friday, April 22, 2011 6:41 AM
  • Hi Lim,

    Thanks for your reply..

    even after making the said changes in the code im still getting the same error... later i tried by removing the code inside the displaymessage() method in "apptryclass".  I got an error "_com_error at memory location 0x002efbb". On debugging, i found the exception being raised in file "comip.h" in the HRESULT CreateInstance() method. In the "autos" tabbed pane i find something as " hr 0x80070002 The system cannot find the file specified.  HRESULT". i have pasted the code of the comip.h file with the method (HRESULT CreateInstance(const CLSID& rclsid, IUnknown* pOuter = NULL, DWORD dwClsContext = CLSCTX_ALL) throw()) at line no 576(approximately).. 

    /***
    
    * comip.h - Native C++ compiler COM support - COM interface pointers header
    
    *
    
    * Copyright (c) Microsoft Corporation. All rights reserved.
    
    *
    
    ****/
    
    
    
    #if _MSC_VER > 1000
    
    #pragma once
    
    #endif
    
    
    
    #ifdef _M_CEE_PURE
    
    #error comip.h header cannot be included under /clr:safe or /clr:pure
    
    #endif
    
    
    
    #if !defined(_INC_COMIP)
    
    #define _INC_COMIP
    
    
    
    #include <ole2.h>
    
    #include <malloc.h>
    
    
    
    #include <comutil.h>
    
    
    
    #pragma warning(push)
    
    #pragma warning(disable: 4290)
    
    
    
    #pragma push_macro("new")
    
    #undef new
    
    
    
    #include <new.h>
    
    
    
    class _com_error;
    
    
    
    void __stdcall _com_issue_error(HRESULT);
    
    struct __declspec(uuid("00000000-0000-0000-c000-000000000046")) IUnknown;
    
    
    
    // Provide Interface to IID association
    
    //
    
    template<typename _Interface, const IID* _IID /*= &__uuidof(_Interface)*/> 
    
    class _com_IIID {
    
    public:
    
     typedef _Interface Interface;
    
    
    
     static _Interface* GetInterfacePtr() throw()
    
     {
    
      return NULL;
    
     }
    
    
    
     static _Interface& GetInterface() throw()
    
     {
    
      return *GetInterfacePtr();
    
     }
    
    
    
     static const IID& GetIID() throw()
    
     {
    
      return *_IID;
    
     }
    
    };
    
    
    
    template<typename _IIID> class _com_ptr_t {
    
    public:
    
     // Declare interface type so that the type may be available outside
    
     // the scope of this template.
    
     //
    
     typedef _IIID ThisIIID;
    
     typedef typename _IIID::Interface Interface;
    
    
    
     // When the compiler supports references in template parameters,
    
     // _CLSID will be changed to a reference. To avoid conversion
    
     // difficulties this function should be used to obtain the
    
     // CLSID.
    
     //
    
     static const IID& GetIID() throw()
    
     { 
    
      return ThisIIID::GetIID(); 
    
     }
    
    
    
     // Constructs a smart-pointer from any other smart pointer.
    
     //
    
     template<typename _OtherIID> _com_ptr_t(const _com_ptr_t<_OtherIID>& p) 
    
      : m_pInterface(NULL)
    
     {
    
      HRESULT hr = _QueryInterface(p);
    
    
    
      if (FAILED(hr) && (hr != E_NOINTERFACE)) {
    
       _com_issue_error(hr);
    
      }
    
     }
    
    
    
     // Constructs a smart-pointer from any IUnknown-based interface pointer.
    
     //
    
     template<typename _InterfaceType> _com_ptr_t(_InterfaceType* p) 
    
      : m_pInterface(NULL)
    
     {
    
      HRESULT hr = _QueryInterface(p);
    
    
    
      if (FAILED(hr) && (hr != E_NOINTERFACE)) {
    
       _com_issue_error(hr);
    
      }
    
     }
    
    
    
     // Make sure correct ctor is called
    
     //
    
     template<> _com_ptr_t(_In_ LPSTR str) 
    
     {
    
      new(this) _com_ptr_t(static_cast<LPCSTR> (str), NULL);
    
     }
    
    
    
     // Make sure correct ctor is called
    
     //
    
     template<> _com_ptr_t(_In_ LPWSTR str) 
    
     {
    
      new(this) _com_ptr_t(static_cast<LPCWSTR> (str), NULL);
    
     }
    
    
    
     // Disable conversion using _com_ptr_t* specialization of
    
     // template<typename _InterfaceType> _com_ptr_t(_InterfaceType* p)
    
     //
    
     template<> explicit _com_ptr_t(_com_ptr_t* p) 
    
      : m_pInterface(NULL)
    
     {
    
      if (p == NULL) {
    
       _com_issue_error(E_POINTER);
    
      }
    
      else {
    
       m_pInterface = p->m_pInterface;
    
       AddRef();
    
      }
    
     }
    
    
    
     // Default constructor.
    
     //
    
     _com_ptr_t() throw()
    
      : m_pInterface(NULL)
    
     {
    
     }
    
    
    
     // This constructor is provided to allow NULL assignment. It will issue
    
     // an error if any value other than null is assigned to the object.
    
     //
    
     _com_ptr_t(int null) 
    
      : m_pInterface(NULL)
    
     {
    
      if (null != 0) {
    
       _com_issue_error(E_POINTER);
    
      }
    
     }
    
    
    
    #if defined(_NATIVE_NULLPTR_SUPPORTED) && !defined(_DO_NOT_USE_NULLPTR_IN_COM_PTR_T)
    
    
    
     // This constructor is provided to allow nullptr assignment.
    
     _com_ptr_t(decltype(__nullptr)) : m_pInterface(NULL) { }
    
    
    
    #endif // defined(_NATIVE_NULLPTR_SUPPORTED) && !defined(_DO_NOT_USE_NULLPTR_IN_COM_PTR_T)
    
    
    
     // Copy the pointer and AddRef().
    
     //
    
     _com_ptr_t(const _com_ptr_t& cp) throw()
    
      : m_pInterface(cp.m_pInterface)
    
     { 
    
      _AddRef(); 
    
     }
    
    
    
     // Saves the interface.
    
     //
    
     template<> _com_ptr_t(Interface* pInterface) throw()
    
      : m_pInterface(pInterface)
    
     { 
    
      _AddRef(); 
    
     }
    
    
    
     // Copies the pointer. If fAddRef is TRUE, the interface will
    
     // be AddRef()ed.
    
     //
    
     _com_ptr_t(Interface* pInterface, bool fAddRef) throw()
    
      : m_pInterface(pInterface)
    
     {
    
      if (fAddRef) {
    
       _AddRef();
    
      }
    
     }
    
    
    
     // Construct a pointer for a _variant_t object.
    
     //
    
     _com_ptr_t(const _variant_t& varSrc) 
    
      : m_pInterface(NULL)
    
     {
    
      HRESULT hr = QueryStdInterfaces(varSrc);
    
    
    
      if (FAILED(hr) && (hr != E_NOINTERFACE)) {
    
       _com_issue_error(hr);
    
      }
    
     }
    
    
    
     // Calls CoCreateClass with the provided CLSID.
    
     //
    
     explicit _com_ptr_t(const CLSID& clsid, IUnknown* pOuter = NULL, DWORD dwClsContext = CLSCTX_ALL) 
    
      : m_pInterface(NULL)
    
     {
    
      HRESULT hr = CreateInstance(clsid, pOuter, dwClsContext);
    
    
    
      if (FAILED(hr) && (hr != E_NOINTERFACE)) {
    
       _com_issue_error(hr);
    
      }
    
     }
    
    
    
     // Calls CoCreateClass with the provided CLSID retrieved from
    
     // the string.
    
     //
    
     explicit _com_ptr_t(LPCWSTR str, IUnknown* pOuter = NULL, DWORD dwClsContext = CLSCTX_ALL) 
    
      : m_pInterface(NULL)
    
     {
    
      HRESULT hr = CreateInstance(str, pOuter, dwClsContext);
    
    
    
      if (FAILED(hr) && (hr != E_NOINTERFACE)) {
    
       _com_issue_error(hr);
    
      }
    
     }
    
    
    
     // Calls CoCreateClass with the provided SBCS CLSID retrieved from
    
     // the string.
    
     //
    
     explicit _com_ptr_t(LPCSTR str, IUnknown* pOuter = NULL, DWORD dwClsContext = CLSCTX_ALL) 
    
      : m_pInterface(NULL)
    
     {
    
      HRESULT hr = CreateInstance(str, pOuter, dwClsContext);
    
    
    
      if (FAILED(hr) && (hr != E_NOINTERFACE)) {
    
       _com_issue_error(hr);
    
      }
    
     }
    
    
    
     // Queries for interface.
    
     //
    
     template<typename _OtherIID> _com_ptr_t& operator=(const _com_ptr_t<_OtherIID>& p) 
    
     {
    
      HRESULT hr = _QueryInterface(p);
    
    
    
      if (FAILED(hr) && (hr != E_NOINTERFACE)) {
    
       _com_issue_error(hr);
    
      }
    
    
    
      return *this;
    
     }
    
    
    
     // Queries for interface.
    
     //
    
     template<typename _InterfaceType> _com_ptr_t& operator=(_InterfaceType* p) 
    
     {
    
      HRESULT hr = _QueryInterface(p);
    
     
    
      if (FAILED(hr) && (hr != E_NOINTERFACE)) {
    
       _com_issue_error(hr);
    
      }
    
    
    
      return *this;
    
     }
    
    
    
     // Saves the interface.
    
     //
    
     template<> _com_ptr_t& operator=(Interface* pInterface) throw()
    
     {
    
      if (m_pInterface != pInterface) {
    
       Interface* pOldInterface = m_pInterface;
    
    
    
       m_pInterface = pInterface;
    
    
    
       _AddRef();
    
    
    
       if (pOldInterface != NULL) {
    
        pOldInterface->Release();
    
       }
    
      }
    
    
    
      return *this;
    
     }
    
    
    
     // Copies and AddRef()'s the interface.
    
     //
    
     _com_ptr_t& operator=(const _com_ptr_t& cp) throw()
    
     { 
    
      return operator=(cp.m_pInterface); 
    
     }
    
    
    
     // This operator is provided to permit the assignment of NULL to the class.
    
     // It will issue an error if any value other than NULL is assigned to it.
    
     //
    
     _com_ptr_t& operator=(int null) 
    
     {
    
      if (null != 0) {
    
       _com_issue_error(E_POINTER);
    
      }
    
    
    
      return operator=(reinterpret_cast<Interface*>(NULL));
    
     }
    
    
    
     // Construct a pointer for a _variant_t object.
    
     //
    
     _com_ptr_t& operator=(const _variant_t& varSrc) 
    
     {
    
      HRESULT hr = QueryStdInterfaces(varSrc);
    
    
    
      if (FAILED(hr) && (hr != E_NOINTERFACE)) {
    
       _com_issue_error(hr);
    
      }
    
    
    
      return *this;
    
     }
    
    
    
     // If we still have an interface then Release() it. The interface
    
     // may be NULL if Detach() has previously been called, or if it was
    
     // never set.
    
     //
    
     ~_com_ptr_t() throw()
    
     { 
    
      _Release(); 
    
     }
    
    
    
     // Saves/sets the interface without AddRef()ing. This call
    
     // will release any previously acquired interface.
    
     //
    
     void Attach(Interface* pInterface) throw()
    
     {
    
      _Release();
    
      m_pInterface = pInterface;
    
     }
    
    
    
     // Saves/sets the interface only AddRef()ing if fAddRef is TRUE.
    
     // This call will release any previously acquired interface.
    
     //
    
     void Attach(Interface* pInterface, bool fAddRef) throw()
    
     {
    
      _Release();
    
      m_pInterface = pInterface;
    
    
    
      if (fAddRef) {
    
       if (pInterface == NULL) {
    
        _com_issue_error(E_POINTER);
    
       } 
    
       else {
    
        pInterface->AddRef();
    
       }
    
      }
    
     }
    
    
    
     // Simply NULL the interface pointer so that it isn't Released()'ed.
    
     //
    
     Interface* Detach() throw()
    
     {
    
      Interface* const old = m_pInterface;
    
      m_pInterface = NULL;
    
      return old;
    
     }
    
    
    
     // Return the interface. This value may be NULL.
    
     //
    
     operator Interface*() const throw()
    
     { 
    
      return m_pInterface; 
    
     }
    
    
    
     // Queries for the unknown and return it
    
     // Provides minimal level error checking before use.
    
     //
    
     operator Interface&() const 
    
     { 
    
      if (m_pInterface == NULL) {
    
       _com_issue_error(E_POINTER);
    
      }
    
    
    
      return *m_pInterface; 
    
     }
    
    
    
     // Allows an instance of this class to act as though it were the
    
     // actual interface. Also provides minimal error checking.
    
     //
    
     Interface& operator*() const 
    
     { 
    
      if (m_pInterface == NULL) {
    
       _com_issue_error(E_POINTER);
    
      }
    
    
    
      return *m_pInterface; 
    
     }
    
    
    
     // Returns the address of the interface pointer contained in this
    
     // class. This is useful when using the COM/OLE interfaces to create
    
     // this interface.
    
     //
    
     Interface** operator&() throw()
    
     {
    
      _Release();
    
      m_pInterface = NULL;
    
      return &m_pInterface;
    
     }
    
    
    
     // Allows this class to be used as the interface itself.
    
     // Also provides simple error checking.
    
     //
    
     Interface* operator->() const 
    
     { 
    
      if (m_pInterface == NULL) {
    
       _com_issue_error(E_POINTER);
    
      }
    
    
    
      return m_pInterface; 
    
     }
    
    
    
     // This operator is provided so that simple boolean expressions will
    
     // work. For example: "if (p) ...".
    
     // Returns TRUE if the pointer is not NULL.
    
     //
    
     operator bool() const throw()
    
     { 
    
      return m_pInterface != NULL; 
    
     }
    
    
    
     // Compare two smart pointers
    
     //
    
     template<typename _OtherIID> bool operator==(const _com_ptr_t<_OtherIID>& p) const
    
     {
    
      return _CompareUnknown(p) == 0;
    
     }
    
    
    
     // Compare two pointers
    
     //
    
     template<typename _InterfaceType> bool operator==(_InterfaceType* p) const
    
     {
    
      return _CompareUnknown(p) == 0;
    
     }
    
    
    
     // Compare with other interface
    
     //
    
     template<> bool operator==(Interface* p) const
    
     {
    
      return (m_pInterface == p) 
    
         ? true
    
         : _CompareUnknown(p) == 0;
    
     }
    
    
    
     // Compare two smart pointers
    
     //
    
     template<> bool operator==(const _com_ptr_t& p) const throw()
    
     {
    
      return operator==(p.m_pInterface);
    
     }
    
    
    
     // For comparison to NULL
    
     //
    
     bool operator==(int null) const
    
     {
    
      if (null != 0) {
    
       _com_issue_error(E_POINTER);
    
      }
    
    
    
      return m_pInterface == NULL;
    
     }
    
    
    
     // Compare two smart pointers
    
     //
    
     template<typename _OtherIID> bool operator!=(const _com_ptr_t<_OtherIID>& p) const
    
     {
    
      return !(operator==(p));
    
     }
    
    
    
     // Compare two pointers
    
     //
    
     template<typename _InterfaceType> bool operator!=(_InterfaceType* p) const
    
     {
    
      return !(operator==(p));
    
     }
    
    
    
     // For comparison to NULL
    
     //
    
     bool operator!=(int null) const
    
     {
    
      return !(operator==(null));
    
     }
    
    
    
     // Compare two smart pointers
    
     //
    
     template<typename _OtherIID> bool operator<(const _com_ptr_t<_OtherIID>& p) const
    
     {
    
      return _CompareUnknown(p) < 0;
    
     }
    
    
    
     // Compare two pointers
    
     //
    
     template<typename _InterfaceType> bool operator<(_InterfaceType* p) const
    
     {
    
      return _CompareUnknown(p) < 0;
    
     }
    
    
    
     // Compare two smart pointers
    
     //
    
     template<typename _OtherIID> bool operator>(const _com_ptr_t<_OtherIID>& p) const
    
     {
    
      return _CompareUnknown(p) > 0;
    
     }
    
    
    
     // Compare two pointers
    
     //
    
     template<typename _InterfaceType> bool operator>(_InterfaceType* p) const
    
     {
    
      return _CompareUnknown(p) > 0;
    
     }
    
    
    
     // Compare two smart pointers
    
     //
    
     template<typename _OtherIID> bool operator<=(const _com_ptr_t<_OtherIID>& p) const
    
     {
    
      return _CompareUnknown(p) <= 0;
    
     }
    
    
    
     // Compare two pointers
    
     //
    
     template<typename _InterfaceType> bool operator<=(_InterfaceType* p) const
    
     {
    
      return _CompareUnknown(p) <= 0;
    
     }
    
    
    
     // Compare two smart pointers
    
     //
    
     template<typename _OtherIID> bool operator>=(const _com_ptr_t<_OtherIID>& p) const
    
     {
    
      return _CompareUnknown(p) >= 0;
    
     }
    
    
    
     // Compare two pointers
    
     //
    
     template<typename _InterfaceType> bool operator>=(_InterfaceType* p) const
    
     {
    
      return _CompareUnknown(p) >= 0;
    
     }
    
    
    
     // Provides error-checking Release()ing of this interface.
    
     //
    
     void Release() 
    
     {
    
      if (m_pInterface == NULL) {
    
       _com_issue_error(E_POINTER);
    
      }
    
      else {
    
       m_pInterface->Release();
    
       m_pInterface = NULL;
    
      }
    
     }
    
    
    
     // Provides error-checking AddRef()ing of this interface.
    
     //
    
     void AddRef() 
    
     { 
    
      if (m_pInterface == NULL) {
    
       _com_issue_error(E_POINTER);
    
      }
    
      else {
    
       m_pInterface->AddRef();
    
      }
    
     }
    
    
    
     // Another way to get the interface pointer without casting.
    
     //
    
     Interface* GetInterfacePtr() const throw()
    
     { 
    
      return m_pInterface; 
    
     }
    
    
    
     // Another way to get the interface pointer without casting.
    
     // Use for [in, out] parameter passing
    
     Interface*& GetInterfacePtr() throw()
    
     { 
    
      return m_pInterface; 
    
     }
    
    
    
     // Loads an interface for the provided CLSID.
    
     // Returns an HRESULT. Any previous interface is unconditionally released.
    
     //
    
     <strong> HRESULT CreateInstance(const CLSID& rclsid, IUnknown* pOuter = NULL, DWORD dwClsContext = CLSCTX_ALL) throw()
    
    </strong> {
    
      HRESULT hr;
    
    
    
      _Release();
    
    
    
      if (dwClsContext & (CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER)) {
    
       IUnknown* pIUnknown;
    
       hr = CoCreateInstance(rclsid, pOuter, dwClsContext, __uuidof(IUnknown), reinterpret_cast<void**>(&pIUnknown));
    
    
    
       if (SUCCEEDED(hr)) {
    
        hr = OleRun(pIUnknown);
    
    
    
        if (SUCCEEDED(hr)) {
    
         hr = pIUnknown->QueryInterface(GetIID(), reinterpret_cast<void**>(&m_pInterface));
    
        }
    
    
    
        pIUnknown->Release();
    
       }
    
      }
    
      else {
    
       hr = CoCreateInstance(rclsid, pOuter, dwClsContext, GetIID(), reinterpret_cast<void**>(&m_pInterface));
    
      }
    
    
    
      if (FAILED(hr)) {
    
       // just in case refcount = 0 and dtor gets called
    
       m_pInterface = NULL;
    
      }
    
    
    
      return hr;
    
     }
    
    
    
     // Creates the class specified by clsidString. clsidString may
    
     // contain a class id, or a prog id string.
    
     //
    
     HRESULT CreateInstance(LPCWSTR clsidString, IUnknown* pOuter = NULL, DWORD dwClsContext = CLSCTX_ALL) throw()
    
     {
    
      if (clsidString == NULL) {
    
       return E_INVALIDARG;
    
      }
    
    
    
      CLSID clsid;
    
      HRESULT hr;
    
    
    
      if (clsidString[0] == L'{') {
    
       hr = CLSIDFromString(const_cast<LPWSTR> (clsidString), &clsid);
    
      }
    
      else {
    
       hr = CLSIDFromProgID(const_cast<LPWSTR> (clsidString), &clsid);
    
      }
    
    
    
      if (FAILED(hr)) {
    
       return hr;
    
      }
    
    
    
      return CreateInstance(clsid, pOuter, dwClsContext);
    
     }
    
    
    
     // Creates the class specified by SBCS clsidString. clsidString may
    
     // contain a class id, or a prog id string.
    
     //
    
     HRESULT CreateInstance(LPCSTR clsidStringA, IUnknown* pOuter = NULL, DWORD dwClsContext = CLSCTX_ALL) throw()
    
     {
    
      if (clsidStringA == NULL) {
    
       return E_INVALIDARG;
    
      }
    
    
    
      int size = lstrlenA(clsidStringA) + 1;
    
      int destSize = MultiByteToWideChar(CP_ACP, 0, clsidStringA, size, NULL, 0);
    
    
    
      if (destSize == 0) {
    
       return HRESULT_FROM_WIN32(GetLastError());
    
      }
    
    
    
      LPWSTR clsidStringW;
    
      clsidStringW = static_cast<LPWSTR>(_malloca(destSize * sizeof(WCHAR)));
    
    
    
      if (clsidStringW == NULL) {
    
       return E_OUTOFMEMORY;
    
      }
    
    
    
      if (MultiByteToWideChar(CP_ACP, 0, clsidStringA, size, clsidStringW, destSize) == 0) {
    
       _freea(clsidStringW);
    
       return HRESULT_FROM_WIN32(GetLastError());
    
      }
    
    
    
      HRESULT hr=CreateInstance(clsidStringW, pOuter, dwClsContext);
    
      _freea(clsidStringW);
    
      return hr;
    
     }
    
    
    
     // Attach to the active object specified by rclsid.
    
     // Any previous interface is released.
    
     //
    
     HRESULT GetActiveObject(const CLSID& rclsid) throw()
    
     {
    
      _Release();
    
    
    
      IUnknown* pIUnknown;
    
    
    
      HRESULT hr = ::GetActiveObject(rclsid, NULL, &pIUnknown);
    
    
    
      if (SUCCEEDED(hr)) {
    
       hr = pIUnknown->QueryInterface(GetIID(), reinterpret_cast<void**>(&m_pInterface));
    
    
    
       pIUnknown->Release();
    
      }
    
    
    
      if (FAILED(hr)) {
    
       // just in case refcount = 0 and dtor gets called
    
       m_pInterface = NULL;
    
      }
    
    
    
      return hr;
    
     }
    
    
    
     // Attach to the active object specified by clsidString.
    
     // First convert the LPCWSTR to a CLSID.
    
     //
    
     HRESULT GetActiveObject(LPCWSTR clsidString) throw()
    
     {
    
      if (clsidString == NULL) {
    
       return E_INVALIDARG;
    
      }
    
    
    
      CLSID clsid;
    
      HRESULT hr;
    
    
    
      if (clsidString[0] == '{') {
    
       hr = CLSIDFromString(const_cast<LPWSTR> (clsidString), &clsid);
    
      }
    
      else {
    
       hr = CLSIDFromProgID(const_cast<LPWSTR> (clsidString), &clsid);
    
      }
    
    
    
      if (FAILED(hr)) {
    
       return hr;
    
      }
    
    
    
      return GetActiveObject(clsid);
    
     }
    
    
    
     // Attach to the active object specified by clsidStringA.
    
     // First convert the LPCSTR to a LPCWSTR.
    
     //
    
     HRESULT GetActiveObject(LPCSTR clsidStringA) throw()
    
     {
    
      if (clsidStringA == NULL) {
    
       return E_INVALIDARG;
    
      }
    
    
    
      int size = lstrlenA(clsidStringA) + 1;
    
      int destSize = MultiByteToWideChar(CP_ACP, 0, clsidStringA, size, NULL, 0);
    
    
    
      LPWSTR clsidStringW;
    
      __try {
    
       clsidStringW = static_cast<LPWSTR>(_alloca(destSize * sizeof(WCHAR)));
    
      }
    
      __except (1) {
    
       clsidStringW = NULL;
    
      }
    
    
    
      if (clsidStringW == NULL) {
    
       return E_OUTOFMEMORY;
    
      }
    
    
    
      if (MultiByteToWideChar(CP_ACP, 0, clsidStringA, size, clsidStringW, destSize) == 0) {
    
       return HRESULT_FROM_WIN32(GetLastError());
    
      }
    
    
    
      return GetActiveObject(clsidStringW);
    
     }
    
    
    
     // Performs the QI for the specified IID and returns it in p.
    
     // As with all QIs, the interface will be AddRef'd.
    
     //
    
     template<typename _InterfaceType> HRESULT QueryInterface(const IID& iid, _InterfaceType*& p) throw ()
    
     {
    
      if (m_pInterface != NULL) {
    
       return m_pInterface->QueryInterface(iid, reinterpret_cast<void**>(&p));
    
      }
    
    
    
      return E_POINTER;
    
     }
    
    
    
     // Performs the QI for the specified IID and returns it in p.
    
     // As with all QIs, the interface will be AddRef'd.
    
     //
    
     template<typename _InterfaceType> HRESULT QueryInterface(const IID& iid, _InterfaceType** p) throw()
    
     {
    
      return QueryInterface(iid, *p);
    
     }
    
    
    
    private:
    
     // The Interface.
    
     //
    
     Interface* m_pInterface;
    
    
    
     // Releases only if the interface is not null.
    
     // The interface is not set to NULL.
    
     //
    
     void _Release() throw()
    
     {
    
      if (m_pInterface != NULL) {
    
       m_pInterface->Release();
    
      }
    
     }
    
    
    
     // AddRefs only if the interface is not NULL
    
     //
    
     void _AddRef() throw()
    
     {
    
      if (m_pInterface != NULL) {
    
       m_pInterface->AddRef();
    
      }
    
     }
    
    
    
     // Performs a QI on pUnknown for the interface type returned
    
     // for this class. The interface is stored. If pUnknown is
    
     // NULL, or the QI fails, E_NOINTERFACE is returned and
    
     // _pInterface is set to NULL.
    
     //
    
     template<typename _InterfacePtr> HRESULT _QueryInterface(_InterfacePtr p) throw()
    
     {
    
      HRESULT hr;
    
    
    
      // Can't QI NULL
    
      //
    
      if (p != NULL) {
    
       // Query for this interface
    
       //
    
       Interface* pInterface;
    
       hr = p->QueryInterface(GetIID(), reinterpret_cast<void**>(&pInterface));
    
    
    
       // Save the interface without AddRef()ing.
    
       //
    
       Attach(SUCCEEDED(hr)? pInterface: NULL);
    
      }
    
      else {
    
       operator=(static_cast<Interface*>(NULL));
    
       hr = E_NOINTERFACE;
    
      }
    
    
    
      return hr;
    
     }
    
    
    
     // Compares the provided pointer with this by obtaining IUnknown interfaces
    
     // for each pointer and then returning the difference.
    
     //
    
     template<typename _InterfacePtr> int _CompareUnknown(_InterfacePtr p) const
    
     {
    
      IUnknown* pu1, *pu2;
    
    
    
      if (m_pInterface != NULL) {
    
       HRESULT hr = m_pInterface->QueryInterface(__uuidof(IUnknown), reinterpret_cast<void**>(&pu1));
    
    
    
       if (FAILED(hr)) {
    
        pu1 = NULL;
    
        _com_issue_error(hr);
    
       }
    
       else {
    
        pu1->Release();
    
       }
    
      }
    
      else {
    
       pu1 = NULL;
    
      }
    
    
    
      if (p != NULL) {
    
       HRESULT hr = p->QueryInterface(__uuidof(IUnknown), reinterpret_cast<void**>(&pu2));
    
    
    
       if (FAILED(hr)) {
    
        pu2 = NULL;
    
        _com_issue_error(hr);
    
       }
    
       else {
    
        pu2->Release();
    
       }
    
      }
    
      else {
    
       pu2 = NULL;
    
      }
    
    
    
      return pu1 - pu2;
    
     }
    
    
    
     // Try to extract either IDispatch* or an IUnknown* from
    
     // the VARIANT
    
     //
    
     HRESULT QueryStdInterfaces(const _variant_t& varSrc) throw()
    
     {
    
      if (V_VT(&varSrc) == VT_DISPATCH) {
    
       return _QueryInterface(V_DISPATCH(&varSrc));
    
      }
    
    
    
      if (V_VT(&varSrc) == VT_UNKNOWN) {
    
       return _QueryInterface(V_UNKNOWN(&varSrc));
    
      }
    
    
    
      // We have something other than an IUnknown or an IDispatch.
    
      // Can we convert it to either one of these?
    
      // Try IDispatch first
    
      //
    
      VARIANT varDest;
    
      VariantInit(&varDest);
    
    
    
      HRESULT hr = VariantChangeType(&varDest, const_cast<VARIANT*>(static_cast<const VARIANT*>(&varSrc)), 0, VT_DISPATCH);
    
      if (SUCCEEDED(hr)) {
    
       hr = _QueryInterface(V_DISPATCH(&varDest));
    
      }
    
    
    
      if (hr == E_NOINTERFACE) {
    
       // That failed ... so try IUnknown
    
       //
    
       VariantInit(&varDest);
    
       hr = VariantChangeType(&varDest, const_cast<VARIANT*>(static_cast<const VARIANT*>(&varSrc)), 0, VT_UNKNOWN);
    
       if (SUCCEEDED(hr)) {
    
        hr = _QueryInterface(V_UNKNOWN(&varDest));
    
       }
    
      }
    
    
    
      VariantClear(&varDest);
    
      return hr;
    
     }
    
    };
    
    
    
    // Reverse comparison operators for _com_ptr_t
    
    //
    
    template<typename _InterfaceType> bool operator==(int null, const _com_ptr_t<_InterfaceType>& p) 
    
    {
    
     if (null != 0) {
    
      _com_issue_error(E_POINTER);
    
     }
    
    
    
     return p == NULL;
    
    }
    
    
    
    template<typename _Interface, typename _InterfacePtr> bool operator==(_Interface* i, const _com_ptr_t<_InterfacePtr>& p) 
    
    {
    
     return p == i;
    
    }
    
    
    
    template<typename _Interface> bool operator!=(int null, const _com_ptr_t<_Interface>& p) 
    
    {
    
     if (null != 0) {
    
      _com_issue_error(E_POINTER);
    
     }
    
    
    
     return p != NULL;
    
    }
    
    
    
    template<typename _Interface, typename _InterfacePtr> bool operator!=(_Interface* i, const _com_ptr_t<_InterfacePtr>& p) 
    
    {
    
     return p != i;
    
    }
    
    
    
    template<typename _Interface> bool operator<(int null, const _com_ptr_t<_Interface>& p) 
    
    {
    
     if (null != 0) {
    
      _com_issue_error(E_POINTER);
    
     }
    
    
    
     return p > NULL;
    
    }
    
    
    
    template<typename _Interface, typename _InterfacePtr> bool operator<(_Interface* i, const _com_ptr_t<_InterfacePtr>& p) 
    
    {
    
     return p > i;
    
    }
    
    
    
    template<typename _Interface> bool operator>(int null, const _com_ptr_t<_Interface>& p) 
    
    {
    
     if (null != 0) {
    
      _com_issue_error(E_POINTER);
    
     }
    
    
    
     return p < NULL;
    
    }
    
    
    
    template<typename _Interface, typename _InterfacePtr> bool operator>(_Interface* i, const _com_ptr_t<_InterfacePtr>& p) 
    
    {
    
     return p < i;
    
    }
    
    
    
    template<typename _Interface> bool operator<=(int null, const _com_ptr_t<_Interface>& p) 
    
    {
    
     if (null != 0) {
    
      _com_issue_error(E_POINTER);
    
     }
    
    
    
     return p >= NULL;
    
    }
    
    
    
    template<typename _Interface, typename _InterfacePtr> bool operator<=(_Interface* i, const _com_ptr_t<_InterfacePtr>& p) 
    
    {
    
     return p >= i;
    
    }
    
    
    
    template<typename _Interface> bool operator>=(int null, const _com_ptr_t<_Interface>& p) 
    
    {
    
     if (null != 0) {
    
      _com_issue_error(E_POINTER);
    
     }
    
    
    
     return p <= NULL;
    
    }
    
    
    
    template<typename _Interface, typename _InterfacePtr> bool operator>=(_Interface* i, const _com_ptr_t<_InterfacePtr>& p) 
    
    {
    
     return p <= i;
    
    }
    
    
    
    #pragma pop_macro("new")
    
    #pragma warning(pop)
    
    
    
    #endif // _INC_COMIP
    
    
    
    

    Monday, April 25, 2011 8:18 AM
  • Hello firingnow,

     

    1. The code changes that I recommended in my post dated Friday April 22nd is definitely necessary.

    1.1 Hence ensure that Apptryclass is declared as :

    public class Apptryclass : ApptryclassInt
    {
     ...
    }

     

    2. The CreateInstance() problem described in your last post is likely connected with incorrect loading of the target assembly.

    2.1 For this, take note of the following :

    2.1.1 You mentioned in your OP that you installed the NewApptrial4com class library into the GAC.

    2.1.2 In this case, after making code changes (e.g. to Apptryclass), you must re-install the latest class library into the GAC by using gacutil -i NewApptrial4com.dll

    2.1.4 It is not sufficient just to re-compile the class library.

    2.2 However, I advise that you do not install your NewApptrial4com class lib into the GAC. Please see secton 3 below.

     

    3. Further Advise.

    3.1 The following are some further advise that you may benefit from :

    3.1.1. Explicitly assign GUID values to "ApptryclassInt" and "Apptryclass", e.g. :

    namespace NewApptrial4com
    {
        [ComVisible(true)]
        [Guid("1A9ECDD2-24FC-4f9b-97BF-BF170B16CB38")]
        public interface ApptryclassInt
        {
            void Displaymessage();
        }

        [ComVisible(true)]
        [Guid("9CEFF09D-7140-451e-A85E-2341A7C978FA")]
        public class Apptryclass : ApptryclassInt
        {
            public void Displaymessage()
            {
                MessageBox.Show("Apptryclass");
            }
        }
    }

    3.1.2 This would fix the GUIDs of "ApptryclassInt" and "Apptryclass". If GUIDs are not specifically fixed using the GuidAttribute, then it is the Visual Studio IDE that assigns these values.

    3.1.3 Note that the IDE-generated GUIDs may change as you make changes to the NewApptrial4com class lib. Problems may result.

     

    3.2 Do not install the NewApptrial4com class lib into the GAC while it is still under development. Instead, register the full path to NewApptrial4com.dll in the registry so that the ComConsoleTrial4App.exe client application will always find it.

    3.2.1 For this, when you call REGASM on the NewApptrial4com class lib, use the /codebase flag :

    regasm NewApptrial4com.dll /tlb /codebase

    However, once all development have been completed, remove the /codebase flag from the call to REGASM.

     

    - Bio.

     



    Monday, April 25, 2011 4:17 PM
  • Hi Lim,

    I inherited the class from the interface, tried uninstalling the assembly and reinstalling it in GAC,  added the guid values , set the comvisible property to true but still getting the same error of  "An unhandled exception of type 'System.Runtime.InteropServices.SEHException' occurred in NewcomConsoleTrial4app.exe. Additional information: External component has thrown an exception". Im still getting error in the same place.. the cocreateinstance method. In addition, when executing the application, in the output window im getting the following messages--

    'NewcomConsoleTrial4app.exe': Loaded 'C:\Users\mmanickam\Documents\Visual Studio 2010\Projects\NewcomConsoleTrial4app\Debug\NewcomConsoleTrial4app.exe', Symbols loaded.

    'NewcomConsoleTrial4app.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file

    'NewcomConsoleTrial4app.exe': Loaded 'C:\Windows\SysWOW64\mscoree.dll', Cannot find or open the PDB file

    'NewcomConsoleTrial4app.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file

    'NewcomConsoleTrial4app.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file

    'NewcomConsoleTrial4app.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded.

    'NewcomConsoleTrial4app.exe': Loaded 'C:\Windows\SysWOW64\ole32.dll', Cannot find or open the PDB file

    'NewcomConsoleTrial4app.exe': Loaded 'C:\Windows\SysWOW64\msvcrt.dll', Cannot find or open the PDB file

    'NewcomConsoleTrial4app.exe': Loaded 'C:\Windows\SysWOW64\gdi32.dll', Cannot find or open the PDB file

    'NewcomConsoleTrial4app.exe': Loaded 'C:\Windows\SysWOW64\user32.dll', Cannot find or open the PDB file

    'NewcomConsoleTrial4app.exe': Loaded 'C:\Windows\SysWOW64\advapi32.dll', Cannot find or open the PDB file

    'NewcomConsoleTrial4app.exe': Loaded 'C:\Windows\SysWOW64\sechost.dll', Cannot find or open the PDB file

    'NewcomConsoleTrial4app.exe': Loaded 'C:\Windows\SysWOW64\rpcrt4.dll', Cannot find or open the PDB file

    'NewcomConsoleTrial4app.exe': Loaded 'C:\Windows\SysWOW64\sspicli.dll', Cannot find or open the PDB file

    'NewcomConsoleTrial4app.exe': Loaded 'C:\Windows\SysWOW64\cryptbase.dll', Cannot find or open the PDB file

    'NewcomConsoleTrial4app.exe': Loaded 'C:\Windows\SysWOW64\lpk.dll', Cannot find or open the PDB file

    'NewcomConsoleTrial4app.exe': Loaded 'C:\Windows\SysWOW64\usp10.dll', Cannot find or open the PDB file

    'NewcomConsoleTrial4app.exe': Loaded 'C:\Windows\SysWOW64\oleaut32.dll', Cannot find or open the PDB file

    'NewcomConsoleTrial4app.exe': Loaded 'C:\Windows\SysWOW64\imm32.dll', Cannot find or open the PDB file

    'NewcomConsoleTrial4app.exe': Loaded 'C:\Windows\SysWOW64\msctf.dll', Cannot find or open the PDB file

    'NewcomConsoleTrial4app.exe': Loaded 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscoreei.dll', Cannot find or open the PDB file

    'NewcomConsoleTrial4app.exe': Loaded 'C:\Windows\SysWOW64\shlwapi.dll', Cannot find or open the PDB file

    'NewcomConsoleTrial4app.exe': Loaded 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll', Cannot find or open the PDB file

    'NewcomConsoleTrial4app.exe': Loaded 'C:\Windows\SysWOW64\msvcr100_clr0400.dll', Cannot find or open the PDB file

    'NewcomConsoleTrial4app.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\mscorlib\eb4e1e70734f6efb9c7de7ec5f452c9e\mscorlib.ni.dll', Cannot find or open the PDB file

    'NewcomConsoleTrial4app.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'

    'NewcomConsoleTrial4app.exe': Loaded 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\nlssorting.dll', Cannot find or open the PDB file

    'NewcomConsoleTrial4app.exe' (Managed (v4.0.30319)): Loaded 'C:\Users\mmanickam\Documents\Visual Studio 2010\Projects\NewcomConsoleTrial4app\Debug\NewcomConsoleTrial4app.exe', Symbols loaded.

    'NewcomConsoleTrial4app.exe': Loaded 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\clrjit.dll', Cannot find or open the PDB file

    'NewcomConsoleTrial4app.exe': Loaded 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\diasymreader.dll', Cannot find or open the PDB file

    'NewcomConsoleTrial4app.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\System\7abfd34ae39103ceccdfb8b262ed6a97\System.ni.dll', Cannot find or open the PDB file

    'NewcomConsoleTrial4app.exe' (Managed (v4.0.30319)): LoadedC:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll'

     

     

    Tuesday, April 26, 2011 10:26 AM
  • Hello firingnow,

     

    1. From the execution output I see that NewcomConsoleTrial4app.exe is a 32-bit app which runs on a 64-bit machine. Hence the use of SysWOW64 DLLs.

    1.1 This is perfectly fine as long as the NewApptrial4com.dll class lib is also a 32-bit DLL.

    1.2 Please ensure this. Otherwise NewApptrial4com.dll cannot be loaded (in general, 32-bit apps/DLLs do not mix with 64-bit apps/DLLs).

     

    2. If NewApptrial4com.dll is indeed a 32-bit app, then we may have come to the end of the rope.

    2.1 No further advise from me except to say that my test DLL and client application (which I have used to emulate the problem reported in the OP) worked out correctly on my machine.

    2.2 Perhaps you could build some of the COM interop samples from Visual Studio 2010 and see whether the same problem can be re-created.

    2.3 If the problem can be re-created, then perhaps there are more fundamental problems lurking.

    2.4 If those sample programs can run properly, then perhaps you could examine their project properties and see if you could follow them closely.

     

    3. Best of luck, firingnow.

     

    - Bio.

     

    Tuesday, April 26, 2011 4:47 PM
  • Hi Lim,

    When i tried looking into the COM repository i was not able to view the newapptrial4com dll. When i tried using regsvr32 im getting "module was loaded but entry point dllregisterserver was not found" with i tried regsvr32 for tlb file im getting "module may not be compatible with the version of winidows ur using". The OS im having is "windows server 2008R2" and .Net framework 4.0. based on these details can you provide me some soln??

    Wednesday, April 27, 2011 2:59 PM
  • Hello firingnow,

     

    1. >> When i tried using regsvr32 im getting "module was loaded but entry point dllregisterserver was not found" with i tried regsvr32 for tlb file im getting "module may not be compatible with the version of winidows ur using"...

    1.1 Regsvr32 is meant for unmanaged COM servers (e.g. written in C++ via ATL).

    1.2 Your newapptrial4com.dll is written in C# and so it is a managed DLL. You must use Regasm to register this DLL.

    1.3 Also regsvr32 is not meant to be used on .TLB files.

     

    2. >> The OS im having is "windows server 2008R2" and .Net framework 4.0. based on these details can you provide me some soln??

    2.1 I'm not familiar enough with Windows Server 2008 to be sure of any restrictions. It could also be that regasm.exe failed due to you not having administrator privileges.

    2.2 If possible, test newapptrial4com.dll and ComConsoleTrial4App.exe in another OS that does not impose too much security restructions, e.g. Windows XP.

    2.3 Make sure that newapptrial4com.dll is build for 32-bit and then register it using Regasm.exe.

     

    Best of luck,

    Bio.

     

    • Marked as answer by Paul Zhou Friday, April 29, 2011 3:08 AM
    Wednesday, April 27, 2011 4:31 PM