Click to See Complete Forum and Search --> : Using Class Wrappers for COM DLL


Russ Lundberg
May 5th, 1999, 07:42 PM
I have created a project that uses raw COM to get IDispatch and then Interface pointers.

Now I want to create C++ Class Wrappers and make life much easier.

I have done the following to accomplish my goal:

In MSVC++ 6 select View|ClassWizard .... then select "Add Class" button then "From Type Library..". Enter path for COM DLL, and select all classes and then press OK. The CPP and H files are created with my class wrappers.

Then I use CoCreateInstance() as in like:

HRESULT hr = CoCreateInstance(CLSID_mySystem,NULL,CLSCTX_INPROC_SERVER |
CLSCTX_LOCAL_SERVER,IID_IADSystem,(void**)&pIMyObj);

Then I try to use a method like:
pIMyObj->Connect( vObject );

I receive an access denied whatever method I try to call. I have traced the problem through to the Invoke function where the exception is received.

If anyone has done this before I would greatly appreaciate some advice of where to proceed from here.

Thanks in advance!

Russ

Russ Lundberg
May 5th, 1999, 08:21 PM
One little detail I forgot to meantion. I am using the COM interface from a JNI DLL.

I have things working using the raw COM. I am just trying to get them working with the Class wrappers.

Russ

leolin@
May 5th, 1999, 08:23 PM
do you check the HRESULT hr = CoCreateInstance(CLSID_mySystem,NULL,CLSCTX_INPROC_SERVER |
CLSCTX_LOCAL_SERVER,IID_IADSystem,(void**)&pIMyObj)successfully?

Do you pass the correct parameters to that method?
pIMyObj->Connect( vObject );

In fact , sometime needn't export the type library, just include .h and define the interface,
you can get method through the direct way(
no use IDispath), most interface in system
are dual interface.

Russ Lundberg
May 6th, 1999, 11:18 AM
Thanks for the response.

To answer your questions Yes, and Yes. hr was 0(zero) and the correct parameters were being passed.

In the mean time, it looks Iike I got things working.

The solution was to take the pIMyObj returned from CoCreateInstance and do the following:

DIADClass TempClass(pIMyObj);

Then do:
TempClass.Connect(vObject);

It looks like it is now working!!

Thanks again for the response!

Russ