is it possible to mix C and C++ ?
I have a Fs2002 gauge project written enterely in C
and I need to include Directsound capacity in it.
Can I call C++ function (from DX''s playsound sample ) by the C''s gauge project ? if yes how ? (CINTERFACE ?? )
I have already do some test but the compiler don''t stop to complaint abnout things so I wonder if this is the right direction.
I grabbed old DirectSound C code showing how to play wave
perhaps it will be more simple to go with it ?
Thanks for any input
Dan
DirectSound is based on COM so you should be able to interface with it using C. The classes in dsutil.h and dsutil.cpp appear simple enough to write in C or to extract the relevant pieces. If the C++ code is compiled using ''extern "C"'' you should be able to interface with it too, otherwise, you might have troubles with name mangling.
every COM interface can be used in C.
In C++, you could write something like
IDirectSound* blah;
blah->SomeFunction();
but in C, you would have to call something like
IDirectSound* blah;
blah->vtable->SomeFunction(&blah);
I know for a fact that in DX they use macros for C so that you can call something like this:
IDirectSound* blah;
blah->IDirectSound_SomeFunction();
Check the DirectX docs on using DX in C, I know for a fact that its there.
In C++, you could write something like
IDirectSound* blah;
blah->SomeFunction();
but in C, you would have to call something like
IDirectSound* blah;
blah->vtable->SomeFunction(&blah);
I know for a fact that in DX they use macros for C so that you can call something like this:
IDirectSound* blah;
blah->IDirectSound_SomeFunction();
Check the DirectX docs on using DX in C, I know for a fact that its there.
You can suppress name mangling in C++ by making your function prototypes like this:
You can then call C++ functions from C code.
extern "C" int f();
You can then call C++ functions from C code.
Here's the straight C implementation of the IUnknown interface - with out qualifying all the variables - take a look a dsound.h for the same kind of construct. DSound uses a different intializer function than CoInitialize etc.
[edited by - lessbread on April 20, 2002 5:04:46 PM]
#ifndef __IUnknown_INTERFACE_DEFINED__#define __IUnknown_INTERFACE_DEFINED__typedef IUnknown *LPUNKNOWN;extern const IID IID_IUnknown;typedef struct IUnknownVtbl { BEGIN_INTERFACE HRESULT (STDMETHODCALLTYPE *QueryInterface)(IUnknown *,REFIID,void * *); ULONG (STDMETHODCALLTYPE *AddRef)(IUnknown * ); ULONG (STDMETHODCALLTYPE *Release)(IUnknown *);END_INTERFACE} IUnknownVtbl;interface IUnknown { CONST_VTBL struct IUnknownVtbl *lpVtbl; };#ifdef COBJMACROS#define IUnknown_QueryInterface(T,r,O) (T)->lpVtbl->QueryInterface(T,r,O)#define IUnknown_AddRef(T) (T)->lpVtbl->AddRef(T)#define IUnknown_Release(T) (T)->lpVtbl->Release(T)#endifHRESULT _stdcall IUnknown_QueryInterface_Proxy(IUnknown * T,REFIID,void * *);void __RPC_STUB IUnknown_QueryInterface_Stub(IRpcStubBuffer *, IRpcChannelBuffer *, PRPC_MESSAGE, DWORD *);ULONG _stdcall IUnknown_AddRef_Proxy(IUnknown *);void __RPC_STUB IUnknown_AddRef_Stub(IRpcStubBuffer *,IRpcChannelBuffer *,PRPC_MESSAGE, DWORD *);ULONG _stdcall IUnknown_Release_Proxy(IUnknown * );void __RPC_STUB IUnknown_Release_Stub(IRpcStubBuffer *,IRpcChannelBuffer *,PRPC_MESSAGE,DWORD *);#endif
[edited by - lessbread on April 20, 2002 5:04:46 PM]
if you use a c++ compiler, then mixing the code i much easier since you can use the c++ code and c code without having to convert c++ stuff to the c equvilient meaning easier time using the majority of samples avaible. however, if you cannot do this, then you are stuck learning how to use c++ constructs in c, then converting the tutorials and samples yourself which is not too hard (because after all tutorials are designed to help you understand the concept not give you code to copy). you can look into asm dx tutorials since they need to access the dx objects like you do in c.
btw just an fyi, nearly all c code can be compiled using a c++ compiler without many changes if any.
btw just an fyi, nearly all c code can be compiled using a c++ compiler without many changes if any.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement