// load an external type library VOID FAR LoadExtTypeLib ( LPIMPORTLIB lpImpLib ) { ITypeLib FAR* lptlib; HRESULT res; BSTR bstrName; SETITEMCUR(lpImpLib->lpszFileName); // get * to ITypeLib interface CHECKRESULT(LoadTypeLib(ToW(lpImpLib->lpszFileName), &lptlib)); lpImpLib->lptlib = lptlib; // get name of this library CHECKRESULT(lptlib->GetDocumentation(-1, &bstrName, NULL, NULL, NULL)); // copy library name from the BSTR lpImpLib->lpszLibName = _fstrdup(ToA(bstrName)); SysFreeString(bstrName); // free the BSTR // get * to ITypeComp interface CHECKRESULT(lptlib->GetTypeComp(&(lpImpLib->lptcomp))); // get library attributes CHECKRESULT(lptlib->GetLibAttr(&(lpImpLib->lptlibattr))); }
TInputDialog::TInputDialog(PTWindowsObject AParent, LPSTR ATitle, LPSTR APrompt, LPSTR ABuffer, WORD ABufferSize, PTModule AModule) : TDialog(AParent, SD_INPUTDIALOG, AModule) { SetCaption(ATitle); Prompt = _fstrdup(APrompt ? APrompt : ""); Buffer = ABuffer; BufferSize = ABufferSize; }
void TestMoveF( void ) { char bufA[80] = "FoO baR gOoBeR bLaH"; char bufB[80]; char __far *bufPtr; char __far *newBuf; int status; bufPtr = _fstrcpy( bufB, "FoO baR" ); /* copy string */ VERIFY( bufPtr == bufB ); bufPtr = _fstrcat( bufB, " gOoBeR bLaH" ); /* append the rest */ VERIFY( bufPtr == bufB ); status = _fstrcmp( bufA, bufB ); /* check result */ VERIFY( status == 0 ); bufPtr = _fstrset( bufB, 0x00 ); /* zero out buffer */ VERIFY( bufPtr == bufB ); bufPtr = _fstrncpy( bufB, "ABCDEFGHIJ", 2 );/* copy two bytes */ VERIFY( bufPtr == bufB ); bufPtr = _fstrncat( bufB, "CDEFGHIJ", 3 ); /* copy three more */ VERIFY( bufPtr == bufB ); status = _fstrcmp( bufB, "ABCDE" ); /* ensure only five bytes */ VERIFY( status == 0 ); bufPtr = _fstrnset( bufB, 0x00, 10 ); /* blank string */ VERIFY( bufPtr == bufB ); status = _fstrcmp( bufB, "" ); /* verify empty */ VERIFY( status == 0 ); bufPtr = _fstrcpy( bufB, "abcdefghij" ); /* copy string */ VERIFY( bufPtr == bufB ); bufPtr = _fstrrev( bufB ); /* reverse it */ VERIFY( bufPtr == bufB ); status = _fstrcmp( bufB, "jihgfedcba" ); /* ensure reversed ok */ VERIFY( status == 0 ); newBuf = _fstrdup( bufA ); /* duplicate string */ status = _fstrcmp( bufA, newBuf ); VERIFY( status == 0 ); }
// find type defined in an external type library, // and add it to the type table if found. // lpszLibName is NULL if we're to look in ALL external type libraries. LPTYPE FAR FindExtType ( LPSTR lpszLibName, LPSTR lpszTypeName ) { LPIMPORTLIB lpImpLib; HRESULT res; ULONG lHashVal; ITypeInfo FAR* lptinfo; ITypeComp FAR* lptcomp; Assert (lpszTypeName != NULL); if (typlib.pImpLib != NULL) // if any imported type libraries { // point to first imported library entry lpImpLib = (LPIMPORTLIB)ListFirst(typlib.pImpLib); for (;;) { // if we're to look in all libraries, or this specific lib if (lpszLibName == NULL || !FCmpCaseIns(lpszLibName, lpImpLib->lpszLibName)) { SETITEMCUR(lpImpLib->lpszFileName); lHashVal = LHashValOfNameSysA(lpImpLib->lptlibattr->syskind, lpImpLib->lptlibattr->lcid, lpszTypeName); CHECKRESULT(lpImpLib->lptcomp->BindType(ToW(lpszTypeName), lHashVal, &lptinfo, &lptcomp)); if (lptinfo) // if found { // create a type table entry for this guy ListInsert(&typlib.pEntry, sizeof(TYPE)); // lpszTypeName will get freed by caller. // We must allocate new memory for it. typlib.pEntry->type.szName = _fstrdup(lpszTypeName); // CONSIDER: do a GetTypeAttr on this guy, // to ensure it's not a 'module' type typlib.pEntry->type.tdesc.vt = VT_USERDEFINED; // init this now in case of error, since // error cleanup code looks at this. typlib.pEntry->type.lptinfo = NULL; LPTYPEATTR ptypeattr; TENTRYKIND tentrykind; CHECKRESULT(lptinfo->GetTypeAttr(&ptypeattr)); // Get the interface typeinfo instead of // the Dispinteface version. if (ptypeattr->wTypeFlags & TYPEFLAG_FDUAL){ ITypeInfo FAR* lptinfo2; HREFTYPE hreftype; CHECKRESULT(lptinfo->GetRefTypeOfImplType((unsigned int)-1, &hreftype)); CHECKRESULT(lptinfo->GetRefTypeInfo(hreftype, &lptinfo2)); lptinfo->Release(); lptinfo->ReleaseTypeAttr(ptypeattr); lptinfo = lptinfo2; CHECKRESULT(lptinfo->GetTypeAttr(&ptypeattr)); } typlib.pEntry->type.lptinfo = lptinfo; // assume generic imported type tentrykind = (TENTRYKIND)(rgtentrykind[ptypeattr->typekind] | tIMPORTED); if (lpszLibName) { tentrykind = (TENTRYKIND)(tentrykind | tQUAL); } typlib.pEntry->type.tentrykind = tentrykind; typlib.pEntry->type.import.wTypeFlags = ptypeattr->wTypeFlags; lptinfo->ReleaseTypeAttr(ptypeattr); return &(typlib.pEntry->type); // all done } } // advance to next entry if not all done if (lpImpLib == (LPIMPORTLIB)ListLast(typlib.pImpLib)) break; // exit if all done lpImpLib = lpImpLib->pNext; } // WHILE } return (LPTYPE)NULL; //type not found }