VB C++ DirectX and COM 
Author Message
 VB C++ DirectX and COM

I am working in VB and another team are working in C++. How can I use a pure COM
pointer created within their DLL?

The pointers are IDirectDraw7, and two IDirectDrawSurface7 pointers for the
primary back buffer. As soon as I try and use them in VB (in place of DirectDraw7
and DirectDrawSurface7) the program crashes.

There seems to be a type mismatch between the pointer provided by the C++
interface of DirectDraw7 and the VB interface of DirectDraw7. I need to use the
instance of DirectDraw7 from the DLL but I want to use it

In the code extract below dd comes from the DLL. The program stops at ->.

        Dim SurfaceDescription As DDSURFACEDESC2

        SurfaceDescription.lFlags = DDSD_CAPS
        SurfaceDescription.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN

        FindMediaDir FileName

->           Set m_Surface = dd.CreateSurfaceFromFile(FileName, SurfaceDescription)

So the dd is an IDirectDraw7 pointer created in C++ which I want to use in VB.



Fri, 08 Aug 2003 04:25:19 GMT  
 VB C++ DirectX and COM
Hi,

You almost answered yourself...
in C++, the pointer points to an ISomething interface.
SO, it has to be the same with VB!
do something like:
<assume: Somthing is a COM class, ISomthing is the interface it implements>

Dim IObj as ISomthing
Dim Obj as Something

< let's say Obj was created and initialized >

Set IObj=Obj ' This queries the interface and "casts" Obj to IObj

retval =  myCPPFuncWhichRecievesAnISomething (IObj)


Quote:

> I am working in VB and another team are working in C++. How can I use a pure COM
> pointer created within their DLL?

> The pointers are IDirectDraw7, and two IDirectDrawSurface7 pointers for the
> primary back buffer. As soon as I try and use them in VB (in place of DirectDraw7
> and DirectDrawSurface7) the program crashes.

> There seems to be a type mismatch between the pointer provided by the C++
> interface of DirectDraw7 and the VB interface of DirectDraw7. I need to use the
> instance of DirectDraw7 from the DLL but I want to use it

> In the code extract below dd comes from the DLL. The program stops at ->.

>         Dim SurfaceDescription As DDSURFACEDESC2

>         SurfaceDescription.lFlags = DDSD_CAPS
>         SurfaceDescription.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN

>         FindMediaDir FileName

> ->      Set m_Surface = dd.CreateSurfaceFromFile(FileName, SurfaceDescription)

> So the dd is an IDirectDraw7 pointer created in C++ which I want to use in VB.



Fri, 08 Aug 2003 18:42:30 GMT  
 VB C++ DirectX and COM
Thanks

The trouble is I have tried casting IDirectDraw7 (C++) to DirectDraw7 (VB) and as
soon as I try to use it (for example creating an off screen surface) VB crashes
with a program error!

Any ideas?

Nathy

Quote:
-----Original Message-----

Hi,

You almost answered yourself...
in C++, the pointer points to an ISomething interface.
SO, it has to be the same with VB!
do something like:
<assume: Somthing is a COM class, ISomthing is the interface it implements>

Dim IObj as ISomthing
Dim Obj as Something

< let's say Obj was created and initialized >

Set IObj=Obj ' This queries the interface and "casts" Obj to IObj

retval =  myCPPFuncWhichRecievesAnISomething (IObj)



> I am working in VB and another team are working in C++. How can I use a pure COM
> pointer created within their DLL?

> The pointers are IDirectDraw7, and two IDirectDrawSurface7 pointers for the
> primary back buffer. As soon as I try and use them in VB (in place of
DirectDraw7
> and DirectDrawSurface7) the program crashes.

> There seems to be a type mismatch between the pointer provided by the C++
> interface of DirectDraw7 and the VB interface of DirectDraw7. I need to use the
> instance of DirectDraw7 from the DLL but I want to use it

> In the code extract below dd comes from the DLL. The program stops at ->.

>         Dim SurfaceDescription As DDSURFACEDESC2

>         SurfaceDescription.lFlags = DDSD_CAPS
>         SurfaceDescription.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN

>         FindMediaDir FileName

> ->      Set m_Surface = dd.CreateSurfaceFromFile(FileName, SurfaceDescription)

> So the dd is an IDirectDraw7 pointer created in C++ which I want to use in VB.

.



Fri, 08 Aug 2003 20:12:24 GMT  
 VB C++ DirectX and COM
Hi,

Can you add a code snippet from both the VC++ and VB projects?


Quote:

> Thanks

> The trouble is I have tried casting IDirectDraw7 (C++) to DirectDraw7 (VB) and as
> soon as I try to use it (for example creating an off screen surface) VB crashes
> with a program error!

> Any ideas?

> Nathy

> -----Original Message-----
> Hi,

> You almost answered yourself...
> in C++, the pointer points to an ISomething interface.
> SO, it has to be the same with VB!
> do something like:
> <assume: Somthing is a COM class, ISomthing is the interface it implements>

> Dim IObj as ISomthing
> Dim Obj as Something

> < let's say Obj was created and initialized >

> Set IObj=Obj ' This queries the interface and "casts" Obj to IObj

> retval =  myCPPFuncWhichRecievesAnISomething (IObj)



> > I am working in VB and another team are working in C++. How can I use a pure COM
> > pointer created within their DLL?

> > The pointers are IDirectDraw7, and two IDirectDrawSurface7 pointers for the
> > primary back buffer. As soon as I try and use them in VB (in place of
> DirectDraw7
> > and DirectDrawSurface7) the program crashes.

> > There seems to be a type mismatch between the pointer provided by the C++
> > interface of DirectDraw7 and the VB interface of DirectDraw7. I need to use the
> > instance of DirectDraw7 from the DLL but I want to use it

> > In the code extract below dd comes from the DLL. The program stops at ->.

> >         Dim SurfaceDescription As DDSURFACEDESC2

> >         SurfaceDescription.lFlags = DDSD_CAPS
> >         SurfaceDescription.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN

> >         FindMediaDir FileName

> > ->      Set m_Surface = dd.CreateSurfaceFromFile(FileName, SurfaceDescription)

> > So the dd is an IDirectDraw7 pointer created in C++ which I want to use in VB.

> .



Sat, 09 Aug 2003 00:01:43 GMT  
 VB C++ DirectX and COM
Not quite.. the best I can do is ..

From the Header file they gave me:

#ifndef DXInterfaces_STRUCT
#define DXInterfaces_STRUCT
typedef struct tagDXInterfaces
{
        LPDIRECTDRAW7   lpDD7;
        LPDIRECTDRAWSURFACE7 lpPrimarySurface;
        LPDIRECTDRAWSURFACE7 lpBackBuffer;

Quote:
} DXInterfaces;

#endif

and

PTENGINE_API bool PTA_GetDirectXInterfaces(DXInterfaces *lpDXI);

You see, the DLL is not a COM DLL is an std something whatever that is so I have
converted the above to:

Private Type DXInterfaces
    lpDD7 As DirectDraw7
    lpPrimarySurface As DirectDrawSurface7
    lpBackBuffer As DirectDrawSurface7

End Type

Private Declare Function PTA_GetDirectXInterfaces Lib "PTEngine.DLL" _
    (lpDXI As DXInterfaces) As Long

When I call the function:

    Dim DirectX As DXInterfaces

    InitDirectX = False

    If PTA_GetDirectXInterfaces(DirectX) Then
        Set dd = DirectX.lpDD7
        Set m_srfPrimary = DirectX.lpPrimarySurface
        Set m_srfBackBuffer = DirectX.lpBackBuffer

and then when I try to use one of the pointers:

    Dim SurfaceDescription As DDSURFACEDESC2

    SurfaceDescription.lFlags = DDSD_CAPS
    SurfaceDescription.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN

    FindMediaDir FileName

    Set m_Surface = dd.CreateSurfaceFromFile(FileName, SurfaceDescription)

at this point it all goes pair shape and VB dies!!

Do you see what is happening. I cannot declare the function and type in exactly
the same way since all I have access to in VB is the VB DirectX library!

Maybe if their DLL was a proper COM DLL is might work in VB but that obviously
would mean the other guys would have to rewrite their API?

The problem is that the other people are a third party in another part of the
world employed by my client!

Quote:
-----Original Message-----

Hi,

Can you add a code snippet from both the VC++ and VB projects?



> Thanks

> The trouble is I have tried casting IDirectDraw7 (C++) to DirectDraw7 (VB) and
as
> soon as I try to use it (for example creating an off screen surface) VB crashes
> with a program error!

> Any ideas?

> Nathy

> -----Original Message-----
> Hi,

> You almost answered yourself...
> in C++, the pointer points to an ISomething interface.
> SO, it has to be the same with VB!
> do something like:
> <assume: Somthing is a COM class, ISomthing is the interface it implements>

> Dim IObj as ISomthing
> Dim Obj as Something

> < let's say Obj was created and initialized >

> Set IObj=Obj ' This queries the interface and "casts" Obj to IObj

> retval =  myCPPFuncWhichRecievesAnISomething (IObj)



> > I am working in VB and another team are working in C++. How can I use a pure
COM
> > pointer created within their DLL?

> > The pointers are IDirectDraw7, and two IDirectDrawSurface7 pointers for the
> > primary back buffer. As soon as I try and use them in VB (in place of
> DirectDraw7
> > and DirectDrawSurface7) the program crashes.

> > There seems to be a type mismatch between the pointer provided by the C++
> > interface of DirectDraw7 and the VB interface of DirectDraw7. I need to use
the
> > instance of DirectDraw7 from the DLL but I want to use it

> > In the code extract below dd comes from the DLL. The program stops at ->.

> >         Dim SurfaceDescription As DDSURFACEDESC2

> >         SurfaceDescription.lFlags = DDSD_CAPS
> >         SurfaceDescription.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN

> >         FindMediaDir FileName

> > ->      Set m_Surface = dd.CreateSurfaceFromFile(FileName, SurfaceDescription)

> > So the dd is an IDirectDraw7 pointer created in C++ which I want to use in VB.

> .

.



Sat, 09 Aug 2003 01:33:43 GMT  
 VB C++ DirectX and COM
Hi,

I don't know why you didn't get the right objects.
Try to make each of the fields in the type declaration an "Object", then cast (with
"set") to the proper type.

What I did last time I faced such a problem, is create a wrapper COM class which
translates VB to the DLL...
It isn't fun, but it works great.
Try something like a COM class that has a method for each function (hard work but very
good solution), which translates the COM classes received and sent between VB and the
DLL.

Anyway, good luck!

Quote:

> Not quite.. the best I can do is ..

> From the Header file they gave me:

> #ifndef DXInterfaces_STRUCT
> #define DXInterfaces_STRUCT
> typedef struct tagDXInterfaces
> {
>         LPDIRECTDRAW7   lpDD7;
>         LPDIRECTDRAWSURFACE7 lpPrimarySurface;
>         LPDIRECTDRAWSURFACE7 lpBackBuffer;
> } DXInterfaces;
> #endif

> and

> PTENGINE_API bool PTA_GetDirectXInterfaces(DXInterfaces *lpDXI);

> You see, the DLL is not a COM DLL is an std something whatever that is so I have
> converted the above to:

> Private Type DXInterfaces
>     lpDD7 As DirectDraw7
>     lpPrimarySurface As DirectDrawSurface7
>     lpBackBuffer As DirectDrawSurface7

> End Type

> Private Declare Function PTA_GetDirectXInterfaces Lib "PTEngine.DLL" _
>     (lpDXI As DXInterfaces) As Long

> When I call the function:

>     Dim DirectX As DXInterfaces

>     InitDirectX = False

>     If PTA_GetDirectXInterfaces(DirectX) Then
>         Set dd = DirectX.lpDD7
>         Set m_srfPrimary = DirectX.lpPrimarySurface
>         Set m_srfBackBuffer = DirectX.lpBackBuffer

> and then when I try to use one of the pointers:

>     Dim SurfaceDescription As DDSURFACEDESC2

>     SurfaceDescription.lFlags = DDSD_CAPS
>     SurfaceDescription.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN

>     FindMediaDir FileName

>     Set m_Surface = dd.CreateSurfaceFromFile(FileName, SurfaceDescription)

> at this point it all goes pair shape and VB dies!!

> Do you see what is happening. I cannot declare the function and type in exactly
> the same way since all I have access to in VB is the VB DirectX library!

> Maybe if their DLL was a proper COM DLL is might work in VB but that obviously
> would mean the other guys would have to rewrite their API?

> The problem is that the other people are a third party in another part of the
> world employed by my client!

> -----Original Message-----
> Hi,

> Can you add a code snippet from both the VC++ and VB projects?



> > Thanks

> > The trouble is I have tried casting IDirectDraw7 (C++) to DirectDraw7 (VB) and
> as
> > soon as I try to use it (for example creating an off screen surface) VB crashes
> > with a program error!

> > Any ideas?

> > Nathy

> > -----Original Message-----
> > Hi,

> > You almost answered yourself...
> > in C++, the pointer points to an ISomething interface.
> > SO, it has to be the same with VB!
> > do something like:
> > <assume: Somthing is a COM class, ISomthing is the interface it implements>

> > Dim IObj as ISomthing
> > Dim Obj as Something

> > < let's say Obj was created and initialized >

> > Set IObj=Obj ' This queries the interface and "casts" Obj to IObj

> > retval =  myCPPFuncWhichRecievesAnISomething (IObj)



> > > I am working in VB and another team are working in C++. How can I use a pure
> COM
> > > pointer created within their DLL?

> > > The pointers are IDirectDraw7, and two IDirectDrawSurface7 pointers for the
> > > primary back buffer. As soon as I try and use them in VB (in place of
> > DirectDraw7
> > > and DirectDrawSurface7) the program crashes.

> > > There seems to be a type mismatch between the pointer provided by the C++
> > > interface of DirectDraw7 and the VB interface of DirectDraw7. I need to use
> the
> > > instance of DirectDraw7 from the DLL but I want to use it

> > > In the code extract below dd comes from the DLL. The program stops at ->.

> > >         Dim SurfaceDescription As DDSURFACEDESC2

> > >         SurfaceDescription.lFlags = DDSD_CAPS
> > >         SurfaceDescription.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN

> > >         FindMediaDir FileName

> > > ->      Set m_Surface = dd.CreateSurfaceFromFile(FileName, SurfaceDescription)

> > > So the dd is an IDirectDraw7 pointer created in C++ which I want to use in VB.

> > .

> .



Mon, 11 Aug 2003 21:15:04 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. VB C++ DirectX and COM

2. Using VB COM Objects in Visual C++ 5

3. C++ COM obj in VB

4. Using events in VB from a C++ COM object

5. COM/COM+ in VB or C++

6. error after closing c++ com used by vb

7. VB call C++ COM.

8. VB & C++ COM Components Talking

9. Call C++ Routines in VB COM

10. Querying COM Interfaces From VB Like You Can In C++

11. Calling a C++ COM object from a VB program

12. com clarification please c++/vb

 

 
Powered by phpBB® Forum Software