Invoke a COM Method using InvokeMember

0

I am wrapping a COM API Ultimately I am trying to push more code down into Generics and the inheritance pattern in the api is not helping.

I have a generic of IBase, THere are ~80 classes that represent result sets. They are very similar, but they all inherit, or rather implement, the very basic IBase.

I have tried Extension methods and I dont think that is the way to go because the com is late bound and using Reflection.PropertyInfo seemed to be a dead end.

In the generic, we have the sub types, so I think I can use InvokeMember to call the methods/properties I need.

instnc = Activator.CreateComInstanceFrom(assy, tyepname)
retClass = Type.GetTypeFromProgID(progId)

My challenge is that I can not find the progId. I have searched the registry, I have made many guesses. "Excel.Application" works, so the basic approach is solid.

THe com dll in question is the Intuit Quickbooks api. I have tried many variations of

"QBFC13Lib.ICustomerRetList"

Am I on the right track? If so, where can I find the progId? Should I try a different tack?

from oleView, i see this for ICustomerRetList

[
  odl,
  uuid(DF331154-953C-4813-BAEC-F65DDBBFEB5B),
  helpstring("ICustomerTypeRetList Interface"),
  dual,
  oleautomation
]
interface ICustomerTypeRetList : IQBBase {
    [id(0x00000004), helpstring("method GetAt")]
    HRESULT GetAt(
                    long index, 
                    [out, retval] ICustomerTypeRet** retVal);
    [id(0x00000005), propget, helpstring("property Count")]
    HRESULT Count([out, retval] long* pVal);
    [id(0x00000006), helpstring("method Append")]
    HRESULT Append([out, retval] ICustomerTypeRet** retVal);
};

some more relevant lines from the typeLib

there are 36 interface declarations. I think we have established we are not after these... we want the things that implement these

interface ICustomerMsgRetList;    
interface ICustomerMod;

there are many lines that reference types such as the line below. These are simply objects that have customer as a property (Purchase order for instance). These are all found w/in Interface declarations. Its been a while since I did C++. Is IQBBase a pointer to a pointer? Thinking outloud, dont need an answer.

HRESULT CustomerRef([out, retval] IQBBaseRef** pVal);    

So yes, there may be a factory in there somewhere. I do believe these object (ICustomerRetList implementers) are instantiable, they clearly are instantiated. But the typelib is not giving up its secrets. Going back to the original question, I don't think there is an answer unless I can get the progId. The progIds may be purposefully obfuscated. Dont know. I know I guess at them and have not been successful. The intuit support forum is no longer active to the best of my knowledge.

vb.net
reflection
com
system.reflection
qbfc
asked on Stack Overflow Apr 20, 2016 by greg • edited Apr 29, 2016 by greg

1 Answer

1

You write "THe com dll in question is the Intuit Quickbooks api". I don't quite understand because that is not the name of a DLL. If you know the DLL, you can use the Microsoft utility OleView with the name of the DLL and it will display a de-compiled type library for you where you can look at all the types including ProgIds.

Personally, I would use regedit.exe and then go to HKEY_CLASSES_ROOT\TypeLib. From there I would use the search facility to search for "Intuit" or "quickbooks" to locate the typelibrary. If you find the typelibrary, then you can use OleView to browse it.

If you don't find it, you can look at your Quickbooks installation and then find its file path. After finding the path, go to HKEY_CLASSES_ROOT in RegEdit and search for the path. You should find some keys that have the path and if they are labeled LocalServer32 or InProcServer32, that will give you the CLSID and from the CLSID you can get the ProgID

answered on Stack Overflow Apr 21, 2016 by Joseph Willcoxson

User contributions licensed under CC BY-SA 3.0