www.digitalmars.com         C & C++   DMDScript  

D - How to use IDispatch? (COM, ActiveX)

reply shizu <shizu_member pathlink.com> writes:
Hi. I have used D recently. It's so fan.

Well, I understood how to use COM in D from samples and the imported DirectX
Lib.
But I can't call the interfaces of a COM made with VB.
I meet the error "access violation".

The COM has DUAL Interface: IUnknown and IDispatch.
I think I have to use IDispatch with the COM.
But IUnknown was implemented in phobos only.
Tell me how to use the COM Please?

----sources I wrote.-----------
interface IClass1 : IUnknown {
extern(Windows):
HRESULT Calc(long x, long y, long* z); // z=x+y
} ;

int main() {
const GUID  CLSID_Class1 ={0xd1890a6d, 0xb213, 0x11d4,
[0xaf,0xc1,0x00,0xd0,0xb7,0xad,0x59,0xe8]}; /* CLSID */
const IID  IID_IClass1 = {0xd1890a6c, 0xb213, 0x11d4,
[0xaf,0xc1,0x00,0xd0,0xb7,0xad,0x59,0xe8]}; /* IID   */

BLAH BLAH

hr=CoInitialize(null);
hr=CoCreateInstance(&CLSID_Class1, null, CLSCTX_INPROC_SERVER,
&IID_IClass1,&pIClass1);

long x,y,z;
x=10; y=20; z=0;
pIClass1.Calc(a,b,&z); //at here, I meet the error. 
pIClass1.Release();
printf("x+y=%d\n", z);

BLAH BLAH
}
Aug 01 2003
parent "Walter" <walter digitalmars.com> writes:
Test to verify that CoCreateInstance() succeeded. -Walter

"shizu" <shizu_member pathlink.com> wrote in message
news:bgev23$1hsk$1 digitaldaemon.com...
 Hi. I have used D recently. It's so fan.

 Well, I understood how to use COM in D from samples and the imported
DirectX
 Lib.
 But I can't call the interfaces of a COM made with VB.
 I meet the error "access violation".

 The COM has DUAL Interface: IUnknown and IDispatch.
 I think I have to use IDispatch with the COM.
 But IUnknown was implemented in phobos only.
 Tell me how to use the COM Please?

 ----sources I wrote.-----------
 interface IClass1 : IUnknown {
 extern(Windows):
 HRESULT Calc(long x, long y, long* z); // z=x+y
 } ;

 int main() {
 const GUID  CLSID_Class1 ={0xd1890a6d, 0xb213, 0x11d4,
 [0xaf,0xc1,0x00,0xd0,0xb7,0xad,0x59,0xe8]}; /* CLSID */
 const IID  IID_IClass1 = {0xd1890a6c, 0xb213, 0x11d4,
 [0xaf,0xc1,0x00,0xd0,0xb7,0xad,0x59,0xe8]}; /* IID   */

 BLAH BLAH

 hr=CoInitialize(null);
 hr=CoCreateInstance(&CLSID_Class1, null, CLSCTX_INPROC_SERVER,
 &IID_IClass1,&pIClass1);

 long x,y,z;
 x=10; y=20; z=0;
 pIClass1.Calc(a,b,&z); //at here, I meet the error.
 pIClass1.Release();
 printf("x+y=%d\n", z);

 BLAH BLAH
 }
Aug 02 2003