Add code to communicate with the Siebel COM Server.
- In the workspace window, click the FileView tab.
- Expand the Source Files and Header Files folders.
- Double-click the
SiebelCOMDlg.h
file.
The code window opens.
- Add the following code highlighted in bold to the
SiebelCOMDlg.h
file:
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "sobjsrv.h" // Include Siebel wrapper classes
class CSiebelCOMDlgAutoProxy;
///////////////////////////////////////////////////////////
// CSiebelCOMDlg dialog
class CSiebelCOMDlg : public CDialog{
DECLARE_DYNAMIC(CSiebelCOMDlg);
friend class CSiebelCOMDlgAutoProxy;
SiebelApplication sApp; // Declare Siebel object
//Construction
public:
CSiebelCOMDlg(CWnd* pParent = NULL); //standard constructor
virtual ~CSiebelCOMDlg();
- Choose File > Open, and then select the
SiebelCOMDlg.cpp
file. Add the following code highlighted in bold to the OnInitDialog
procedure:
CDialog::OnInitDialog();
...
// TODO: Add extra initialization here
// Start the Siebel Data Server
if (!sApp.CreateDispatch(_T("SiebelDataServer.ApplicationObject)))
{
AfxMessageBox("Cannot start Siebel Data Server.");
EndDialog(-1); // Fail
} else
{
AfxMessageBox("Siebel Data Server initialized.");
}
return TRUE; // Return TRUE unless you set the focus to a control
...
- In the same file, add the following code highlighted in bold to the
OnOK
procedure. Make sure that the line beginning with sApp.LoadObjects
points to the location of the CFG file you intend to use. In the line beginning with sApp.Login
, make sure that you have entered a valid logon name and password.
void CSiebelCOMDlg::OnOK()
{
short sErr;
// Load configuration file
// Make sure that the following line points to the correct file
sApp.LoadObjects(C:\\siebel\\bin\\siebel.cfg", &sErr);
if(sErr)
{
AfxMessageBox("LoadObject failed.");
return;
} else
{
AfxMessageBox("CFG file loaded.");
}
// Log in as SADMIN
sApp.Login("SADMIN", "SADMIN", &sErr);
if(sErr)
{
AfxMessageBox("Login failed.");
return;
} else
{
AfxMessageBox("Logged into Siebel database.");
}
// Get Account business object
LPDISPATCH lpdBo;
lpdBo = sApp.GetBusObject("Account", &sErr);
if(sErr)
{
AfxMessageBox("GetBusObject failed.");
return;
} else
{
AfxMessageBox("Account business object retrieved.");
}
SiebelBusObject Bo(lpdBo);
// Get Account business component
LPDISPATCH lpdBc;
lpdBc = Bo.GetBusComp("Account", &sErr);
if(sErr)
{
AfxMessageBox("GetBusComp failed.");
return;
} else
{
AfxMessageBox("Account business component retrieved.");
}
SiebelBusComp Bc(lpdBc);
// Get the name of the fist account
if (sErr) return;
Bc.ClearToQuery(&sErr);
if (sErr) return;
Bc.SetSearchSpe("Name", "*", &sErr);
if (sErr) return;
Bc.ExecuteQuery(ForwardOnly, &sErr);
if (sErr) return;
Bc.FirstRecord(&sErr);
if (sErr) return;
// Display the account name in a message box
CString csAcctName;
csAcctName = Bc.GetFieldValue("Name", &sErr);
AfxMessageBox(csAcctName);
Bc = null;
lpdBc = null;
Bo = null;
lpdBo = null;
return;
if (CanExit())
CDialog::OnOK();
}