Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > API de Windows
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 24-08-2006
harpo harpo is offline
Miembro
 
Registrado: jul 2006
Posts: 35
Poder: 0
harpo Va por buen camino
Problemas utilizando STI para adquisición de imágenes

Buenas gente

Estoy desarrollando una aplicación que, entre otras cosas, debe controlar y acceder a cámaras digitales.

A la hora de acceder al contenido de las mismas, he utilizado WIA (Windows Image Acquisition) sin ningún problema. SIn embargo, teniendo en cuenta que el driver WIA es exclusivo de Windows Xp, no funciona en Windows 98,ME,2000... para los cuales se necesita STI (Still Image).

Pues bien, a la hora de desarrollar empleando STI, me encuentro con que (para variar), está pensado con el culo y explicado peor aún.

Mi código:
Código:
procedure CreateDevice (StillImage:IStillImage);
var
  hr: HRESULT;
  dwItemsReturned:Pointer;
  pBuffer:Pointer;
  dwType:LongWord;
  dwFlags:LongWord;
  pdwEventCode:pointer;
  pDevice:pointer;    //IStiDevice
  DeviceInternalName:PWideChar;
 
begin
 
  CoInitialize(nil);
  hr := CoCreateInstance(CLSID_Sti, nil, CLSCTX_INPROC_SERVER, IID_IStillImage,stillImage);
  if Succeeded(hr) and Assigned(stillImage) then
  begin
    StillImage.Initialize(STI_VERSION,STI_DEVICE_CREATE_BOTH);
    hr:=StillImage.GetDeviceList(dwType,dwFlags,dwItemsReturned,pBuffer);
    hr:=StillImage.CreateDevice(STI_DEVICE_INFORMATION(pBuffer^).szDeviceInternalName,STI_DEVICE_CREATE_DATA,pDevice,nil);
    StillImage:=nil;
  end;
  CoUninitialize;
end;
PRIMER PROBLEMA

En teoría, el primer paso es crear una instancia de IStillImage que creo con CoCreateInstance sin problemas. La inicializo y a la hora de obtener la lista de dispositivos se me presenta el primer problema: tengo instalados una multifunción Brother MFC(...), que funciona como scanner y por tanto se controla mediante STI, y mi cámara en pruebas: una Canon Powerchot S3IS. Pues bien ... la función GetDeviceList devuelve un array de estructuras STI_DEVICE_INFORMATION que contienen la información de los dispositivos conectados. Pero, no se cómo carajo moverme por ese array y sólo puedo acceder al primer dispositivo, la Brother, que no sirve de nada. En el sti.h (en mi caso sti.pas) no encuentro el famoso array de estructuras STI_DEVICE_INFORMATION y si la declaración de dichas estructuras, y por tanto no sé cómo hacer el typecast de lo contenido en pdata para acceder al array en sí. Lo que si puedo hacer es acceder a la primera posición con STI_DEVICE_INFORMATION(pBuffer^). El STI.PAS podeis verlo AQUÍ.

SEGUNDO PROBLEMA

Para solucionar momentaneamente el primer problema he desinstalado la Brother y dejado la Canon como único dispositivo, pudiendo así acceder a él. Pero mi segundo y peor problema viene a la hora de crear el manejador del dispositivo mediante CreateDevice, al cual hay que pasarle un puntero al nombre interno del dispositvo (szDeviceInternalName) devuelto en la estructura STI_DEVICE_INFORMATION, obtenida con la función anterior (GetDeviceList).

Pues bien ... NO FUNCIONA.

Creo que estoy llamando a la función con los parámetros correctos

Código:
 StillImage.CreateDevice(STI_DEVICE_INFORMATION(pBuffer^).szDeviceInternalName,STI_DEVICE_CREATE_DATA,pDevice,nil);
A ver si podeis echarle un ojo. Muchas Gracias
Responder Con Cita
  #2  
Antiguo 24-08-2006
Avatar de seoane
[seoane] seoane is offline
Miembro Premium
 
Registrado: feb 2004
Ubicación: A Coruña, España
Posts: 3.717
Poder: 24
seoane Va por buen camino
Con lo del array creo que te puedo ayudar. El tipo STI_DEVICE_INFORMATION si que lo tienes, pues un array, no es mas que eso un array:

Código Delphi [-]
type
  STI_DEVICE_INFORMATION_ARRAY = array[0..0] of STI_DEVICE_INFORMATION;
  PSTI_DEVICE_INFORMATION_ARRAY = ^STI_DEVICE_INFORMATION_ARRAY;

Para utilizarlo, lo hacemos como cualquier otro array:
Código Delphi [-]
var
    ...
  pBuffer: PSTI_DEVICE_INFORMATION_ARRAY;
  i: integer;
begin
   ...
   hr:=StillImage.GetDeviceList(dwType,dwFlags,dwItemsReturned,pBuffer);
   for i:= 0 to dwItemsReturned - 1 do
   begin
      pBuffer^[i].szDeviceInternalName;
   end;
Responder Con Cita
  #3  
Antiguo 24-08-2006
harpo harpo is offline
Miembro
 
Registrado: jul 2006
Posts: 35
Poder: 0
harpo Va por buen camino
Muchas gracias, funciona perfectamente

Ahora el código me queda así:
Código:
procedure CreateDevice (StillImage:IStillImage);
var
  hr: HRESULT;
  dwItemsReturned:Pointer;
  pBuffer:PSTI_DEVICE_INFORMATION_ARRAY;
  DeviceInformation:STI_DEVICE_INFORMATION;
  dwType:LongWord;
  dwFlags:LongWord;
  pDevice:IStiDevice;    //IStiDevice
  DeviceName:PWideChar;
  DeviceInternalName:string;
  i:integer;
begin
  CoInitialize(nil);
  hr := CoCreateInstance(CLSID_Sti, nil, CLSCTX_INPROC_SERVER, IID_IStillImage,stillImage);
  if Succeeded(hr) and Assigned(stillImage) then
  begin
    StillImage.Initialize(STI_VERSION,STI_DEVICE_CREATE_BOTH);
    hr:=StillImage.GetDeviceList(dwType,dwFlags,dwItemsReturned,pBuffer);
    for i:=0 to 1 do
    begin
         if pBuffer^[i].DeviceType = 131072 then
            DeviceInformation:=pBuffer^[i];
    end;
    for i:=0 to STI_MAX_INTERNAL_NAME_LENGTH do
    begin
        if DeviceInformation.szDeviceInternalName[i] <> '' then
             DeviceInternalName:=DeviceInternalName+STI_DEVICE_INFORMATION(pBuffer^).szDeviceInternalName[i];
    end;
   DeviceName:=StringToWideChar(DeviceInternalName,DeviceName,Length(DeviceInternalName));
   hr:=StillImage.CreateDevice(DeviceName,STI_DEVICE_CREATE_DATA,pDevice,nil);
   StillImage:=nil;
  end;
  CoUninitialize;

end;
El problema está en la función CreateDevice, creo q probablemente en el nombre que le estoy pasando. La cabecera en el sti.pas viene así:

Código:
 function CreateDevice(pwszDeviceName: PWideChar; dwMode: DWORD; out pDevice: IStiDevice; punkOuter: IUnknown): HRESULT; stdcall;
Y en la referencia de msdn viene lo siguiente:

Cita:
IStillImage::CreateDevice

The IStillImage::CreateDevice method creates an instance of the COM object that defines the IStiDevice COM Interface, and returns a pointer to the interface.
HRESULT
CreateDevice(
LPWSTRpwszDeviceName,
DWORDdwMode,
PSTIDEVICE*pDevice,
LPUNKNOWNpunkOuter
);

Parameters

pwszDeviceNameCaller-supplied pointer to a string representing an internal device name, obtained by calling IStillImage::GetSTILaunchInformation or IStillImage::GetDeviceList.

dwMode
Caller-supplied constant value indicating the Transfer Modes in which the device is to be used. The following values are valid. Mode Description
STI_DEVICE_CREATE_BOTH The device is being opened for both obtaining status and transferring data.
STI_DEVICE_CREATE_DATA The device is being opened only for data transfers.
STI_DEVICE_CREATE_STATUS The device is being opened only for obtaining status information.

pDeviceReceives a pointer to the IStiDevice COM Interface.

punkOuterOptional, caller-supplied pointer to the "controlling unknown" for object aggregation. See the following Comments section. Return Value

If the operation succeeds, the method returns S_OK. Otherwise, it returns one of the STIERR-prefixed error codes defined in stierr.h.
Headers

Declared in sti.h. Include sti.h.
Comments

For an application to use the IStiDevice interface, it must first call IStillImage::StiCreateInstance to get a pointer to the IStillImage interface, then call IStillImage::CreateDevice to get a pointer to the IStiDevice interface. The pointer received in pDevice is used subsequently when calling IStiDevice methods, as illustrated in the sample still image code, to obtain access to the specified device.
If you want to create an aggregate COM object that includes IStiDevice, you must supply a pointer to the "controlling unknown" in punkOuter. In most cases you will not be creating an aggregate object, so punkOuter should be NULL. Object aggregation and the controlling unknown are described in the Platform SDK documentation and in the Component Object Model Specification.
See Also

IStiDevice::Release

Al hacer la llamada a esta función , pDevice apunta a nil

A ver si alguien me ilumina. Muchas gracias
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Componete DICOM para imagenes. JuanErasmo C++ Builder 4 08-05-2007 17:40:35
imágenes de fondo para una aplicación rls Varios 3 16-11-2005 22:56:24
Problemas con Streams e Imágenes Elfoscuro Gráficos 2 09-05-2005 19:42:26
problemas con mail e imagenes hugokizo PHP 2 11-10-2004 10:02:14
Manual para programar utilizando las DirectX Jan_polero OOP 0 23-05-2004 22:34:23


La franja horaria es GMT +2. Ahora son las 02:17:49.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi