?? rcoapplication.cpp
字號:
// RcOApplication.cpp: implementation of the CRcOApplication class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "RcMSSQL.h"
#include "RcOApplication.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
LPSQLDMOAPPLICATION CRcOApplication::m_pDMOApp=NULL;
CRcOApplication::CRcOApplication()
{
m_pErrorMessage=NULL;
m_pErrorMessage=new CRcErrorMessage;
m_strErrorMessage=_T("");
m_arrServersList.RemoveAll();
m_lServersAmount=0;
}
CRcOApplication::~CRcOApplication()
{
if (m_pErrorMessage != NULL)
{
delete m_pErrorMessage;
m_pErrorMessage=NULL;
}
m_strErrorMessage=_T("");
m_arrServersList.RemoveAll();
m_lServersAmount=0;
}
BOOL CRcOApplication::Initializtion()
{
HRESULT hr;
if FAILED(hr = CoInitialize (NULL))
{
m_strErrorMessage.Format ("%s", "CoInitialize 失敗!");
return FALSE;
}
if (m_pDMOApp != NULL) return TRUE;
if FAILED(hr = CoCreateInstance (CLSID_SQLDMOApplication, NULL, CLSCTX_INPROC_SERVER,
IID_ISQLDMOApplication, (LPVOID*)&m_pDMOApp))
{
m_strErrorMessage.Format ("%s", "CLSID_SQLDMOApplication: CoCreateInstance 失敗!");
return FALSE;
}
return TRUE;
}
BOOL CRcOApplication::Completion()
{
if (m_pDMOApp)
{
m_pDMOApp->Release();
m_pDMOApp=NULL;
}
CoUninitialize ();
return TRUE;
}
BOOL CRcOApplication::SetAvailableServersList()
{
// Remarks:
// Nondefault instances of SQL Server are displayed in the form of SERVERNAME/INSTANCENAME.
// The ListAvailableSQLServers method is supported only for servers and workstations
// running Microsoft Windows NT 4.0 and Microsoft Windows 2000.
assert(m_pDMOApp != NULL); /* Cannot be NULL */
m_arrServersList.RemoveAll();
m_lServersAmount=0;
BOOL bExitStatus=FALSE;
try
{
LPSQLDMONAMELIST pNameList=NULL;
if SUCCEEDED(m_pDMOApp->ListAvailableSQLServers(&pNameList))
{
LONG lCount=0; pNameList->GetCount(&lCount);
BSTR strTemplate=NULL; // BSTR: A 32-bit character pointer.
CString strServerName;
for (LONG i=0; i < lCount; i++)
{
pNameList->GetItemByOrd(i, &strTemplate);
strServerName=strTemplate;
m_arrServersList.Add(strServerName);
m_lServersAmount++;
}
bExitStatus=TRUE;
}
if (m_pDMOApp) pNameList=NULL;
}
catch(...)
{
m_pErrorMessage->FormatErrorMessage("IID_ISQLDMOApplication 異常中斷", GetLastError ());
m_strErrorMessage=m_pErrorMessage->GetErrorMessage();
}
return bExitStatus;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -