Menu

#194 CastTo/QueryInterface problem

open
nobody
win32 (141)
5
2005-03-04
2005-02-10
oleaw
No

In the COM API I am using, the following is provided: To
create a new patient object I have to cast the Patient
manager interface to the IDIContstructor interface.

PatMgr: IDIPatientMgr;
NewPat: IDIPatient;
...
PatMgr := DISession.GetManagerById(miPatient) as
IDIPatientMgr;
NewPat := (PatMgr as IDIConstructor).CreateNew as
IDIPatient;
//edit the patient...
//Save the changes
(NewPat as IDIEdit).Save;

In python I have written the following code.

miPerson = 26
try:
PersonMgr
except NameError:
PersonMgr = self.__dips_api.GetManagerById(miPerson)
else:
print "PersonMgr eksisterer"

NewPerson = CastTo(PersonMgr, 'IDIPersonMgr')

This casts PersonMgr to the right Interface.
My problem is that once I use the CastTo function all of
my other functions cease to work. Apparently all the
objects are wrapped in PyIUnkown, and python is no
longer able to find their appropriate type. This problem
will persist until delete the automatically generated
python COM code and restart IDLE.
All the interfaces I am using are IDispatch.

I have also tried to alternatively cast the interface with
PersonMgr.QueryObject(‘IDIConstructor’) and
Dispatch(PersonMgr , None, 'IDIContructor'),
but these functions are unable to find the interface.
Have also tried with makepy

Can anyone provide information on how to make CastTo
work, (can I unwrap the PyIUnknown wrapper?)

Ole A

Discussion

  • oleaw

    oleaw - 2005-02-10

    Logged In: YES
    user_id=1216110

    The line
    NewPerson = CastTo(PersonMgr, 'IDIPersonMgr')
    is
    NewPerson = CastTo(PersonMgr, 'IDIConstructor')
    and IDIContructor should be IDIConstructor

    This however is not the problem

    Ole A

     
  • oleaw

    oleaw - 2005-02-10
    • priority: 5 --> 7
     
  • oleaw

    oleaw - 2005-02-16

    Logged In: YES
    user_id=1216110

    The following code corrects the problem in a similar function,
    but it does not help with the CreateNew function:

    Patient = PatientMgr.GetPatientById
    ('aakajf+0000005001392')
    Person = Dispatch(Patient, 'IDIPerson', '{F6C0D843-
    DEC8-4C31-A766-12CBE59F3184}', UnicodeToString=0)
    Person = Person._oleobj_.QueryInterface
    (pythoncom.IID_IDispatch)
    Person = Dispatch(Person)
    print Person.LastName

     
  • oleaw

    oleaw - 2005-02-16
    • priority: 7 --> 8
     
  • oleaw

    oleaw - 2005-02-16

    Logged In: YES
    user_id=1216110

    The COM objects are written in Delphi

     
  • Mark Hammond

    Mark Hammond - 2005-02-17

    Logged In: YES
    user_id=14198

    You indicate you get back an IUnknown - can you call
    QueryInterface on this IUnknown for IDispatch?

     
  • Mark Hammond

    Mark Hammond - 2005-03-04
    • priority: 8 --> 5
     
  • Mark Hammond

    Mark Hammond - 2005-03-04

    Logged In: YES
    user_id=14198

    are you still having this problem?

     
  • oleaw

    oleaw - 2005-03-07

    Logged In: YES
    user_id=1216110

    I sill have the problem (but I have been on a two week
    vacation, so I haven't been working on it...). I seem to be able
    to get the right Interface, but get the following error when I try
    CreateNew():

    line 327, in CreateNew
    ret = self._oleobj_.InvokeTypes(1, LCID, 1, (13, 0), (),)
    com_error: (-2147352562, 'Ugyldig antall parametere.(Invalid
    number of parameters)', None, None)

     
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.