ICP  1
api.cpp
Go to the documentation of this file.
1 // api.cpp : Implementation of Capi
2 
3 #include "stdafx.h"
4 #include "api.h"
5 #include "session.h"
6 
7 #include "instapi_utils.h"
8 
9 
10 
11 // Capi
12 
13 STDMETHODIMP Capi::InterfaceSupportsErrorInfo(REFIID riid)
14 {
15  static const IID* const arr[] =
16  {
17  &IID_Iapi
18  };
19 
20  for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
21  {
22  if (InlineIsEqualGUID(*arr[i],riid))
23  return S_OK;
24  }
25  return S_FALSE;
26 }
27 
28 
29 STDMETHODIMP Capi::create(BSTR instrument, BSTR user_name, BSTR password, Isession** session)
30 {
31  std::string errmsg;
32  try
33  {
34  InstAPILib* the_api = inst_api.get();
35  // initialise session
36  ULONG session_id = 0;
37  the_api->createSession(instrument, user_name, password, &session_id);
38  // create session object for result
39  CComPtr<Csession::Isession> the_session;
40  the_session.CoCreateInstance(CLSID_session, 0, CLSCTX_ALL);
41  the_session->put_session_id(session_id);
42  *session = the_session.Detach();
43  }
44  catch(const std::exception& ex)
45  {
46  errmsg = ex.what();
47  }
48  return reportError(this, errmsg);
49 }
void createSession(BSTR instrument, BSTR user_name, BSTR password, ULONG *session_id)
Definition: instapi_lib.cpp:21
Poco::SingletonHolder< InstAPILib > inst_api
HRESULT create(BSTR instrument, BSTR user_name, BSTR password, Isession **session)
Definition: api.cpp:29
HRESULT InterfaceSupportsErrorInfo(REFIID riid)
Definition: api.cpp:13
HRESULT reportError(T *obj, const std::string &errmsg)
Definition: instapi_utils.h:9