typelibraryconverterdlg.cpp

来自「这是VCF框架的代码」· C++ 代码 · 共 1,668 行 · 第 1/4 页

CPP
1,668
字号
	header += "#ifndef " + coClassName + "_H__\n";	header += "#define " + coClassName + "_H__\n";	header += "#include \"FoundationKit.h\"\n\n";	//check for ATL support	if ( TRUE == this->m_useATLForCoClassImpl ) {		header += "#include <atlbase.h>\n";		header += "#include <comdef.h>\n\n";			}	header += "\n\nusing namespace VCF;\n\n";	if ( TRUE == this->m_useTLBAsNamespace ) {		header += "namespace ";		header += pTypeLibHolder->m_typeLibName;		header += "  {\n\n";	}		coClassName += "_CLASSID";	header += "#define " + coClassName + " \t\t\"";	header += uuid + "\"\n";	if ( this->m_useCPPComments ) {				header += "//class " + pCoClass->m_className + "\n";		header += "//UUID: " + uuid + "\n";		header += "//ProgID: " + pCoClass->m_progID + "\n";	}	else {		header += "/**\n";		header += "*class " + pCoClass->m_className + "\n";		header += "*UUID: " + uuid + "\n";		header += "*ProgID: " + pCoClass->m_progID + "\n";		header += "*/\n";	}		if ( m_baseClass.GetLength() > 0 ) {		header += "class " + pCoClass->m_className + " : public " + m_baseClass;	}	else {		header += "class " + pCoClass->m_className;	}		CString s;	s += "Adding CoClass " + pCoClass->m_className + "...";	UpdateProgress( s );		int interfaceCount = pCoClass->m_implementedInterfaces.size();	if ( interfaceCount > 0 ) {		if ( m_baseClass.GetLength() > 0 ) {			header += ", ";		}		else {			header += " : ";		}	}	for ( int j=0;j<interfaceCount;j++) {		InterfaceHolder* pImplInterface = pCoClass->m_implementedInterfaces[j];		header += "public " + pImplInterface->m_interfaceName;		s = "";		s += "CoClass " + pCoClass->m_className + " implements " + pImplInterface->m_interfaceName;		UpdateProgress( s );		if ( j < (interfaceCount-1) ) {			header += ", ";		}	}	header += " {\n";	header += "public:\n";	header += "\tBEGIN_CLASSINFO( " + pCoClass->m_className + ", \"";	if ( TRUE == this->m_useTLBAsNamespace ) {		header += pTypeLibHolder->m_typeLibName + "::";	}	header += pCoClass->m_className + "\", \"VCF::Object\", ";	header += coClassName + " );\n";	header += "\tEND_CLASSINFO( " + pCoClass->m_className + " );\n\n";	header += "\t" + pCoClass->m_className + "();\n\n";	header += "\tvirtual ~" + pCoClass->m_className + "();\n\n";	for ( j=0;j<interfaceCount;j++) {		InterfaceHolder* pImplInterface = pCoClass->m_implementedInterfaces[j];		int methodCount = pImplInterface->m_methods.size();		for (int m=0;m<methodCount;m++) {			s = "";								s.Format( "Adding method %d of %d for interface %s", m, methodCount, (char*)pImplInterface->m_interfaceName );			UpdateProgress( s );						MethodHolder* pMethod = pImplInterface->m_methods[m];						header += GenerateMethodComments( pMethod, 1 );			header += "\tvirtual " + pMethod->m_returnType + " ";						CString methodName = "";			if ( pMethod->m_isPropertyGetter ) {				methodName += this->m_getMethodPrefix;			}			else if ( pMethod->m_isPropertySetter ) {				methodName += this->m_setMethodPrefix;			}			methodName += pMethod->m_methodName;			if ( this->m_useLowerCaseFuncNames ) {				CString lwr = methodName.GetAt(0);				lwr.MakeLower();				methodName.Delete(0,1);				methodName = lwr + methodName;			}					header += methodName;						std::vector<MethodArgumentHolder>::iterator argIter = pMethod->m_arguments.begin();			header += "(";			if ( pMethod->m_arguments.empty() ) {				header += " ";			}			else {					int argCount = pMethod->m_arguments.size();				while ( argIter != pMethod->m_arguments.end() ) {					argCount --;					MethodArgumentHolder& arg = *argIter;					header += " " + arg.m_argType + " " + arg.m_argName;						if ( argCount > 0 ) {						header += ",";					}					argIter ++;				}				header += " ";			}			header += ");";						//header += pMethod->m_declaration + ";";						CString siName = (TCHAR*)pImplInterface->m_superInterfaceName;			if ( siName == "IDispatch" ) {				header += "//[id(" + pMethod->m_methodID + ")]";			}			header += "\n\n";		}	}	//check for ATL support	if ( TRUE == this->m_useATLForCoClassImpl ) {		header += "//ATL COM Peer";		header += "\nprotected:\n";				header += "\tCComQIPtr<" + pCoClass->m_implementedInterfaces[j]->m_interfaceName +					",__uuidof(" + pCoClass->m_implementedInterfaces[j]->m_interfaceName + ")> m_comPtr;";	}	header += "};\n\n";	if ( TRUE == this->m_useTLBAsNamespace ) {		header += "}  //end of namespace ";		header += pTypeLibHolder->m_typeLibName;		header += "\n\n";	}		header += "#endif //";	header += s;		header += "\n\n";	return header;}CString TypeLibraryConverterDlg::GenerateCoClassImpl( CoClassHolder* pCoClass, TypeLibHolder* pTypeLibHolder ){	CString coClassImpl = "";		coClassImpl += "//";	coClassImpl += pCoClass->m_className;	coClassImpl += ".cpp\n\n";		if ( TRUE == m_singleUnitPerClass ) {		coClassImpl += "#include \"" + pTypeLibHolder->m_typeLibName + ".h\"\n";		coClassImpl += "#include \"" + pTypeLibHolder->m_typeLibName + "Interfaces.h\"\n";	}	else {				switch ( this->m_fileDistributionType ) {			case SINGLE_FILE_FOR_TLB : {				coClassImpl += "#include \"" + pTypeLibHolder->m_typeLibName + ".h\"\n";			}			break;			case SINGLE_FILE_FOR_IFACE_COCLASS : {				coClassImpl += "#include \"" + pTypeLibHolder->m_typeLibName + "Interfaces.h\"\n";			}			break;			case SINGLE_FILE_FOR_IFACE_TYPEDEF_COCLASS : {				coClassImpl += "#include \"" + pTypeLibHolder->m_typeLibName + "TypeDefs.h\"\n";				coClassImpl += "#include \"" + pTypeLibHolder->m_typeLibName + "Interfaces.h\"\n";			}			break;		}	}	coClassImpl += "#include \"" + pCoClass->m_className + ".h\"\n\n";		coClassImpl += "using namespace VCF;\n";	if ( TRUE == this->m_useTLBAsNamespace ) {		coClassImpl += "using namespace " + pTypeLibHolder->m_typeLibName + ";\n\n";	}		//check for ATL support	if ( TRUE == this->m_useATLForCoClassImpl ) {		coClassImpl += pCoClass->m_className + "::" + pCoClass->m_className + "()\n";		coClassImpl += "{\n";				coClassImpl += "\n}\n\n";		coClassImpl += pCoClass->m_className + "::~" + pCoClass->m_className + "()\n";		coClassImpl += "{\n\n}\n\n";	}	else {		coClassImpl += pCoClass->m_className + "::" + pCoClass->m_className + "()\n";		coClassImpl += "{\n\n}\n\n";		coClassImpl += pCoClass->m_className + "::~" + pCoClass->m_className + "()\n";		coClassImpl += "{\n\n}\n\n";	}		int interfaceCount = pCoClass->m_implementedInterfaces.size();	for ( int j=0;j<interfaceCount;j++) {		InterfaceHolder* pImplInterface = pCoClass->m_implementedInterfaces[j];		int methodCount = pImplInterface->m_methods.size();		for (int m=0;m<methodCount;m++) {			CString s = "";								s.Format( "Adding method %d of %d for interface %s", m, methodCount, (char*)pImplInterface->m_interfaceName );			UpdateProgress( s );						MethodHolder* pMethod = pImplInterface->m_methods[m];			coClassImpl += pMethod->m_returnType + " " + pCoClass->m_className + "::";			if ( pMethod->m_isPropertyGetter ) {				coClassImpl += this->m_getMethodPrefix;			}			else if ( pMethod->m_isPropertySetter ) {				coClassImpl += this->m_setMethodPrefix;			}			coClassImpl += pMethod->m_methodName;			std::vector<MethodArgumentHolder>::iterator argIter = pMethod->m_arguments.begin();			coClassImpl += "(";			if ( pMethod->m_arguments.empty() ) {				coClassImpl += " ";			}			else {					int argCount = pMethod->m_arguments.size();				while ( argIter != pMethod->m_arguments.end() ) {					argCount --;					MethodArgumentHolder& arg = *argIter;					coClassImpl += " " + arg.m_argType + " " + arg.m_argName;						if ( argCount > 0 ) {						coClassImpl += ",";					}					argIter ++;				}				coClassImpl += " ";			}			coClassImpl += ");";			//coClassImpl += pMethod->m_declaration + "\n{\n";			if ( pMethod->m_isPropertyGetter ) {				coClassImpl += "\t" + pMethod->m_returnType + " result;\n\n";				coClassImpl += "\treturn result;\n";			}			else {				coClassImpl += "\n";			}			coClassImpl += "}\n\n";		}	}	return coClassImpl;}CString TypeLibraryConverterDlg::GenerateInterface( InterfaceHolder* pInterface, TypeLibHolder* pTypeLibHolder ){	CString header = "";	CString uuid = (TCHAR*)pInterface->m_interfaceID;	uuid.Delete(0,1);	uuid.Delete(uuid.GetLength()-1,1);	if ( this->m_useCPPComments ) {				header += "//Interface " + pInterface->m_interfaceName + "\n";		header += "//UUID: " + uuid + "\n";	}	else {		header += "/**\n";		header += "*Interface " + pInterface->m_interfaceName + "\n";		header += "*UUID: " + uuid + "\n";		header += "*/\n";	}		header += "class " + pInterface->m_interfaceName + " : public VCF::Interface { \n";	header += "public:\n";	header += "\tvirtual ~" + pInterface->m_interfaceName + "(){};\n\n";	CString s;	s += "Adding Interface " + pInterface->m_interfaceName + "...";	UpdateProgress( s );	int methodCount = pInterface->m_methods.size();	for (int i=0;i<methodCount;i++) {		MethodHolder* pMethod = pInterface->m_methods[i];		s = "";		s.Format( "Adding method %d of %d for interface %s", i, methodCount, (char*)pInterface->m_interfaceName );		UpdateProgress( s );		header += GenerateMethodComments( pMethod, 1 );		header += "\tvirtual " + pMethod->m_returnType + " ";				CString methodName = "";		if ( pMethod->m_isPropertyGetter ) {			methodName += this->m_getMethodPrefix;		}		else if ( pMethod->m_isPropertySetter ) {			methodName += this->m_setMethodPrefix;		}		methodName += pMethod->m_methodName;		if ( this->m_useLowerCaseFuncNames ) {			CString lwr = methodName.GetAt(0);			lwr.MakeLower();			methodName.Delete(0,1);			methodName = lwr + methodName;		}				header += methodName;		std::vector<MethodArgumentHolder>::iterator argIter = pMethod->m_arguments.begin();		header += "(";		if ( pMethod->m_arguments.empty() ) {			header += " ";		}		else {				int argCount = pMethod->m_arguments.size();			while ( argIter != pMethod->m_arguments.end() ) {				argCount --;				MethodArgumentHolder& arg = *argIter;				header += " " + arg.m_argType + " " + arg.m_argName;					if ( argCount > 0 ) {					header += ",";				}				argIter ++;			}			header += " ";		}		header += ") = 0;";				CString siName = (TCHAR*)pInterface->m_superInterfaceName;		if ( siName == "IDispatch" ) {			header += "//[id(" + pMethod->m_methodID + ")]";		}		header += "\n\n";	}	header += "};\n\n\n";	return header;}void TypeLibraryConverterDlg::GenerateSingleUnitperClassImpl( TypeLibHolder* pTypeLibHolder ){	CString header;	header += "//";	header += pTypeLibHolder->m_typeLibName.copy();	header += ".h\n\n";	header += "#ifndef ";		CString s = (char*)pTypeLibHolder->m_typeLibName;	s.MakeUpper();	s = "_" + s + "_H__";	header += s.GetBuffer(0);	s.ReleaseBuffer();	header += "\n";	header += "#define ";	header += s.GetBuffer(0);	s.ReleaseBuffer();	header += "\n\n";	header += "#include \"FoundationKit.h\"\n\n";	header += "\n\nusing namespace VCF;\n\n";	if ( TRUE == this->m_useTLBAsNamespace ) {		header += "namespace ";		header += pTypeLibHolder->m_typeLibName;		header += "  {\n\n";	}	header += GenerateClassRegFunction( pTypeLibHolder );	header += "//Typelibrary typedefs\n\n";	header += pTypeLibHolder->m_typeDefs;	header += "\n//End of Typelibrary typedefs\n\n";		if ( TRUE == this->m_useTLBAsNamespace ) {		header += "}  //end of namespace ";		header += pTypeLibHolder->m_typeLibName;		header += "\n\n";	}		header += "#endif //";	header += s.GetBuffer(0);	s.ReleaseBuffer();		header += "\n\n";		CString headerFileName = "foo";	headerFileName = m_headerDir;	headerFileName += pTypeLibHolder->m_typeLibName;	headerFileName += ".h";	CStdioFile headerFile( headerFileName, CFile::modeCreate | CFile::modeWrite );	headerFile.WriteString( header.GetBuffer(0) );	header.ReleaseBuffer();	headerFile.Close();	m_fileList.push_back( headerFileName );		//do interfaces	header = "";	header += "//";	header += pTypeLibHolder->m_typeLibName.copy();	header += ".h\n\n";	header += "#ifndef ";		s = (char*)pTypeLibHolder->m_typeLibName;	s += "Interfaces";	s.MakeUpper();	s = "_" + s + "_H__";	header += s;	header += "\n";

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?