//TH-Header //***************************************************************************************** // Copyright (c) 2001 Michael Kurz // All rights reserved. // If you want to use this source in your applications conatct: // // $FileName : cDllImportToVDF.pkg // $ProjectName : Shared Classes // $Author : Michael Kurz // $Created : 29.06.2001 11:21 // // Contents: // Converts a String, which contains a DLL import statement from C to VDF style. // //***************************************************************************************** //TH-RevisionStart //TH-RevisionEnd //SYNC_API long SyncDeleteDB (const Char* pName, int nCardNum); Use VdfBase.pkg Use cLineParser.pkg Use cSrcLineParser.pkg Class cDllImportToVDF Is a Message //Insert your Properties here. Procedure Construct_Object Forward Send Construct_Object Object oSrcLineParser Is a cSrcLineParser End_Object Object oLineParser Is a cLineParser Set psSepCharacter To "," // Arguments in Parameterlist are seperated by "," Set piSkipEmptyParts To True // Blanks shouldnt make a difference! End_Object End_Procedure //Finish object construction Procedure End_Construct_Object Forward Send End_Construct_Object End_Procedure // External_Function CMRegisterControl "CMRegisterControl" CMAX_DLL_NAME Dword dwVersion Returns Integer Function ConvertCode String sLine Returns String Integer hoID isPointer iC String sNew sFctName sFctRetType sFctParas sPara sType sComment Move (oSrcLineParser(Self)) To hoID Move (Replace(";",sLine,"")) To sLine Send ParseLine To hoID sLine // Parts for the Declaration. Move (Value(hoID,2)) To sFctName // Name of the function Move (Value(hoID,1)) To sFctRetType // Returntype of the call Move (ConvertCToDFType(sFctRetType)) To sFctRetType // convert it to a VDF type. Move (Value(hoID,3)) To sFctParas // ParameterList of the function Move (psComment(hoID)) To sComment // Store the comment, if ther was one. Move (Replace("(",sFctParas,"")) To sFctParas // We dont need the Parenthesis. Move (Replace(")",sFctParas,"")) To sFctParas // ... Move (Replace("const ",sFctParas,"")) To sFctParas // also const keyword we dont need Send ParseLine To (oLineParser(Self)) sFctParas // Parses the parameters of the function Move "" To sFctParas // Init the New Parameterlist with "" For iC From 0 To (Item_Count(oLineParser(Self)-1)) Get value Of (oLineParser(Self)) Item iC To sPara // Is a Pair of Parameter and ParameterName. If "*" In sPara Begin Move (Replaces("*",sPara,"")) To sPara // We dont need the pointer signs. Move 1 To isPointer End Else If "&" In sPara Begin Move (Replaces("&",sPara,"")) To sPara // We dont need the pointer signs. Move 1 To isPointer End Else Move 0 To isPointer Send ParseLine To hoID sPara // Now use the oSrcLineParser to seperate the Type from the ParameterName Move (Value(hoID,0)) To sType // Should be the Type of the Parameter Move (Value(hoID,1)) To sPara // Should be the Name of the Parameter If sPara Eq "" Begin // In C declarations you dont need to add the name of the parameter only the type -> so build one. Append sPara (Lowercase(Left(sType,1))) "Para" iC // tParaX End If isPointer Move "Pointer" To sType // IF its a poionter, well then simplay use the Pointer :-) Else Move (ConvertCToDFType(sType)) To sType // Convert the type if its not a pointer If sType Ne "" Begin // Only use if both Parameters are filled If (Uppercase(Left(sType,4))) Eq "CHAR" Move "Word" To sType // dont know which better type! If sFctParas Ne "" Append sFctParas " " // Add a Blank if not the 1st Parameter Append sFctParas sType " " sPara // Add the new Parameter with name and type. End End Append sNew "External_Function " sFctName " " (Character(34)) sFctName (Character(34)) " YOURDLL.DLL " sFctParas Append sNew " returns " sFctRettype Function_Return sNew End_Function End_Class Global_Variable Integer ghoDllImportToVDF Object oDllImportToVDF Is a cDllImportToVDF Move Self To ghoDllImportToVDF End_Object // Will convert a C Dll call to VDF. // (will only work with one line definitions.) Function gfsConvertCDllCallToVDF Global String sLine Returns String Function_Return (ConvertCode(ghoDllImportToVDF,sLine)) End_Function