我的代码与COM有什么问题? [英] what's wrong in my code related to COM?

查看:111
本文介绍了我的代码与COM有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  *****BLOCK_1****

    if( strcmpi(appName.c_str(),MSSQL)==0 ||strcmpi(appName.c_str(),MSSQL2005)==0 )
{


      if (FAILED(CoCreateInstance (CLSID_SQLDMOServer, NULL, CLSCTX_INPROC_SERVER,
    IID_ISQLDMOServer, (LPVOID*)&m_pSQLServer))) {


    DMOAvailable=false;
    IDiscoverPtr pICalc;
    HRESULT hRes=CoCreateInstance(Test::CLSID_SqlClass, NULL,  CLSCTX_INPROC_SERVER,Test::IID_IDiscover, reinterpret_cast<void**> (&pICalc));

    if(FAILED(hRes))

         {
           cout << "CoCreateInstance Failed on CLSID_SQLDMOServer\n";

       return FALSE;
     }

***BLOCK_2***

if((strcmpi(appName.c_str(),MSSQL2008)==0 || strcmpi(appName.c_str(),MSSQL2005)==0 )    && DMOAvailable==false )
{

    HRESULT hr=CoInitialize(NULL);
    IDiscoverPtr pICalc(__uuidof(SqlClass));
    if(FAILED(CoCreateInstance(Test::CLSID_SqlClass, NULL, CLSCTX_INPROC_SERVER, 
        Test::IID_IDiscover, reinterpret_cast<void**> (&pICalc))))
    {
        cout<<" Loading SQLSMO failed This is because of SMO not Available "<<endl;
        return FALSE;
    }

}

*****BLOCK_3 ****

if((strcmpi(appName.c_str(),MSSQL2008)==0 && DMOAvailable==true))
{

    HRESULT hr= CoInitialize(NULL);

    cout<<"\nIn Init SqlServer DMO-true and SQL2008"<<endl;



    HRESULT hRes=CoCreateInstance(Test::CLSID_SqlClass, NULL, CLSCTX_INPROC_SERVER, 
    Test::IID_IDiscover, reinterpret_cast<void**> (&pICalc));
    if(FAILED(hRes))
    {
       printf(" Loading SQLSMO failed This is because of SMO not Available 0x%X\n",hRes)
       return FALSE;
    }
    else
        cout<<success;


}

return TRUE;
}


 I have prepared the Test.dll in c# and in that i have a an interface IDiscover and a     class SqlClass implementing that interface.I have Manually assigned the Guid like this

[System.Runtime.InteropServices.Guid("D4660088-308E-49fb-AB1A-77224F3FF851")]

public interface IDiscover
{
  string getSqlInstances(string HostName);

  string getDB(string SQLInstanceName);

  string getDatabaseInfo(string SQLInstanceName, string DBName);
};

namespace Test

  {

    [System.Runtime.InteropServices.Guid("46A951AC-C2D9-48e0-97BE-91F3C9E7B065")]

    public class SqlClass:IDiscover

  {

  }
}

我也使COMVisible = true;

I also make COMVisible=true;

并使用RegAsm.exe Test.dll / tlb注册类: Test.tlb / codebase

and register the class using RegAsm.exe Test.dll/tlb:Test.tlb /codebase

并将tlb作为#import c:... \Test.tlb named_guids

and imported the tlb in one cpp file as #import c:...\Test.tlb named_guids

这是工作正常在我的机器和我的虚拟机任何case.if我给sql2005它的工作,我给sql2008它的工作。
在某些其他机器,它显示错误代码作为0x80004002只有当进入第三块。如果它进入第一块和第二块它的工作罚款在其他机器也。在第三块发生在我不理解plzzzzzzzz帮助我在这方面...

This is working fine in my Machine And also in My virtual Machine for any case.if i gave sql2005 it works and i gave sql2008 it working. and in some other machine it shows that errror code as 0x80004002 only when entering into 3rd block.if it enters 1st block and 2nd block its working fine in other machine also.what happening in 3rd block i am not understanding plzzzzzzzz help me in this regard...

Sharptooth可以plzz通过这一个.....

Sharptooth u can plzz go through this one .....

推荐答案

使用COM时,程序集应该是Release Builds。在进一步挖掘之前,请务必这样做。

When working with COM, your assemblies should be "Release Builds". Make sure that's the case before digging around any further.

这篇关于我的代码与COM有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆