引用 sqldmo.h和sqldmoid.h 两个文件后
我要建立一个对象,比如说:     LPSQLDMOAPPLICATION m_application;     然后,我要调用 CoCreateInstence 函数,我应该如何调用?用什么参数?

解决方案 »

  1.   

    see an example here:http://groups.google.com/groups?selm=%232CTfBopBHA.2172%40tkmsftngp03&oe=UTF-8&output=gplainLPSQLDMOSERVER pSQLServer = NULL;
     if FAILED(hr = CoCreateInstance(CLSID_SQLDMOServer, NULL,
    CLSCTX_INPROC_SERVER,
      IID_ISQLDMOServer, (LPVOID*)&pSQLServer))
     {
      _tprintf(TEXT("CoCreateInstance Failed\n"));
      return (0);
     } pSQLServer->SetLoginTimeout(10);
     if FAILED(hr =
    pSQLServer->Connect(TEXT("it-peterlin"),TEXT("sa"),TEXT("sa")))
     {
      _tprintf(TEXT("Connect failed\n"));
      LPSUPPORTERRORINFO pSEI = NULL;
      if SUCCEEDED(pSQLServer->QueryInterface(IID_ISupportErrorInfo,
    (LPVOID*)&pSEI))
      {
       if SUCCEEDED(pSEI->InterfaceSupportsErrorInfo(IID_ISQLDMOServer))
       {
        LPERRORINFO pEI = NULL;
        GetErrorInfo (0, &pEI);
        SQLDMO_BSTR strDescription, strSource;
        pEI->GetDescription (&strDescription);
        pEI->GetSource (&strSource);
        _tprintf(TEXT("%s returned error %d: %s\n"),
         strSource,
         SCODE_CODE(hr),
         strDescription);
        pEI->Release ();
       }
      }
      else
      {
       _tprintf(TEXT("Error %d\n"), HRESULT_CODE(hr));
      }
     pSEI->Release ();
     }
     else
     {
      SQLDMO_BSTR str;
      SQLDMO_BSTR myStr;
      LONG lServerCount = 0;
      pSQLServer->GetVersionString(&str);
      _tprintf(TEXT("%s\n"),str);
      LPSQLDMOAPPLICATION pApp = NULL;
      pSQLServer->GetApplication(&pApp);
      pApp->GetName(&str);
    ................
      

  2.   

    可是为什么我在build 此代码的时候,link时老出错?
      

  3.   

    show the error messagesor find where the sql*.lib files are, add the directory to your IDE's Tools->Options->Directories->Library Files, add the sql*.lib files to your link library list
      

  4.   

    make sure you have this line
    #include <initguid.h>
    #include <sqldmoid.h>
    #include <sqldmo.h>
    or 
    if you get
    error LNK2001: unresolved external symbol _CLSID_SQLDMOServer
    error LNK2001: unresolved external symbol _IID_IWSQLDMOServer Keep the "sqldmo.h" in your stdafx.h file.Add a new file to your project  (usually called guidseg.cpp)
    Add to it #include <initguid.h> and #include <sqlmoid.h>
    Change the settings on that file (JUST that file) to not use precompiled headersgood luck!
      

  5.   

    非常感谢 saucer(思归)我说的错误正是 您上面提到的错误! error LNK2001: unresolved external symbol _CLSID_SQLDMOServer
    error LNK2001: unresolved external symbol _IID_IWSQLDMOServer 估计是头文件 'sqldmo.h' 没有在stdafx.h中被引用,我马上进行测试!另外,顺便问一下,在VC++环境中,控制sqlserver,除了SQL-DM0之外,还有其他的途径吗!我觉得SQL-DMO仍然不是很灵活,(可能功能上还比较可以);    saucer(思归) 兄 
    我接触VC++的时间不是很长,可以说是什么都不懂,我希望我今后能多多向您学习,您不会介意我给你写信吧!我非常希望今后我能多多和您联系,可以吗?我的  EMAIL: [email protected]
           QQ   : 30115970