/***
* Typelib.cpp
*
*
*****************************************************************************/

#include "typbrows.h"


TCHAR * TypeKind[] = {
	TEXT("Enum"),             /* TKIND_ENUM */
	TEXT("Struct"),           /* TKIND_RECORD */
	TEXT("Module"),           /* TKIND_MODULE */
	TEXT("Interface"),        /* TKIND_INTERFACE */
	TEXT("Dispinterface"),    /* TKIND_DISPATCH */
	TEXT("Coclass"),          /* TKIND_COCLASS */
	TEXT("Typedef"),          /* TKIND_ALIAS */
	TEXT("Union"),            /* TKIND_UNION */
};



BOOL InitTypeLib (ITypeLib *pTypeLib, HWND hParent)
{
	unsigned int utypeinfoCount, i;
	BSTR bstrDoc, bstrHelpFile ;
	DWORD dwHelpContext ;
	TCHAR out [256] ;	
	TCHAR FAR* psz;



/*
STEP 4
Use the GetDocumentation( ) method to get the type library's 
(offset == -1) help file, help string, and help context.  The placement 
of these into the dialog box's controls has been done for you.  
*/


	wsprintf(out, TEXT("%ld"), dwHelpContext);
	SetDlgItemText (hParent,IDC_HELPCONTEXT, out);

	psz = (bstrDoc != NULL) ? bstrDoc : TEXT("<none>");
	SetDlgItemText (hParent,IDC_HELPSTRING, psz);
	if (bstrDoc) SysFreeString (bstrDoc) ;
		
	psz = (bstrHelpFile != NULL) ? bstrHelpFile : TEXT("<none>") ;
	SetDlgItemText (hParent, IDC_HELPFILE, psz) ;
	if (bstrHelpFile) SysFreeString (bstrHelpFile) ;


/*
STEP 5
Use the method ITypeLib:: GetTypeInfoCount( ) to get the number of type 
info objects in the type lib.  Then for each type info, use the method 
ITypeLib::GetDocumentation( ) to get its name.  The code that puts it in 
the list box has been done for you.
*/

	BSTR bstrName;
		
	for(i = 0; i < utypeinfoCount; i++)
	{

	  SendDlgItemMessage (hParent,IDC_TYPELIST,  LB_ADDSTRING, 0, (LPARAM)bstrName);
	  SysFreeString(bstrName);
	}               
	
	return TRUE;
}

/***
*void SetSelectedType
*Purpose:
*  When the user changes the selection of a type, this function updates the
*  dialog by changing the member list and the help for the type. It also sets
*  pTypeInfoCur to refer to the typeinfo.
*
*Entry:
*  dwIndex =
*
*Exit:
*  return value = None
*
***********************************************************************/
void SetSelectedType(LPTYPELIB pTypeLib, DWORD dwIndex, HWND hParent)
{
	BSTR bstrDoc, bstrHelpFile ;
	TCHAR FAR* psz;
	TCHAR szBuf[40];
	unsigned long dwHelpContext;
	TYPEKIND tkind;
    
/*
STEP 6
Use the method ITypeLib:: GetTypeInfoType( ) to get the type of the type 
info.  The code to find its name and put it into its edit control has already 
been written for you.   
*/

	SetDlgItemText(hParent, IDC_TYPEKIND, TypeKind[tkind]);


/*
STEP 6 Continued
Get the documentation string and help context from the type lib.
Place into their dialog items
*/

	wsprintf(szBuf, TEXT("%ld"), dwHelpContext);
	SetDlgItemText (hParent,IDC_HELPCONTEXT, szBuf);

	psz = (bstrDoc != NULL) ? bstrDoc : TEXT("<none>");
	SetDlgItemText (hParent,IDC_HELPSTRING, psz);
	
	psz = (bstrHelpFile != NULL) ? bstrHelpFile : TEXT("<none>") ;
	SetDlgItemText (hParent, IDC_HELPFILE, psz) ;
	
	SysFreeString(bstrDoc);
	SysFreeString(bstrHelpFile) ;
}
