Wrap to COM. 
Author Message
 Wrap to COM.

I have sample code below:
  // Load the DLL and initialise it.
 m_DllInst = LoadLibrary("ccddll.dll");
 BOOL status = MAT_Initialise(&m_CcdDevice,  m_DllInst);
 assert(status != FALSE);

Can I wrap it to COM (load 'ccddll.dll' into my ATL server and open some
interfaces for VB to access?

Thanks..

CcdInterface.h:
/*==========================================================================
=
 *
 * File: $Workfile: CcdInterface.h $
 *
 *
 * Description:
 *
 * This file contains the definitions for the interface classes that lie
between the
 * application program and the hardware interface library.
 *
 *

****************************************************************************
 ....
/*
 * Declare a handle type for the attached CCD device. In this case the
handle becomes a
 * compound type containing the DLL instance and the handle of the CCD
device. A sub-type
 * is defined for the CCD device handle that is passed to the DLL functions.
 */
typedef void *MAT_BARE_HANDLE_T;
typedef struct
{
 MAT_BARE_HANDLE_T the_handle;
 HINSTANCE   dll_instance;

Quote:
} MAT_HANDLE_T;

/*
 * Typedef function pointers for all of the interface functions
 */
typedef BOOL    (__stdcall MAT_InitialiseFnT)   (void);
typedef BOOL    (__stdcall MAT_ConnectFnT)    (MAT_BARE_HANDLE_T *,
MAT_TYPE_E);
typedef BOOL    (__stdcall MAT_DisconnectFnT)   (MAT_BARE_HANDLE_T);
typedef int     (__stdcall MAT_GetXSizeFnT)    (MAT_BARE_HANDLE_T);
typedef int     (__stdcall MAT_GetYSizeFnT)    (MAT_BARE_HANDLE_T);
typedef MAT_IMAGE_DATA_T * (__stdcall MAT_GetImageFnT)
(MAT_BARE_HANDLE_T);
typedef BOOL    (__stdcall MAT_GetStatusFnT)   (MAT_BARE_HANDLE_T,
MAT_STATUS_T *);
typedef BOOL    (__stdcall MAT_ArmFnT)     (MAT_BARE_HANDLE_T);
typedef BOOL    (__stdcall MAT_IsArmedFnT)    (MAT_BARE_HANDLE_T);
typedef BOOL    (__stdcall MAT_EnableBinningFnT)  (MAT_BARE_HANDLE_T, BOOL);
typedef BOOL    (__stdcall MAT_EnableManualTriggerFnT) (MAT_BARE_HANDLE_T,
BOOL);
typedef BOOL    (__stdcall MAT_ForceTriggerFnT)   (MAT_BARE_HANDLE_T);
typedef BOOL    (__stdcall MAT_ResetFnT)    (MAT_BARE_HANDLE_T);
typedef BOOL    (__stdcall MAT_SetIntegrationTimeFnT) (MAT_BARE_HANDLE_T,
MAT_INT_TIME_E);
typedef BOOL    (__stdcall MAT_EnableSubDarkImageFnT) (MAT_BARE_HANDLE_T,
BOOL);
typedef BOOL    (__stdcall MAT_SetDarkImageFnT)   (MAT_BARE_HANDLE_T,
MAT_IMAGE_DATA_T *);
typedef BOOL    (__stdcall MAT_SoftwareIdFnT)   (MAT_BARE_HANDLE_T, char *,
char *);
.....


Tue, 01 Mar 2005 21:13:09 GMT  
 Wrap to COM.
i dont think so there should be any problem in wraping the dll in COM
component
In this case there is going to be 1 more indirection if ur happy with that
overhead no probs

Vinod

Quote:
> I have sample code below:
>   // Load the DLL and initialise it.
>  m_DllInst = LoadLibrary("ccddll.dll");
>  BOOL status = MAT_Initialise(&m_CcdDevice,  m_DllInst);
>  assert(status != FALSE);

> Can I wrap it to COM (load 'ccddll.dll' into my ATL server and open some
> interfaces for VB to access?

> Thanks..

> CcdInterface.h:

/*==========================================================================
Quote:
> =
>  *
>  * File: $Workfile: CcdInterface.h $
>  *
>  *
>  * Description:
>  *
>  * This file contains the definitions for the interface classes that lie
> between the
>  * application program and the hardware interface library.
>  *
>  *

****************************************************************************
Quote:
>  ....
> /*
>  * Declare a handle type for the attached CCD device. In this case the
> handle becomes a
>  * compound type containing the DLL instance and the handle of the CCD
> device. A sub-type
>  * is defined for the CCD device handle that is passed to the DLL
functions.
>  */
> typedef void *MAT_BARE_HANDLE_T;
> typedef struct
> {
>  MAT_BARE_HANDLE_T the_handle;
>  HINSTANCE   dll_instance;
> } MAT_HANDLE_T;

> /*
>  * Typedef function pointers for all of the interface functions
>  */
> typedef BOOL    (__stdcall MAT_InitialiseFnT)   (void);
> typedef BOOL    (__stdcall MAT_ConnectFnT)    (MAT_BARE_HANDLE_T *,
> MAT_TYPE_E);
> typedef BOOL    (__stdcall MAT_DisconnectFnT)   (MAT_BARE_HANDLE_T);
> typedef int     (__stdcall MAT_GetXSizeFnT)    (MAT_BARE_HANDLE_T);
> typedef int     (__stdcall MAT_GetYSizeFnT)    (MAT_BARE_HANDLE_T);
> typedef MAT_IMAGE_DATA_T * (__stdcall MAT_GetImageFnT)
> (MAT_BARE_HANDLE_T);
> typedef BOOL    (__stdcall MAT_GetStatusFnT)   (MAT_BARE_HANDLE_T,
> MAT_STATUS_T *);
> typedef BOOL    (__stdcall MAT_ArmFnT)     (MAT_BARE_HANDLE_T);
> typedef BOOL    (__stdcall MAT_IsArmedFnT)    (MAT_BARE_HANDLE_T);
> typedef BOOL    (__stdcall MAT_EnableBinningFnT)  (MAT_BARE_HANDLE_T,
BOOL);
> typedef BOOL    (__stdcall MAT_EnableManualTriggerFnT) (MAT_BARE_HANDLE_T,
> BOOL);
> typedef BOOL    (__stdcall MAT_ForceTriggerFnT)   (MAT_BARE_HANDLE_T);
> typedef BOOL    (__stdcall MAT_ResetFnT)    (MAT_BARE_HANDLE_T);
> typedef BOOL    (__stdcall MAT_SetIntegrationTimeFnT) (MAT_BARE_HANDLE_T,
> MAT_INT_TIME_E);
> typedef BOOL    (__stdcall MAT_EnableSubDarkImageFnT) (MAT_BARE_HANDLE_T,
> BOOL);
> typedef BOOL    (__stdcall MAT_SetDarkImageFnT)   (MAT_BARE_HANDLE_T,
> MAT_IMAGE_DATA_T *);
> typedef BOOL    (__stdcall MAT_SoftwareIdFnT)   (MAT_BARE_HANDLE_T, char
*,
> char *);
> .....



Wed, 02 Mar 2005 00:53:07 GMT  
 Wrap to COM.
I'm most there.
Still don't know how to pass the image structure back the client(only need
to pass the point back?)

Thanks,


Quote:
> i dont think so there should be any problem in wraping the dll in COM
> component
> In this case there is going to be 1 more indirection if ur happy with that
> overhead no probs

> Vinod


> > I have sample code below:
> >   // Load the DLL and initialise it.
> >  m_DllInst = LoadLibrary("ccddll.dll");
> >  BOOL status = MAT_Initialise(&m_CcdDevice,  m_DllInst);
> >  assert(status != FALSE);

> > Can I wrap it to COM (load 'ccddll.dll' into my ATL server and open some
> > interfaces for VB to access?

> > Thanks..

> > CcdInterface.h:

/*==========================================================================
Quote:
> > =
> >  *
> >  * File: $Workfile: CcdInterface.h $
> >  *
> >  *
> >  * Description:
> >  *
> >  * This file contains the definitions for the interface classes that lie
> > between the
> >  * application program and the hardware interface library.
> >  *
> >  *

****************************************************************************

- Show quoted text -

Quote:
> >  ....
> > /*
> >  * Declare a handle type for the attached CCD device. In this case the
> > handle becomes a
> >  * compound type containing the DLL instance and the handle of the CCD
> > device. A sub-type
> >  * is defined for the CCD device handle that is passed to the DLL
> functions.
> >  */
> > typedef void *MAT_BARE_HANDLE_T;
> > typedef struct
> > {
> >  MAT_BARE_HANDLE_T the_handle;
> >  HINSTANCE   dll_instance;
> > } MAT_HANDLE_T;

> > /*
> >  * Typedef function pointers for all of the interface functions
> >  */
> > typedef BOOL    (__stdcall MAT_InitialiseFnT)   (void);
> > typedef BOOL    (__stdcall MAT_ConnectFnT)    (MAT_BARE_HANDLE_T *,
> > MAT_TYPE_E);
> > typedef BOOL    (__stdcall MAT_DisconnectFnT)   (MAT_BARE_HANDLE_T);
> > typedef int     (__stdcall MAT_GetXSizeFnT)    (MAT_BARE_HANDLE_T);
> > typedef int     (__stdcall MAT_GetYSizeFnT)    (MAT_BARE_HANDLE_T);
> > typedef MAT_IMAGE_DATA_T * (__stdcall MAT_GetImageFnT)
> > (MAT_BARE_HANDLE_T);
> > typedef BOOL    (__stdcall MAT_GetStatusFnT)   (MAT_BARE_HANDLE_T,
> > MAT_STATUS_T *);
> > typedef BOOL    (__stdcall MAT_ArmFnT)     (MAT_BARE_HANDLE_T);
> > typedef BOOL    (__stdcall MAT_IsArmedFnT)    (MAT_BARE_HANDLE_T);
> > typedef BOOL    (__stdcall MAT_EnableBinningFnT)  (MAT_BARE_HANDLE_T,
> BOOL);
> > typedef BOOL    (__stdcall MAT_EnableManualTriggerFnT)
(MAT_BARE_HANDLE_T,
> > BOOL);
> > typedef BOOL    (__stdcall MAT_ForceTriggerFnT)   (MAT_BARE_HANDLE_T);
> > typedef BOOL    (__stdcall MAT_ResetFnT)    (MAT_BARE_HANDLE_T);
> > typedef BOOL    (__stdcall MAT_SetIntegrationTimeFnT)
(MAT_BARE_HANDLE_T,
> > MAT_INT_TIME_E);
> > typedef BOOL    (__stdcall MAT_EnableSubDarkImageFnT)
(MAT_BARE_HANDLE_T,
> > BOOL);
> > typedef BOOL    (__stdcall MAT_SetDarkImageFnT)   (MAT_BARE_HANDLE_T,
> > MAT_IMAGE_DATA_T *);
> > typedef BOOL    (__stdcall MAT_SoftwareIdFnT)   (MAT_BARE_HANDLE_T, char
> *,
> > char *);
> > .....



Wed, 02 Mar 2005 03:22:15 GMT  
 Wrap to COM.
Create yet another COM object wrapping image structure, create an
instance as needed and pass its interface pointer back to the client.
--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken


Quote:
> I'm most there.
> Still don't know how to pass the image structure back the client(only
need
> to pass the point back?)

> Thanks,



> > i dont think so there should be any problem in wraping the dll in
COM
> > component
> > In this case there is going to be 1 more indirection if ur happy
with that
> > overhead no probs

> > Vinod


> > > I have sample code below:
> > >   // Load the DLL and initialise it.
> > >  m_DllInst = LoadLibrary("ccddll.dll");
> > >  BOOL status = MAT_Initialise(&m_CcdDevice,  m_DllInst);
> > >  assert(status != FALSE);

> > > Can I wrap it to COM (load 'ccddll.dll' into my ATL server and
open some
> > > interfaces for VB to access?

> > > Thanks..

> > > CcdInterface.h:

/*======================================================================
====

- Show quoted text -

Quote:
> > > =
> > >  *
> > >  * File: $Workfile: CcdInterface.h $
> > >  *
> > >  *
> > >  * Description:
> > >  *
> > >  * This file contains the definitions for the interface classes
that lie
> > > between the
> > >  * application program and the hardware interface library.
> > >  *
> > >  *

************************************************************************
****

- Show quoted text -

Quote:
> > >  ....
> > > /*
> > >  * Declare a handle type for the attached CCD device. In this case
the
> > > handle becomes a
> > >  * compound type containing the DLL instance and the handle of the
CCD
> > > device. A sub-type
> > >  * is defined for the CCD device handle that is passed to the DLL
> > functions.
> > >  */
> > > typedef void *MAT_BARE_HANDLE_T;
> > > typedef struct
> > > {
> > >  MAT_BARE_HANDLE_T the_handle;
> > >  HINSTANCE   dll_instance;
> > > } MAT_HANDLE_T;

> > > /*
> > >  * Typedef function pointers for all of the interface functions
> > >  */
> > > typedef BOOL    (__stdcall MAT_InitialiseFnT)   (void);
> > > typedef BOOL    (__stdcall MAT_ConnectFnT)    (MAT_BARE_HANDLE_T
*,
> > > MAT_TYPE_E);
> > > typedef BOOL    (__stdcall MAT_DisconnectFnT)

(MAT_BARE_HANDLE_T);
Quote:
> > > typedef int     (__stdcall MAT_GetXSizeFnT)

(MAT_BARE_HANDLE_T);
Quote:
> > > typedef int     (__stdcall MAT_GetYSizeFnT)

(MAT_BARE_HANDLE_T);
Quote:
> > > typedef MAT_IMAGE_DATA_T * (__stdcall MAT_GetImageFnT)
> > > (MAT_BARE_HANDLE_T);
> > > typedef BOOL    (__stdcall MAT_GetStatusFnT)   (MAT_BARE_HANDLE_T,
> > > MAT_STATUS_T *);
> > > typedef BOOL    (__stdcall MAT_ArmFnT)     (MAT_BARE_HANDLE_T);
> > > typedef BOOL    (__stdcall MAT_IsArmedFnT)    (MAT_BARE_HANDLE_T);
> > > typedef BOOL    (__stdcall MAT_EnableBinningFnT)
(MAT_BARE_HANDLE_T,
> > BOOL);
> > > typedef BOOL    (__stdcall MAT_EnableManualTriggerFnT)
> (MAT_BARE_HANDLE_T,
> > > BOOL);
> > > typedef BOOL    (__stdcall MAT_ForceTriggerFnT)

(MAT_BARE_HANDLE_T);
Quote:
> > > typedef BOOL    (__stdcall MAT_ResetFnT)    (MAT_BARE_HANDLE_T);
> > > typedef BOOL    (__stdcall MAT_SetIntegrationTimeFnT)
> (MAT_BARE_HANDLE_T,
> > > MAT_INT_TIME_E);
> > > typedef BOOL    (__stdcall MAT_EnableSubDarkImageFnT)
> (MAT_BARE_HANDLE_T,
> > > BOOL);
> > > typedef BOOL    (__stdcall MAT_SetDarkImageFnT)
(MAT_BARE_HANDLE_T,
> > > MAT_IMAGE_DATA_T *);
> > > typedef BOOL    (__stdcall MAT_SoftwareIdFnT)

(MAT_BARE_HANDLE_T, char

- Show quoted text -

Quote:
> > *,
> > > char *);
> > > .....



Wed, 02 Mar 2005 03:50:54 GMT  
 Wrap to COM.
Thanks.

How to pass its interface pointer back to the client.


Quote:
> Create yet another COM object wrapping image structure, create an
> instance as needed and pass its interface pointer back to the client.
> --
> With best wishes,
>     Igor Tandetnik

> "For every complex problem, there is a solution that is simple, neat,
> and wrong." H.L. Mencken



> > I'm most there.
> > Still don't know how to pass the image structure back the client(only
> need
> > to pass the point back?)

> > Thanks,



> > > i dont think so there should be any problem in wraping the dll in
> COM
> > > component
> > > In this case there is going to be 1 more indirection if ur happy
> with that
> > > overhead no probs

> > > Vinod


> > > > I have sample code below:
> > > >   // Load the DLL and initialise it.
> > > >  m_DllInst = LoadLibrary("ccddll.dll");
> > > >  BOOL status = MAT_Initialise(&m_CcdDevice,  m_DllInst);
> > > >  assert(status != FALSE);

> > > > Can I wrap it to COM (load 'ccddll.dll' into my ATL server and
> open some
> > > > interfaces for VB to access?

> > > > Thanks..

> > > > CcdInterface.h:

> /*======================================================================
> ====
> > > > =
> > > >  *
> > > >  * File: $Workfile: CcdInterface.h $
> > > >  *
> > > >  *
> > > >  * Description:
> > > >  *
> > > >  * This file contains the definitions for the interface classes
> that lie
> > > > between the
> > > >  * application program and the hardware interface library.
> > > >  *
> > > >  *

> ************************************************************************
> ****
> > > >  ....
> > > > /*
> > > >  * Declare a handle type for the attached CCD device. In this case
> the
> > > > handle becomes a
> > > >  * compound type containing the DLL instance and the handle of the
> CCD
> > > > device. A sub-type
> > > >  * is defined for the CCD device handle that is passed to the DLL
> > > functions.
> > > >  */
> > > > typedef void *MAT_BARE_HANDLE_T;
> > > > typedef struct
> > > > {
> > > >  MAT_BARE_HANDLE_T the_handle;
> > > >  HINSTANCE   dll_instance;
> > > > } MAT_HANDLE_T;

> > > > /*
> > > >  * Typedef function pointers for all of the interface functions
> > > >  */
> > > > typedef BOOL    (__stdcall MAT_InitialiseFnT)   (void);
> > > > typedef BOOL    (__stdcall MAT_ConnectFnT)    (MAT_BARE_HANDLE_T
> *,
> > > > MAT_TYPE_E);
> > > > typedef BOOL    (__stdcall MAT_DisconnectFnT)
> (MAT_BARE_HANDLE_T);
> > > > typedef int     (__stdcall MAT_GetXSizeFnT)
> (MAT_BARE_HANDLE_T);
> > > > typedef int     (__stdcall MAT_GetYSizeFnT)
> (MAT_BARE_HANDLE_T);
> > > > typedef MAT_IMAGE_DATA_T * (__stdcall MAT_GetImageFnT)
> > > > (MAT_BARE_HANDLE_T);
> > > > typedef BOOL    (__stdcall MAT_GetStatusFnT)   (MAT_BARE_HANDLE_T,
> > > > MAT_STATUS_T *);
> > > > typedef BOOL    (__stdcall MAT_ArmFnT)     (MAT_BARE_HANDLE_T);
> > > > typedef BOOL    (__stdcall MAT_IsArmedFnT)    (MAT_BARE_HANDLE_T);
> > > > typedef BOOL    (__stdcall MAT_EnableBinningFnT)
> (MAT_BARE_HANDLE_T,
> > > BOOL);
> > > > typedef BOOL    (__stdcall MAT_EnableManualTriggerFnT)
> > (MAT_BARE_HANDLE_T,
> > > > BOOL);
> > > > typedef BOOL    (__stdcall MAT_ForceTriggerFnT)
> (MAT_BARE_HANDLE_T);
> > > > typedef BOOL    (__stdcall MAT_ResetFnT)    (MAT_BARE_HANDLE_T);
> > > > typedef BOOL    (__stdcall MAT_SetIntegrationTimeFnT)
> > (MAT_BARE_HANDLE_T,
> > > > MAT_INT_TIME_E);
> > > > typedef BOOL    (__stdcall MAT_EnableSubDarkImageFnT)
> > (MAT_BARE_HANDLE_T,
> > > > BOOL);
> > > > typedef BOOL    (__stdcall MAT_SetDarkImageFnT)
> (MAT_BARE_HANDLE_T,
> > > > MAT_IMAGE_DATA_T *);
> > > > typedef BOOL    (__stdcall MAT_SoftwareIdFnT)
> (MAT_BARE_HANDLE_T, char
> > > *,
> > > > char *);
> > > > .....



Thu, 03 Mar 2005 12:41:02 GMT  
 Wrap to COM.
HRESULT get_myInterfacePointer([out, retval] IMyInterface** ppResult);

--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken


Quote:
> Thanks.

> How to pass its interface pointer back to the client.



> > Create yet another COM object wrapping image structure, create an
> > instance as needed and pass its interface pointer back to the
client.
> > --
> > With best wishes,
> >     Igor Tandetnik

> > "For every complex problem, there is a solution that is simple,
neat,
> > and wrong." H.L. Mencken



> > > I'm most there.
> > > Still don't know how to pass the image structure back the
client(only
> > need
> > > to pass the point back?)

> > > Thanks,



> > > > i dont think so there should be any problem in wraping the dll
in
> > COM
> > > > component
> > > > In this case there is going to be 1 more indirection if ur happy
> > with that
> > > > overhead no probs

> > > > Vinod


> > > > > I have sample code below:
> > > > >   // Load the DLL and initialise it.
> > > > >  m_DllInst = LoadLibrary("ccddll.dll");
> > > > >  BOOL status = MAT_Initialise(&m_CcdDevice,  m_DllInst);
> > > > >  assert(status != FALSE);

> > > > > Can I wrap it to COM (load 'ccddll.dll' into my ATL server and
> > open some
> > > > > interfaces for VB to access?

> > > > > Thanks..

> > > > > CcdInterface.h:

/*======================================================================

- Show quoted text -

Quote:
> > ====
> > > > > =
> > > > >  *
> > > > >  * File: $Workfile: CcdInterface.h $
> > > > >  *
> > > > >  *
> > > > >  * Description:
> > > > >  *
> > > > >  * This file contains the definitions for the interface
classes
> > that lie
> > > > > between the
> > > > >  * application program and the hardware interface library.
> > > > >  *
> > > > >  *

************************************************************************

- Show quoted text -

Quote:
> > ****
> > > > >  ....
> > > > > /*
> > > > >  * Declare a handle type for the attached CCD device. In this
case
> > the
> > > > > handle becomes a
> > > > >  * compound type containing the DLL instance and the handle of
the
> > CCD
> > > > > device. A sub-type
> > > > >  * is defined for the CCD device handle that is passed to the
DLL
> > > > functions.
> > > > >  */
> > > > > typedef void *MAT_BARE_HANDLE_T;
> > > > > typedef struct
> > > > > {
> > > > >  MAT_BARE_HANDLE_T the_handle;
> > > > >  HINSTANCE   dll_instance;
> > > > > } MAT_HANDLE_T;

> > > > > /*
> > > > >  * Typedef function pointers for all of the interface
functions
> > > > >  */
> > > > > typedef BOOL    (__stdcall MAT_InitialiseFnT)   (void);
> > > > > typedef BOOL    (__stdcall MAT_ConnectFnT)
(MAT_BARE_HANDLE_T
> > *,
> > > > > MAT_TYPE_E);
> > > > > typedef BOOL    (__stdcall MAT_DisconnectFnT)
> > (MAT_BARE_HANDLE_T);
> > > > > typedef int     (__stdcall MAT_GetXSizeFnT)
> > (MAT_BARE_HANDLE_T);
> > > > > typedef int     (__stdcall MAT_GetYSizeFnT)
> > (MAT_BARE_HANDLE_T);
> > > > > typedef MAT_IMAGE_DATA_T * (__stdcall MAT_GetImageFnT)
> > > > > (MAT_BARE_HANDLE_T);
> > > > > typedef BOOL    (__stdcall MAT_GetStatusFnT)
(MAT_BARE_HANDLE_T,
> > > > > MAT_STATUS_T *);
> > > > > typedef BOOL    (__stdcall MAT_ArmFnT)

(MAT_BARE_HANDLE_T);
Quote:
> > > > > typedef BOOL    (__stdcall MAT_IsArmedFnT)

(MAT_BARE_HANDLE_T);
Quote:
> > > > > typedef BOOL    (__stdcall MAT_EnableBinningFnT)
> > (MAT_BARE_HANDLE_T,
> > > > BOOL);
> > > > > typedef BOOL    (__stdcall MAT_EnableManualTriggerFnT)
> > > (MAT_BARE_HANDLE_T,
> > > > > BOOL);
> > > > > typedef BOOL    (__stdcall MAT_ForceTriggerFnT)
> > (MAT_BARE_HANDLE_T);
> > > > > typedef BOOL    (__stdcall MAT_ResetFnT)

(MAT_BARE_HANDLE_T);

- Show quoted text -

Quote:
> > > > > typedef BOOL    (__stdcall MAT_SetIntegrationTimeFnT)
> > > (MAT_BARE_HANDLE_T,
> > > > > MAT_INT_TIME_E);
> > > > > typedef BOOL    (__stdcall MAT_EnableSubDarkImageFnT)
> > > (MAT_BARE_HANDLE_T,
> > > > > BOOL);
> > > > > typedef BOOL    (__stdcall MAT_SetDarkImageFnT)
> > (MAT_BARE_HANDLE_T,
> > > > > MAT_IMAGE_DATA_T *);
> > > > > typedef BOOL    (__stdcall MAT_SoftwareIdFnT)
> > (MAT_BARE_HANDLE_T, char
> > > > *,
> > > > > char *);
> > > > > .....



Fri, 04 Mar 2005 22:09:22 GMT  
 Wrap to COM.
Thanks for the reply.

The image buffer were a 2 dimensional array :
 unsigned short image_array[Y_SIZE][X_SIZE]

x.h:
typedef unsigned short M_IMAGE_DATA_T;

public:
M_IMAGE_DATA_T *m_Image;

STDMETHOD(get_Image) ( [out, retval] VARIANT * pResult)
or
STDMETHOD(get_Image) ( [out, retval] unsigned short * pResult[]) -- wrong
here?
{
     How to simply assign m_Image to  pResult?
     and do I need to free the m_Image resource?

Quote:
}

Thank you again!


Fri, 04 Mar 2005 23:04:28 GMT  
 Wrap to COM.
If you know the client needs all or most of the data in the image, you
can return a SAFEARRAY of shorts - it supports 2D arrays with variable
boundaries.

HRESULT get_Image([out, retval] SAFEARRAY(short)** ppResult);

Create an array with SafeArrayCreate, get access to internal buffer with
SafeArrayAccessData, fill it with data, unlock with
SafeArrayUnaccessData.

If you know the client will typically access small number of pixels in
the image, create a new COM object that internally holds image data.
Implement an interface on this object that has properties for accessing
individual pixels, and maybe a property for getting all data at once as
described above. Create this object and return its interface from
get_Image. That's what I meant by wrapping image structure in a COM
object.
--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken


Quote:
> Thanks for the reply.

> The image buffer were a 2 dimensional array :
>  unsigned short image_array[Y_SIZE][X_SIZE]

> x.h:
> typedef unsigned short M_IMAGE_DATA_T;

> public:
> M_IMAGE_DATA_T *m_Image;

> STDMETHOD(get_Image) ( [out, retval] VARIANT * pResult)
> or
> STDMETHOD(get_Image) ( [out, retval] unsigned short * pResult[]) --
wrong
> here?
> {
>      How to simply assign m_Image to  pResult?
>      and do I need to free the m_Image resource?
> }

> Thank you again!



Sat, 05 Mar 2005 02:52:13 GMT  
 Wrap to COM.
C++ code looks fine, except that since you use SafeArrayPutElement, you
don't need SafeArrayAccessData / SafeArrayUnaccessData. Those are for
direct access to raw data buffer, which is much more efficient than
SafeArrayPutElement.

What is the IDL definition of the method? How is VB calling it?

Also, UBound is inclusive - it's not an element count, it's the highest
valid index. You don't want to subtract 1.
--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken


Quote:
> Thanks for your help.

> The code below didn't return correct result to client.  Please help me
take
> a look.

> Thanks..

> VB client:

> For R = 0 To UBound(colorArray, 2) - 1
>         For C = 0 To UBound(colorArray, 1) - 1
>             Debug.Print colorArray(C, R) & Space(5);  // Here has err:
> Subscript out of range.
>         Next
>         Sort.Print
> Next

> > Create an array with SafeArrayCreate, get access to internal buffer
with
> > SafeArrayAccessData, fill it with data, unlock with
> > SafeArrayUnaccessData.

> x.h:
> typedef unsigned short M_IMAGE_DATA_T;

> public:
> M_IMAGE_DATA_T *m_Image;

> STDMETHODIMP COMIManage::M_GetImage(VARIANT *pVal)
> {
>   VariantInit(pVal);
>   pVal->vt = VT_ARRAY |VT_I2;

>   unsigned short data,*ptr=&m_Image[0];

>   SAFEARRAY* psa;

>  SAFEARRAYBOUND rgb[] = {{0,m_YSize},{0,m_XSize}};
>  psa = SafeArrayCreate(VT_I2,2, rgb);

>  short shArray;
>  SafeArrayAccessData(psa,(void**) & shArray);

>  long ai[2];

>  for (int y=0; y<m_YSize; y++)
>     {

>    ai[0] = y;
>       for (int x=0; x<m_XSize; x++)
>       {
>   ai[1] = x
>   data = static_cast<short>(*ptr ) ;

>   SafeArrayPutElement(psa, ai, &data);

>   ptr++;

>    }
>    }

>  SafeArrayUnaccessData(psa);

>  pVal->parray = psa;

> return S_OK;
> }



Sat, 05 Mar 2005 05:57:35 GMT  
 Wrap to COM.
Thanks for your help.

The code below didn't return correct result to client.  Please help me take
a look.

Thanks..

VB client:

For R = 0 To UBound(colorArray, 2) - 1
        For C = 0 To UBound(colorArray, 1) - 1
            Debug.Print colorArray(C, R) & Space(5);  // Here has err:
Subscript out of range.
        Next
        Sort.Print
Next

Quote:
> Create an array with SafeArrayCreate, get access to internal buffer with
> SafeArrayAccessData, fill it with data, unlock with
> SafeArrayUnaccessData.

x.h:
typedef unsigned short M_IMAGE_DATA_T;

public:
M_IMAGE_DATA_T *m_Image;

STDMETHODIMP COMIManage::M_GetImage(VARIANT *pVal)
{
  VariantInit(pVal);
  pVal->vt = VT_ARRAY |VT_I2;

  unsigned short data,*ptr=&m_Image[0];

  SAFEARRAY* psa;

 SAFEARRAYBOUND rgb[] = {{0,m_YSize},{0,m_XSize}};
 psa = SafeArrayCreate(VT_I2,2, rgb);

 short shArray;
 SafeArrayAccessData(psa,(void**) & shArray);

 long ai[2];

 for (int y=0; y<m_YSize; y++)
    {

   ai[0] = y;
      for (int x=0; x<m_XSize; x++)
      {
  ai[1] = x
  data = static_cast<short>(*ptr ) ;

  SafeArrayPutElement(psa, ai, &data);

  ptr++;

   }
   }

 SafeArrayUnaccessData(psa);

 pVal->parray = psa;

return S_OK;

Quote:
}



Sat, 05 Mar 2005 05:30:03 GMT  
 Wrap to COM.
Let me correct myself:

[id(16), helpstring("method O_GetImage")] HRESULT O_GetImage([out, retval]
VARIANT *pVal);

STDMETHODIMP COMImageManage::OM_GetImage(VARIANT *pVal)
{
   ...

Quote:
}



Sat, 05 Mar 2005 06:22:55 GMT  
 Wrap to COM.

Quote:
> What is the IDL definition of the method? How is VB calling it?

[id(16), helpstring("method O_GetImage")] HRESULT OM_GetImage3([out, retval]
VARIANT *pVal);

STDMETHODIMP COMImageManage::OM_GetImage1(VARIANT *pVal)
{

 // Get a pointer to image data store
 m_Image = M_GetImage(m_CcdDevice);

 VariantInit(pVal);
 pVal->vt = VT_ARRAY |VT_I2;

 unsigned short data,*ptr=&m_Image[0];

 SAFEARRAY* psa;

// Always:
// m_YSize = 1274;
// m_XSize = 1640;

SAFEARRAYBOUND rgb[] = {{0,m_YSize},{0,m_XSize}};
 psa = SafeArrayCreate(VT_I2,2, rgb);

 long ai[2];

 for (int y=0; y<m_YSize; y++)
     {

    ai[0] = y;
       for (int x=0; x<m_XSize; x++)
       {
  ai[1] = x;

  short temp_data = static_cast<short>(*ptr ) - 32768;

  data =  (temp_data & 0xFF) << 8;   // Swap the byte order
         data |= (temp_data >> 8) & 0xFF;

  SafeArrayPutElement(psa, ai, &data);

  ptr++;

   }
   }

  pVal->parray = psa;

   return S_OK;

Quote:
}

VB Code:

Dim objC As OImageManage
Set objC = New OImageManage

Dim colorArray As Variant

colorArray = objC.O_GetImage()

For R = 0 To UBound(colorArray, 2) - 1
        For C = 0 To UBound(colorArray, 1) - 1
            Debug.Print colorArray(C, R) & Space(5);
        Next
Next
set objC = Nothing

Debug:
?UBound(colorArray, 2)
 1639
?UBound(colorArray, 1)
 1273
Locals Window:
Expression        Value                             Type
+ : colorArray :  <No Variables>          : Variant/Integer(1274 to 1273,
1640 to 1639)

When try to print:
?colorArray(C, R)
Error:  Subscript out of range.

Thanks again!



Sat, 05 Mar 2005 06:18:45 GMT  
 Wrap to COM.
Yes. you found it.
Thanks for your responses...

I changed it to:
SAFEARRAYBOUND rgb[] = {{m_YSize,1},{m_XSize,1}};
and it works.

But the array all contains value(128).
Is it something wrong with SafeArrayPutElement(psa, ai, &data);?

Another problem is the array always contain 128

Quote:
> Got it. The definition of SAFEARRAYBOUND is

> typedef struct tagSAFEARRAYBOUND {
>    unsigned long cElements;
>    long lLbound;
> } SAFEARRAYBOUND;

> Number of elements goes first, low bound second. You are initializing
> your dimentions with zero elements and a large low bound. In your VB
> code you are looping from 0, not from LBound, but 0 is way out of range.
> --
> With best wishes,
>     Igor Tandetnik

> "For every complex problem, there is a solution that is simple, neat,
> and wrong." H.L. Mencken



> > > What is the IDL definition of the method? How is VB calling it?

> > [id(16), helpstring("method O_GetImage")] HRESULT OM_GetImage3([out,
> retval]
> > VARIANT *pVal);

> > STDMETHODIMP COMImageManage::OM_GetImage1(VARIANT *pVal)
> > {

> >  // Get a pointer to image data store
> >  m_Image = M_GetImage(m_CcdDevice);

> >  VariantInit(pVal);
> >  pVal->vt = VT_ARRAY |VT_I2;

> >  unsigned short data,*ptr=&m_Image[0];

> >  SAFEARRAY* psa;

> > // Always:
> > // m_YSize = 1274;
> > // m_XSize = 1640;

> > SAFEARRAYBOUND rgb[] = {{0,m_YSize},{0,m_XSize}};
> >  psa = SafeArrayCreate(VT_I2,2, rgb);

> >  long ai[2];

> >  for (int y=0; y<m_YSize; y++)
> >      {

> >     ai[0] = y;
> >        for (int x=0; x<m_XSize; x++)
> >        {
> >   ai[1] = x;

> >   short temp_data = static_cast<short>(*ptr ) - 32768;

> >   data =  (temp_data & 0xFF) << 8;   // Swap the byte order
> >          data |= (temp_data >> 8) & 0xFF;

> >   SafeArrayPutElement(psa, ai, &data);

> >   ptr++;

> >    }
> >    }

> >   pVal->parray = psa;

> >    return S_OK;
> > }

> > VB Code:

> > Dim objC As OImageManage
> > Set objC = New OImageManage

> > Dim colorArray As Variant

> > colorArray = objC.O_GetImage()

> > For R = 0 To UBound(colorArray, 2) - 1
> >         For C = 0 To UBound(colorArray, 1) - 1
> >             Debug.Print colorArray(C, R) & Space(5);
> >         Next
> > Next
> > set objC = Nothing

> > Debug:
> > ?UBound(colorArray, 2)
> >  1639
> > ?UBound(colorArray, 1)
> >  1273
> > Locals Window:
> > Expression        Value                             Type
> > + : colorArray :  <No Variables>          : Variant/Integer(1274 to
> 1273,
> > 1640 to 1639)

> > When try to print:
> > ?colorArray(C, R)
> > Error:  Subscript out of range.

> > Thanks again!



Sat, 05 Mar 2005 07:15:09 GMT  
 Wrap to COM.
Got it. The definition of SAFEARRAYBOUND is

typedef struct tagSAFEARRAYBOUND {
   unsigned long cElements;
   long lLbound;

Quote:
} SAFEARRAYBOUND;

Number of elements goes first, low bound second. You are initializing
your dimentions with zero elements and a large low bound. In your VB
code you are looping from 0, not from LBound, but 0 is way out of range.
--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken


Quote:

> > What is the IDL definition of the method? How is VB calling it?

> [id(16), helpstring("method O_GetImage")] HRESULT OM_GetImage3([out,
retval]
> VARIANT *pVal);

> STDMETHODIMP COMImageManage::OM_GetImage1(VARIANT *pVal)
> {

>  // Get a pointer to image data store
>  m_Image = M_GetImage(m_CcdDevice);

>  VariantInit(pVal);
>  pVal->vt = VT_ARRAY |VT_I2;

>  unsigned short data,*ptr=&m_Image[0];

>  SAFEARRAY* psa;

> // Always:
> // m_YSize = 1274;
> // m_XSize = 1640;

> SAFEARRAYBOUND rgb[] = {{0,m_YSize},{0,m_XSize}};
>  psa = SafeArrayCreate(VT_I2,2, rgb);

>  long ai[2];

>  for (int y=0; y<m_YSize; y++)
>      {

>     ai[0] = y;
>        for (int x=0; x<m_XSize; x++)
>        {
>   ai[1] = x;

>   short temp_data = static_cast<short>(*ptr ) - 32768;

>   data =  (temp_data & 0xFF) << 8;   // Swap the byte order
>          data |= (temp_data >> 8) & 0xFF;

>   SafeArrayPutElement(psa, ai, &data);

>   ptr++;

>    }
>    }

>   pVal->parray = psa;

>    return S_OK;
> }

> VB Code:

> Dim objC As OImageManage
> Set objC = New OImageManage

> Dim colorArray As Variant

> colorArray = objC.O_GetImage()

> For R = 0 To UBound(colorArray, 2) - 1
>         For C = 0 To UBound(colorArray, 1) - 1
>             Debug.Print colorArray(C, R) & Space(5);
>         Next
> Next
> set objC = Nothing

> Debug:
> ?UBound(colorArray, 2)
>  1639
> ?UBound(colorArray, 1)
>  1273
> Locals Window:
> Expression        Value                             Type
> + : colorArray :  <No Variables>          : Variant/Integer(1274 to
1273,
> 1640 to 1639)

> When try to print:
> ?colorArray(C, R)
> Error:  Subscript out of range.

> Thanks again!



Sat, 05 Mar 2005 06:46:11 GMT  
 Wrap to COM.
Please ingore it. It works very well!

Thanks for your help.


Quote:
> Got it. The definition of SAFEARRAYBOUND is

> typedef struct tagSAFEARRAYBOUND {
>    unsigned long cElements;
>    long lLbound;
> } SAFEARRAYBOUND;

> Number of elements goes first, low bound second. You are initializing
> your dimentions with zero elements and a large low bound. In your VB
> code you are looping from 0, not from LBound, but 0 is way out of range.
> --
> With best wishes,
>     Igor Tandetnik

> "For every complex problem, there is a solution that is simple, neat,
> and wrong." H.L. Mencken



> > > What is the IDL definition of the method? How is VB calling it?

> > [id(16), helpstring("method O_GetImage")] HRESULT OM_GetImage3([out,
> retval]
> > VARIANT *pVal);

> > STDMETHODIMP COMImageManage::OM_GetImage1(VARIANT *pVal)
> > {

> >  // Get a pointer to image data store
> >  m_Image = M_GetImage(m_CcdDevice);

> >  VariantInit(pVal);
> >  pVal->vt = VT_ARRAY |VT_I2;

> >  unsigned short data,*ptr=&m_Image[0];

> >  SAFEARRAY* psa;

> > // Always:
> > // m_YSize = 1274;
> > // m_XSize = 1640;

> > SAFEARRAYBOUND rgb[] = {{0,m_YSize},{0,m_XSize}};
> >  psa = SafeArrayCreate(VT_I2,2, rgb);

> >  long ai[2];

> >  for (int y=0; y<m_YSize; y++)
> >      {

> >     ai[0] = y;
> >        for (int x=0; x<m_XSize; x++)
> >        {
> >   ai[1] = x;

> >   short temp_data = static_cast<short>(*ptr ) - 32768;

> >   data =  (temp_data & 0xFF) << 8;   // Swap the byte order
> >          data |= (temp_data >> 8) & 0xFF;

> >   SafeArrayPutElement(psa, ai, &data);

> >   ptr++;

> >    }
> >    }

> >   pVal->parray = psa;

> >    return S_OK;
> > }

> > VB Code:

> > Dim objC As OImageManage
> > Set objC = New OImageManage

> > Dim colorArray As Variant

> > colorArray = objC.O_GetImage()

> > For R = 0 To UBound(colorArray, 2) - 1
> >         For C = 0 To UBound(colorArray, 1) - 1
> >             Debug.Print colorArray(C, R) & Space(5);
> >         Next
> > Next
> > set objC = Nothing

> > Debug:
> > ?UBound(colorArray, 2)
> >  1639
> > ?UBound(colorArray, 1)
> >  1273
> > Locals Window:
> > Expression        Value                             Type
> > + : colorArray :  <No Variables>          : Variant/Integer(1274 to
> 1273,
> > 1640 to 1639)

> > When try to print:
> > ?colorArray(C, R)
> > Error:  Subscript out of range.

> > Thanks again!



Sat, 05 Mar 2005 07:21:21 GMT  
 
 [ 18 post ]  Go to page: [1] [2]

 Relevant Pages 

1. How to Debug .NET Component wrapped as COM

2. wrapping legacy code in com+ objects

3. Wrapping COM calls in ATL project (no MFC)

4. wrapping c++ function in COM

5. Wrapping C++ Code to make it a COM object

6. wrapping com dll doesn't work

7. JavaBean wrapped as a COM Object.......

8. Wrapped CTreeCtrl in Wrapped CTreeView?

9. Wrapping a non-COM function in a COM object?

10. Selling your product: cnet.com, smaller.com, mobileplanet.com, regnow.com, pocketgear.com, handango.com or what?

11. ATL COM - Passing ATL COM classes through another ATL COM class in the same app

12. Wrapping MCF classes in Managed c++ library

 

 
Powered by phpBB® Forum Software