comp.lang.ada
 help / color / mirror / Atom feed
* WIA
@ 2006-01-03 10:50 david
  2006-01-03 11:36 ` WIA Stephen Leake
  2006-01-03 14:04 ` WIA Frank J. Lhota
  0 siblings, 2 replies; 5+ messages in thread
From: david @ 2006-01-03 10:50 UTC (permalink / raw)


Hello,

I'm trying to use wia in an ADA software.

I have found little code samples to write com objects and this seems to
work well.

My problem is to use  (Wia_Property_Storage_Interface.Lpvtbl.)
Writemultiple : i'm not sure about interfacing the two types propspec
and propvariant and the writemultiple call.
In C, writemultiple is :

HRESULT WriteMultiple(
  ULONG cpspec,
  const PROPSPEC rgpspec[],
  const PROPVARIANT rgpropvar[],
  PROPID propidNameFirst
);

I'm not sure about the ada corresponding specifications for the "const
type var[]".
I wrote :

   type Propspec (Kind : Win32.Ulong) is
      record
         case Kind is
            when Prspec_Propid =>
               Propid : Win32.Oleauto.Propid;
            when Prspec_Lpwstr =>
               Lpwstr : Win32.Objbase.Lpolestr;
            when others =>
               null;
         end case;
      end record;
   pragma Convention (C, Propspec);
   type Ppropspec is access all Propspec;
   function To_Ppropspec is new Ada.Unchecked_Conversion
(System.Address, Ppropspec);

   type Tab_Propspec_Propid is array (Positive range <>) of Propspec
(Prspec_Propid);

      type Propvariant (Vt : Win32.Oleauto.Varenum) is
      record
         Wreserved1 : Win32.Word;
         Wreserved2 : Win32.Word;
         Wreserved3 : Win32.Word;
         case Vt is
            when Win32.Oleauto.Vt_I4 =>
               Ival : Win32.Long;
            when Win32.Oleauto.Vt_Bstr =>
               Bstrval : Win32.Oleauto.Bstr;
            when others =>
               null;
         end case;
      end record;
   pragma Convention (C, Propvariant);
   type Ppropvariant is access all Propvariant;
   function To_Ppropvar is new Ada.Unchecked_Conversion
(System.Address, Ppropvariant);

   type Tab_Propvariant_Vt_I4 is array (Positive range <>) of
Propvariant (Win32.Oleauto.Vt_I4);

   type Af_I_Wia_Property_Storage_Writemultiple is access
     function (This      : access I_Wia_Property_Storage;
               Cpspec    : Win32.Ulong; -- in
               Rgpspec   : Ppropspec;-- in const propspec []
               Rgpropvar : Ppropvariant;-- in const propvariant []
               Propidnamefirst : Win32.Oleauto.Propid) -- in essayer
avec 2
       return Win32.Objbase.HRESULT;
   pragma Convention (Stdcall,
Af_I_Wia_Property_Storage_Writemultiple);

When calling this method, I write :

Propspec_Flash_Mode   : Tab_Propspec_Propid (1 .. 1) := (1 => (Kind =>
Prspec_Propid,

Propid => Win32.Oleauto.Propid (Wia_Dpc_Flash_Mode)));
Propvar_Flash_Fill   : Tab_Propvariant_Vt_I4 (1 .. 1) := (1 =>
(Win32.Oleauto.Vt_I4,

Win32.Word (0),

Win32.Word (0),

Win32.Word (0),

Win32.Long (Wia_Flash_Mode_Fill)));


My_Hresult := Wia_Property_Storage_Interface.Lpvtbl.Writemultiple
(Wia_Property_Storage_Interface,

    1,

    To_Ppropspec (Propspec_Flash_Mode (1)'Address),

    To_Ppropvar (Propvar_Flash_Fill (1)'Address),

    2);

I tried to work without tab_prospec_propid and tab_propvariant_vt_i4
but this doesn't work.
When executing, my_hresult is s_false.

I tried to use gnatcom to verify my interfacing but createcom seems to
not work on wiaservc.dll (whereas it works on wiaaut.dll for example.

So, I have 2 questions :

Is someone see a mistake on my interface code ?
Does someone know why gnatcom doesn't work on wiaservc.dll ?

thank you very much and.....

best wishes for 2006

David




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: WIA
  2006-01-03 10:50 WIA david
@ 2006-01-03 11:36 ` Stephen Leake
  2006-01-03 12:54   ` WIA david
  2006-01-03 14:04 ` WIA Frank J. Lhota
  1 sibling, 1 reply; 5+ messages in thread
From: Stephen Leake @ 2006-01-03 11:36 UTC (permalink / raw)


"david" <bsvj2421y19cbiun@jetable.org> writes:

> I'm trying to use wia in an ADA software.

"Ada" is a woman's name, so it is not all caps.

> My problem is to use  (Wia_Property_Storage_Interface.Lpvtbl.)
> Writemultiple : i'm not sure about interfacing the two types propspec
> and propvariant and the writemultiple call.
> In C, writemultiple is :
>
> HRESULT WriteMultiple(
>   ULONG cpspec,
>   const PROPSPEC rgpspec[],
>   const PROPVARIANT rgpropvar[],
>   PROPID propidNameFirst
> );

I found this at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/stg/stg/ipropertystorage_writemultiple.asp

> I'm not sure about the ada corresponding specifications for the "const
> type var[]".
> I wrote :
>
>    type Propspec (Kind : Win32.Ulong) is
>       record
>          case Kind is
>             when Prspec_Propid =>
>                Propid : Win32.Oleauto.Propid;
>             when Prspec_Lpwstr =>
>                Lpwstr : Win32.Objbase.Lpolestr;
>             when others =>
>                null;
>          end case;
>       end record;
>    pragma Convention (C, Propspec);
>    type Ppropspec is access all Propspec;
>    function To_Ppropspec is new Ada.Unchecked_Conversion
> (System.Address, Ppropspec);

This looks good; it matches http://msdn.microsoft.com/library/default.asp?url=/library/en-us/stg/stg/propspec.asp

>    type Tab_Propspec_Propid is array (Positive range <>) of Propspec
> (Prspec_Propid);

This doesn't match any C type; an Ada unconstrained array has the
array bounds in the first few bytes.

>    type Propvariant (Vt : Win32.Oleauto.Varenum) is
>       record
>          Wreserved1 : Win32.Word;
>          Wreserved2 : Win32.Word;
>          Wreserved3 : Win32.Word;
>          case Vt is
>             when Win32.Oleauto.Vt_I4 =>
>                Ival : Win32.Long;
>             when Win32.Oleauto.Vt_Bstr =>
>                Bstrval : Win32.Oleauto.Bstr;
>             when others =>
>                null;
>          end case;
>       end record;
>    pragma Convention (C, Propvariant);
>    type Ppropvariant is access all Propvariant;
>    function To_Ppropvar is new Ada.Unchecked_Conversion
> (System.Address, Ppropvariant);

I'll assume this is right.

>    type Tab_Propvariant_Vt_I4 is array (Positive range <>) of
> Propvariant (Win32.Oleauto.Vt_I4);
>
>    type Af_I_Wia_Property_Storage_Writemultiple is access
>      function (This      : access I_Wia_Property_Storage;
>                Cpspec    : Win32.Ulong; -- in
>                Rgpspec   : Ppropspec;-- in const propspec []
>                Rgpropvar : Ppropvariant;-- in const propvariant []
>                Propidnamefirst : Win32.Oleauto.Propid) -- in essayer
> avec 2
>        return Win32.Objbase.HRESULT;
>    pragma Convention (Stdcall,
> Af_I_Wia_Property_Storage_Writemultiple);
>
> When calling this method, I write :
>
> Propspec_Flash_Mode   : Tab_Propspec_Propid (1 .. 1) := (1 => (Kind =>
> Prspec_Propid,
>
> Propid => Win32.Oleauto.Propid (Wia_Dpc_Flash_Mode)));
> Propvar_Flash_Fill   : Tab_Propvariant_Vt_I4 (1 .. 1) := (1 =>
> (Win32.Oleauto.Vt_I4,
>
> Win32.Word (0),
>
> Win32.Word (0),
>
> Win32.Word (0),
>
> Win32.Long (Wia_Flash_Mode_Fill)));
>
>
> My_Hresult := Wia_Property_Storage_Interface.Lpvtbl.Writemultiple
> (Wia_Property_Storage_Interface,
>
>     1,
>
>     To_Ppropspec (Propspec_Flash_Mode (1)'Address),
>
>     To_Ppropvar (Propvar_Flash_Fill (1)'Address),
>
>     2);

Actually, this looks good. 

Although I would just declare the arguments to Writemultiple as
System.Address, and avoid the calls to Unchecked_Conversion. That
makes it clearer that you do _not_ have strong typing here.

> I tried to work without tab_prospec_propid and tab_propvariant_vt_i4
> but this doesn't work.
> When executing, my_hresult is s_false.

The hardest part about using Win32 is finding the bugs in the manual.
I suspect you are using the data structures in a way that the function
can't handle.

If you can find a working example of this in C or C++, and translate
that as closely as possible into Ada, you might get somewhere.

> I tried to use gnatcom to verify my interfacing but createcom seems to
> not work on wiaservc.dll (whereas it works on wiaaut.dll for example.

You should ask about that on the gnavi mailing list; see
http://sourceforge.net/projects/gnavi/ 

-- 
-- Stephe



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: WIA
  2006-01-03 11:36 ` WIA Stephen Leake
@ 2006-01-03 12:54   ` david
  0 siblings, 0 replies; 5+ messages in thread
From: david @ 2006-01-03 12:54 UTC (permalink / raw)


thank you for your reply.

I try immediately your link on sourceforge....

In C sample, writemultiple is called with arrays' first elements
address (for propspec and propvar), so i will try your advise : work
directly on address too.

best regards
David




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: WIA
  2006-01-03 10:50 WIA david
  2006-01-03 11:36 ` WIA Stephen Leake
@ 2006-01-03 14:04 ` Frank J. Lhota
  2006-01-03 14:22   ` WIA david
  1 sibling, 1 reply; 5+ messages in thread
From: Frank J. Lhota @ 2006-01-03 14:04 UTC (permalink / raw)


david wrote:
> Hello,
> 
> I'm trying to use wia in an ADA software.
> 
> I have found little code samples to write com objects and this seems to
> work well.
> 
> My problem is to use  (Wia_Property_Storage_Interface.Lpvtbl.)
> Writemultiple : i'm not sure about interfacing the two types propspec
> and propvariant and the writemultiple call.
> In C, writemultiple is :
> 
> HRESULT WriteMultiple(
>   ULONG cpspec,
>   const PROPSPEC rgpspec[],
>   const PROPVARIANT rgpropvar[],
>   PROPID propidNameFirst
> );

Well, not quite. WriteMultiple is really a method for objects of type 
IPropertyStorage. If you're working in C++, then this is implemented as 
a C++ method. If you're working in C, then the first parameter is a 
pointer to the object, e.g.

  HRESULT __stdcall WriteMultiple(
    IPropertyStorage* This,
    ULONG cpspec,
    const PROPSPEC rgpspec[],
    const PROPVARIANT rgpropvar[],
    PROPID propidNameFirst
  );

Every call to IPropertyStorage::WriteMultiple needs to include the a 
pointer / reference to the object.


> I'm not sure about the ada corresponding specifications for the "const
> type var[]".
> I wrote :
> 
>    type Propspec (Kind : Win32.Ulong) is
>       record
>          case Kind is
>             when Prspec_Propid =>
>                Propid : Win32.Oleauto.Propid;
>             when Prspec_Lpwstr =>
>                Lpwstr : Win32.Objbase.Lpolestr;
>             when others =>
>                null;
>          end case;
>       end record;
>    pragma Convention (C, Propspec);
>    type Ppropspec is access all Propspec;
>    function To_Ppropspec is new Ada.Unchecked_Conversion
> (System.Address, Ppropspec);
> 
>    type Tab_Propspec_Propid is array (Positive range <>) of Propspec
> (Prspec_Propid);
> 
>       type Propvariant (Vt : Win32.Oleauto.Varenum) is
>       record
>          Wreserved1 : Win32.Word;
>          Wreserved2 : Win32.Word;
>          Wreserved3 : Win32.Word;
>          case Vt is
>             when Win32.Oleauto.Vt_I4 =>
>                Ival : Win32.Long;
>             when Win32.Oleauto.Vt_Bstr =>
>                Bstrval : Win32.Oleauto.Bstr;
>             when others =>
>                null;
>          end case;
>       end record;
>    pragma Convention (C, Propvariant);
>    type Ppropvariant is access all Propvariant;
>    function To_Ppropvar is new Ada.Unchecked_Conversion
> (System.Address, Ppropvariant);
> 
>    type Tab_Propvariant_Vt_I4 is array (Positive range <>) of
> Propvariant (Win32.Oleauto.Vt_I4);
> 
>    type Af_I_Wia_Property_Storage_Writemultiple is access
>      function (This      : access I_Wia_Property_Storage;
>                Cpspec    : Win32.Ulong; -- in
>                Rgpspec   : Ppropspec;-- in const propspec []
>                Rgpropvar : Ppropvariant;-- in const propvariant []
>                Propidnamefirst : Win32.Oleauto.Propid) -- in essayer
> avec 2
>        return Win32.Objbase.HRESULT;
>    pragma Convention (Stdcall,
> Af_I_Wia_Property_Storage_Writemultiple);
> 
> When calling this method, I write :
> 
> Propspec_Flash_Mode   : Tab_Propspec_Propid (1 .. 1) := (1 => (Kind =>
> Prspec_Propid,
> 
> Propid => Win32.Oleauto.Propid (Wia_Dpc_Flash_Mode)));
> Propvar_Flash_Fill   : Tab_Propvariant_Vt_I4 (1 .. 1) := (1 =>
> (Win32.Oleauto.Vt_I4,
> 
> Win32.Word (0),
> 
> Win32.Word (0),
> 
> Win32.Word (0),
> 
> Win32.Long (Wia_Flash_Mode_Fill)));
> 
> 
> My_Hresult := Wia_Property_Storage_Interface.Lpvtbl.Writemultiple
> (Wia_Property_Storage_Interface,
> 
>     1,
> 
>     To_Ppropspec (Propspec_Flash_Mode (1)'Address),
> 
>     To_Ppropvar (Propvar_Flash_Fill (1)'Address),
> 
>     2);
> 
> I tried to work without tab_prospec_propid and tab_propvariant_vt_i4
> but this doesn't work.
> When executing, my_hresult is s_false.
> 
> I tried to use gnatcom to verify my interfacing but createcom seems to
> not work on wiaservc.dll (whereas it works on wiaaut.dll for example.
> 
> So, I have 2 questions :
> 
> Is someone see a mistake on my interface code ?
> Does someone know why gnatcom doesn't work on wiaservc.dll ?
> 
> thank you very much and.....
> 
> best wishes for 2006
> 
> David
> 


-- 
"All things extant in this world,
Gods of Heaven, gods of Earth,
Let everything be as it should be;
Thus shall it be!"
- Magical chant from "Magical Shopping Arcade Abenobashi"

"Drizzle, Drazzle, Drozzle, Drome,
Time for the this one to come home!"
- Mr. Lizard from "Tutor Turtle"



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: WIA
  2006-01-03 14:04 ` WIA Frank J. Lhota
@ 2006-01-03 14:22   ` david
  0 siblings, 0 replies; 5+ messages in thread
From: david @ 2006-01-03 14:22 UTC (permalink / raw)


Hello,
you are right, but a wrote my first post a little too fast.
I use the C implementation, and I call writemultiple with "this"
parameter.

Looking for infos in msdn for the 100 (almost :o) ) time, i have just
seen that if writemultiple return s_false, it means that the arguments
are correct but it can't execute the command. So, perhaps have I rigths
problem to modify my camera properties ...
I continue my quest...

It's a bit difficult to understand well all what to do to use correctly
wia.

thanks a lot
David




Frank J. Lhota a écrit :

> david wrote:
> > Hello,
> >
> > I'm trying to use wia in an ADA software.
> >
> > I have found little code samples to write com objects and this seems to
> > work well.
> >
> > My problem is to use  (Wia_Property_Storage_Interface.Lpvtbl.)
> > Writemultiple : i'm not sure about interfacing the two types propspec
> > and propvariant and the writemultiple call.
> > In C, writemultiple is :
> >
> > HRESULT WriteMultiple(
> >   ULONG cpspec,
> >   const PROPSPEC rgpspec[],
> >   const PROPVARIANT rgpropvar[],
> >   PROPID propidNameFirst
> > );
>
> Well, not quite. WriteMultiple is really a method for objects of type
> IPropertyStorage. If you're working in C++, then this is implemented as
> a C++ method. If you're working in C, then the first parameter is a
> pointer to the object, e.g.
>
>   HRESULT __stdcall WriteMultiple(
>     IPropertyStorage* This,
>     ULONG cpspec,
>     const PROPSPEC rgpspec[],
>     const PROPVARIANT rgpropvar[],
>     PROPID propidNameFirst
>   );
>
> Every call to IPropertyStorage::WriteMultiple needs to include the a
> pointer / reference to the object.
>
>
> > I'm not sure about the ada corresponding specifications for the "const
> > type var[]".
> > I wrote :
> >
> >    type Propspec (Kind : Win32.Ulong) is
> >       record
> >          case Kind is
> >             when Prspec_Propid =>
> >                Propid : Win32.Oleauto.Propid;
> >             when Prspec_Lpwstr =>
> >                Lpwstr : Win32.Objbase.Lpolestr;
> >             when others =>
> >                null;
> >          end case;
> >       end record;
> >    pragma Convention (C, Propspec);
> >    type Ppropspec is access all Propspec;
> >    function To_Ppropspec is new Ada.Unchecked_Conversion
> > (System.Address, Ppropspec);
> >
> >    type Tab_Propspec_Propid is array (Positive range <>) of Propspec
> > (Prspec_Propid);
> >
> >       type Propvariant (Vt : Win32.Oleauto.Varenum) is
> >       record
> >          Wreserved1 : Win32.Word;
> >          Wreserved2 : Win32.Word;
> >          Wreserved3 : Win32.Word;
> >          case Vt is
> >             when Win32.Oleauto.Vt_I4 =>
> >                Ival : Win32.Long;
> >             when Win32.Oleauto.Vt_Bstr =>
> >                Bstrval : Win32.Oleauto.Bstr;
> >             when others =>
> >                null;
> >          end case;
> >       end record;
> >    pragma Convention (C, Propvariant);
> >    type Ppropvariant is access all Propvariant;
> >    function To_Ppropvar is new Ada.Unchecked_Conversion
> > (System.Address, Ppropvariant);
> >
> >    type Tab_Propvariant_Vt_I4 is array (Positive range <>) of
> > Propvariant (Win32.Oleauto.Vt_I4);
> >
> >    type Af_I_Wia_Property_Storage_Writemultiple is access
> >      function (This      : access I_Wia_Property_Storage;
> >                Cpspec    : Win32.Ulong; -- in
> >                Rgpspec   : Ppropspec;-- in const propspec []
> >                Rgpropvar : Ppropvariant;-- in const propvariant []
> >                Propidnamefirst : Win32.Oleauto.Propid) -- in essayer
> > avec 2
> >        return Win32.Objbase.HRESULT;
> >    pragma Convention (Stdcall,
> > Af_I_Wia_Property_Storage_Writemultiple);
> >
> > When calling this method, I write :
> >
> > Propspec_Flash_Mode   : Tab_Propspec_Propid (1 .. 1) := (1 => (Kind =>
> > Prspec_Propid,
> >
> > Propid => Win32.Oleauto.Propid (Wia_Dpc_Flash_Mode)));
> > Propvar_Flash_Fill   : Tab_Propvariant_Vt_I4 (1 .. 1) := (1 =>
> > (Win32.Oleauto.Vt_I4,
> >
> > Win32.Word (0),
> >
> > Win32.Word (0),
> >
> > Win32.Word (0),
> >
> > Win32.Long (Wia_Flash_Mode_Fill)));
> >
> >
> > My_Hresult := Wia_Property_Storage_Interface.Lpvtbl.Writemultiple
> > (Wia_Property_Storage_Interface,
> >
> >     1,
> >
> >     To_Ppropspec (Propspec_Flash_Mode (1)'Address),
> >
> >     To_Ppropvar (Propvar_Flash_Fill (1)'Address),
> >
> >     2);
> >
> > I tried to work without tab_prospec_propid and tab_propvariant_vt_i4
> > but this doesn't work.
> > When executing, my_hresult is s_false.
> >
> > I tried to use gnatcom to verify my interfacing but createcom seems to
> > not work on wiaservc.dll (whereas it works on wiaaut.dll for example.
> >
> > So, I have 2 questions :
> >
> > Is someone see a mistake on my interface code ?
> > Does someone know why gnatcom doesn't work on wiaservc.dll ?
> >
> > thank you very much and.....
> >
> > best wishes for 2006
> >
> > David
> >
>
>
> --
> "All things extant in this world,
> Gods of Heaven, gods of Earth,
> Let everything be as it should be;
> Thus shall it be!"
> - Magical chant from "Magical Shopping Arcade Abenobashi"
>
> "Drizzle, Drazzle, Drozzle, Drome,
> Time for the this one to come home!"
> - Mr. Lizard from "Tutor Turtle"




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-01-03 14:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-01-03 10:50 WIA david
2006-01-03 11:36 ` WIA Stephen Leake
2006-01-03 12:54   ` WIA david
2006-01-03 14:04 ` WIA Frank J. Lhota
2006-01-03 14:22   ` WIA david

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox