ahelpyguy

Hi,

I need to write one small application. Where i need to find all methods and properties of a activex control.

like,
1) Take CLSID or Prog ID
2) Find all methods

How to start in vc++,

Does anyone have the sample code or any docs


Thanks




Re: Visual C++ General Finding all methods from CLSID

Aleksandr Tokarev

Whatch for Type Library, ITypeLib interface and ITypeInfo interface in MSDN and LoadTypeLib function.



Re: Visual C++ General Finding all methods from CLSID

Holger Grund

AFAIK, you have to go directly to the registry to get a LIBID for a given CLSID (it's HKCR\CLSID\<CLSID>\TypeLib). For everything else there should be APIs. LoadRegTypeLib and CLSIDFromProgId are the other one to look for.

If you can instantiate the control or already have an instance, it likely implements IProvideClassInfo(2) via which you can obtain the ITypeInfo interface.

-hg





Re: Visual C++ General Finding all methods from CLSID

ahelpyguy

So i need to start with LIBID, then i need to use API's. So does it will provide me the list of all methods and parameters with type info

Also how should i open that activex control to check or load into browser and use it

Thanks all for ur info.

ahelpyguy




Re: Visual C++ General Finding all methods from CLSID

Aleksandr Tokarev

Code Snippet

ITypeLibPtr tlb;
HRESULT hr = ::LoadTypeLib(L"C:\\Program Files\\Common Files\\microsoft shared\\OFFICE12\\MSO.DLL", &tlb);
for(UINT i = 0; i < tlb->GetTypeInfoCount(); i++)
{
ITypeInfoPtr ti = NULL;
tlb->GetTypeInfo(i, &ti);
TYPEATTR* attr = NULL;
ti->GetTypeAttr(&attr);

for(UINT j = 0; j<attr->cFuncs; j++)
{
FUNCDESC* desc = NULL;
ti->GetFuncDesc(j, &desc);
BSTR arr[100] = {0};
UINT len = 0;
ti->GetNames(desc->memid, &arr[0], 10, &len);
_bstr_t name, doc, help;
DWORD hepctx;

ti->GetDocumentation(desc->memid, name.GetAddress(), doc.GetAddress(), &hepctx, help.GetAddress());
wprintf(L"\nName: %s\n", (LPCWSTR)name);
wprintf(L"Documentaction: %s\n", (LPCWSTR)doc);
wprintf(L"Help context: 0x%x\n", hepctx);
wprintf(L"Help File: %s\n", (LPCWSTR)help);

if(len > 1)
{
wprintf(L"\t%s params:\n", arr[0]);
SysFreeString(arr[0]);
for(UINT k = 1; k<len; k++)
{
wprintf(L"\t\tparam: %s\n", arr[k]);
SysFreeString(arr[k]) ;
}
}
ti->ReleaseFuncDesc(desc);
}
ti->ReleaseTypeAttr(attr);





Re: Visual C++ General Finding all methods from CLSID

ahelpyguy

hi ,

This is really nice code. But when i compile it, it gives me lot of erros. Like,

Error 1 error C2228: left of '.GetAddress' must have class/struct/union d:\codes\source\axscan.cpp 31
Error 2 error C2228: left of '.GetAddress' must have class/struct/union d:\codes\source\axscan.cpp 31
Error 3 error C2228: left of '.GetAddress' must have class/struct/union d:\codes\source\axscan.cpp 31


etc, and many more. I narrow down to some less errors. but still facing a problem as i am new to vs.net

Can u help me in Do u have the working code ....

I coded to search CLSID and Progid from registry. So only finding all methods , properties and there parameters is remained

Thanks





Re: Visual C++ General Finding all methods from CLSID

Aleksandr Tokarev

Yes, this code works in VS 2005.

But it can work event in VS6.

Some includes are missing.

#include <comdef.h>





Re: Visual C++ General Finding all methods from CLSID

ahelpyguy

Hi ,

The code is working. But i need to find out the type of parameters of function as well.

function xyz
{
param abc as string

}

The code only gives the method names and parameter. Is there any way we can find out the type of parameter as well

Like if the param is string or interger or other


But this code helped me a lot.

Thanks
ahelyguy





Re: Visual C++ General Finding all methods from CLSID

Aleksandr Tokarev

Code Snippet
for(UINT k = 1; k<len; k++)
{
wprintf(L"\t\tparam: %s (%d)\n", arr[k], desc->lprgelemdescParam[k-1].tdesc.vt);// Look for VARTYPE description
SysFreeString(arr[k]) ;
}





Re: Visual C++ General Finding all methods from CLSID

ahelpyguy

Hi Alek,

Thanks again for ur help. My second module is not far behind from release. I used above code. but still i am unable to get param type like string or interger

lets say i have one function ,

Sub setCurrentHighlight (
ByVal a As Long ,
ByVal b As Long ,
ByVal c As Single ,
ByVal d As String
)


The output should be like d is string , c is single and a is long...


And ur code shows me like this,

Name: setCurrentHighlight
Documentaction: method setCurrentHighlight
Help context: 0x0
Help File: (null)
setCurrentHighlight params:
param: a (3)
param: b (3)
param: c (3)
param: d (3)

Is there any way to see if it is string or what




Re: Visual C++ General Finding all methods from CLSID

Aleksandr Tokarev

Everything works in my test space.

Function: InsertNodeBefore
Documentaction: (null)
Help context: 0x47c87
Help File: C:\Program Files\Common Files\microsoft shared\OFFICE12\
vbaof11.chm
InsertNodeBefore params:
param: Name (8) // VT_BSTR
param: NamespaceURI (8) // VT_BSTR
param: NodeType (29) //VT_USERDEFINED
param: NodeValue (8) // VT_BSTR
param: NextSibling (26) // VT_PTR

HRESULT InsertNodeBefore (
_bstr_t Name,
_bstr_t NamespaceURI,
enum MsoCustomXMLNodeType NodeType,
_bstr_t NodeValue,
struct CustomXMLNode * NextSibling );

So, show me your code of type dumping. May be there a bug.

Or you can send me your test set where it doesn't work. To my e-mail in profile.

Or research structures in code yourself.





Re: Visual C++ General Finding all methods from CLSID

ahelpyguy

I used same code to test here.

#include <iostream>
#include <sstream>
#include <tchar.h>
#include <windows.h>
#include <string.h>
#include <comdef.h>


int _tmain(int argc, _TCHAR* argv[])
{
ITypeLibPtr tlb;
HRESULT hr = ::LoadTypeLib(L"C:\\Program Files\\Adobe\\Acrobat 7.0\\ActiveX\\AcroPDF.dll", &tlb);
for(UINT i = 0; i < tlb->GetTypeInfoCount(); i++)
{
ITypeInfoPtr ti = NULL;
tlb->GetTypeInfo(i, &ti);
TYPEATTR* attr = NULL;
ti->GetTypeAttr(&attr);

for(UINT j = 0; j<attr->cFuncs; j++)
{
FUNCDESC* desc = NULL;
ti->GetFuncDesc(j, &desc);

BSTR arr[100] = {0};
UINT len = 0;
ti->GetNames(desc->memid, &arr[0], 10, &len);
_bstr_t name, doc, help;
DWORD hepctx;

ti->GetDocumentation(desc->memid, name.GetAddress(), doc.GetAddress(), &hepctx, help.GetAddress());
wprintf(L"\nName: %s\n", (LPCWSTR)name);
wprintf(L"Documentaction: %s\n", (LPCWSTR)doc);
wprintf(L"Help context: 0x%x\n", hepctx);
wprintf(L"Help File: %s\n", (LPCWSTR)help);

if(len > 1)
{
wprintf(L"\t%s params:\n", arr[0]);
SysFreeString(arr[0]);
for(UINT k = 1; k<len; k++)
{
wprintf(L"\t\tparam: %s (%d)\n", arr[k], desc->lprgelemdescParam[k-1].tdesc.vt);// Look for VARTYPE description
SysFreeString(arr[k]) ;
}
}
ti->ReleaseFuncDesc(desc);
}
ti->ReleaseTypeAttr(attr);
}
}


but it didn't work. May be i need to search more on this.
Let me know if something is wrong in the code.





Re: Visual C++ General Finding all methods from CLSID

Aleksandr Tokarev

Send your COM - control project by e-mail.