Re: Convert int to enum

From: Bonj (benjtaylor)
Date: 12/16/04


Date: Thu, 16 Dec 2004 12:39:35 -0000

That'd be great, I wouldn't have a problem if I could use the COM support
classes - which aren't included as part of the SDK.

"Craig Kelly" <cnkelly.nospam@nospam.net> wrote in message
news:Sd4wd.1100946$Gx4.115941@bgtnsc04-news.ops.worldnet.att.net...
> "Bonj" wrote:
>
>> I've tried that, but it's msado15.h, not msado15_h.h, and it isn't the
>> same. I get a load of errors that I've got better things to do than fix,
>> I'd rather have a .vbs that modifies the midl output to be correct as it
>> doesn't seem like there's any other viable solution.
>
> As I mentioned in another post, I prefer the #import directive, but some
> playing around got the following to work. I used some of the COM support
> classes because I *hate* dealing directly with BSTR and VARIANT. I didn't
> really do all that much testing, but the following (with an appropriate
> connection string and query string) retrieved and printed the first column
> of the first row in the recordset...
>
> /*
> test.cpp, compiles with MSVC.NET...
> cl /GX test.cpp /link ole32.lib comsupp.lib
> */
>
> #include <windows.h>
> #include <initguid.h>
> #include "adoid.h"
> #include "msado15.h"
> #include <comdef.h>
> #include <comutil.h>
> #include <string>
> #include <iostream>
>
> using namespace std;
>
> struct COM_Init {
> COM_Init() { CoInitialize(NULL); }
> ~COM_Init() { CoUninitialize(); }
> } COM_Init_;
>
> static void check_hr(HRESULT hr) {
> if (FAILED(hr)) throw hr;
> }
>
> template <class T> static void safe_rel(T& t) {
> if (!t) return;
> t->Release();
> t = NULL;
> }
>
> void safe_rel_rs(ADORecordset*& rs) {
> if (!rs) return;
>
> long s = 0;
>
> if (SUCCEEDED(rs->get_State(&s)))
> if (adStateOpen == s)
> rs->Close();
>
> safe_rel(rs);
> }
>
> static string bstr2stl(const _bstr_t& b) {
> const char* c = b.operator const char *();
> return c ? c : "";
> }
>
> int main(void)
> {
> ADORecordset* rs = NULL;
> ADOFields* flds = NULL;
> ADOField* f = NULL;
>
> try {
> HRESULT hr = S_OK;
>
> hr = CoCreateInstance(CLSID_CADORecordset, NULL,
> CLSCTX_INPROC_SERVER, IID_IADORecordset, (void**)&rs);
> check_hr(hr);
>
> _variant_t connect = _bstr_t("Your_Connection_String");
> _variant_t source = _bstr_t("Your_SQL_SELECT");
> hr = rs->Open(source, connect, adOpenForwardOnly,
> adLockReadOnly, -1);
> check_hr(hr);
>
> check_hr(rs->get_Fields(&flds));
>
> _variant_t val;
> check_hr(flds->get_Item(_variant_t(0L), &f));
> check_hr(f->get_Value(&val));
> cout << bstr2stl((_bstr_t)val) << endl;
> }
> catch(HRESULT hr) { cerr << "COM Failure: " << hr << endl; }
> catch(...) { cerr << "exception" << endl; }
>
> safe_rel(f);
> safe_rel(flds);
> safe_rel_rs(rs);
>
> return 0;
> }
>
>



Relevant Pages

  • Re: Convert int to enum
    ... I wouldn't have a problem if I could use the COM support ... classes - which aren't included as part of the SDK. ... > connection string and query string) retrieved and printed the first column ...
    (microsoft.public.vc.language)
  • Re: Convert int to enum
    ... I wouldn't have a problem if I could use the COM support ... classes - which aren't included as part of the SDK. ... > connection string and query string) retrieved and printed the first column ...
    (microsoft.public.win32.programmer.ole)
  • Re: Convert int to enum
    ... I wouldn't have a problem if I could use the COM support ... classes - which aren't included as part of the SDK. ... > connection string and query string) retrieved and printed the first column ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Web Administration Tool Crashes when creating user
    ... If you are willing, I would like to learn the correct way to set up the membership, profile, and all other providers using the equivalent to the default settings that come with "LocalSqlServer". ... It will check if the Role Manager has been enabled. ... It is reusing the default connection string name: ... Microsoft Online Community Support ...
    (microsoft.public.vsnet.setup)
  • Re: XP Taskbar problem
    ... At the time I posted I had two samples - Chad's tutorial and the April SDK ... and now my project runs at full screen without any flicker. ... support starting in full screen correctly mouse support in multimonitor ... Check startup code and see if window client has dimensions of your screen ...
    (microsoft.public.win32.programmer.directx.managed)

Loading