Add code to communicate with the Siebel COM Server.
- In the workspace window, click the FileView tab.
- Expand the Source Files folder and the Header Files folder.
- Double-click the SiebelCOMDlg.h file.
- In the code window, add the following code to the SiebelCOMDlg.h file. Add only the code that uses bold typeface:
#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 Open from the File menu, and then choose the SiebelCOMDlg.cpp file.
- Add the following code to the OnInitDialog procedure. Add only the code that uses bold typeface:
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 make a control active
...
- In the same file, add the following code to the OnOK procedure.
To add this code correctly, do the following:
- Make sure that the line that begins with sApp.LoadObjects references the location of the Siebel application configuration (CFG) file you intend to use.
- In the line that begins with sApp.Login, make sure you use a valid logon name and password.
- Add only the code that uses bold typeface.
void CSiebelCOMDlg::OnOK()
{
short sErr;
// Load configuration file
// Make sure that the following line references the correct file
sApp.LoadObjects(C:\Siebel\8.1\Server\BIN\ENU\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 in to Siebel database.");
}
// Get Account business object
LPDISPATCH lpdBo;
lpdBo = sApp.GetBusObject("Account", &sErr);
if(sErr)
{
AfxMessageBox("GetBusObject failed.");
return;
} else
{
AfxMessageBox("Account business object returned.");
}
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 returned.");
}
SiebelBusComp Bc(lpdBc);
// Get the name of the first 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();
}