Re: Accessing binary field in a Microsoft Access database table



I need to retrieve data from a binary field in a Microsoft Access database
table. Below is a segment of my failed attempt at doing this in C++. I
hope
you can suggest a solution to my dilemma.

Thanks,
Miguel


ADODB::FieldPtr pField = rec->Fields->GetItem("SHAPE");
_variant_t vField;
vField.Clear( );
vField = pField->Value;

This can be just

_variant_t vField = rec->Fields->GetItem("SHAPE")->Value;

long *shape; // my hope is that this variable will point
to
the contents fo the field. I know the format of the data.
if (vField.vt != VT_NULL) {
shape = pField->Value; // the compiler rejects this statement:
mismatched data types.

Which it would do. Value is not a pointer.

There is absolutely no guarantee that the variant contains a long.
The variants should be used _BY VALUE_ not by pointer.
So I would do

long shape = (long)pField->Value;

as the variant will coerce if it can into the correct value.
And if you need a pointer (or better still reference), then construct a
pointer (reference) to the variant, not a long.

So

_variant_t *pvField = &(rec->Fields->GetItem("SHAPE"));
_variant_t &vField = rec->Fields->GetItem("SHAPE");

Stephen Howe


.



Relevant Pages

  • Re: COM:- passing a variant by reference...
    ... You are set a wrong values to the Variant. ... the variant pointer and set the new value like below. ... > How can I pass a variant type by reference from a VBscript to my COM ... > DISP_FUNCTION(MyScriptObject, "FunctionByReference", FunctionByReference, ...
    (microsoft.public.vc.mfc)
  • Re: How to return string through output VARIANT from C++ COM object
    ... "Kim Gräsman" wrote in message ... >> pointer to a reference to an object, ... A VT_BYREF variant does not own the resource it ...
    (microsoft.public.vc.mfc)
  • Re: How to return string through output VARIANT from C++ COM object
    ... "Kim Gräsman" wrote in message ... >> pointer to a reference to an object, ... A VT_BYREF variant does not own the resource it ...
    (microsoft.public.vc.atl)
  • Re: Question on LSP
    ... Sure, the developer must keep track of which type has been assigned to each pointer to manage complexity in creating the design, which is why the 'T' is in T*. ... Subtyping is a relation which does not ... Those object types are completely orthogonal to the semantics of being an object reference. ... aggregate references, is the aggregate of referenced objects or target ...
    (comp.object)
  • Re: Question on LSP
    ... Because construction paradigms have different goals. ... But that has nothing to do with what a pointer type ... But that does not mean that the semantics of an object reference is ... aggregate references, is the aggregate of referenced objects or target ...
    (comp.object)