Method one would be used when the dll contains many functions but the application
only uses a few functions or there are a small number of times the application calls
the functions.
Method two would be used when the application relies heavily on the functions in the dll.
James
Code:
'============================================================================== 'DLL CODE: '------------------------------------------------------------------------------ #COMPILE DLL "MYWAY.DLL" #REGISTER NONE #DIM ALL FUNCTION _ One& ( _ BYVAL a& _ ) MsgBox "In Dll Function One"+ $CR + "a& = " + FORMAT$(a&) FUNCTION = a& * 10 END FUNCTION '------------------------------------------------------------------------------ FUNCTION _ Two& ( _ BYVAL a&,BYVAL b& _ ) MsgBox "In Dll Function Two"+ $CR + " a& = " + FORMAT$(a&) + $CR + " b& = " + FORMAT$(b&) FUNCTION = a& + b& END FUNCTION '------------------------------------------------------------------------------ FUNCTION _ Three$ ( _ StrIn$ _ ) FUNCTION = StrIn$ + " More Characters Added" + $CR + "Another Line" END FUNCTION '------------------------------------------------------------------------------ FUNCTION _ Test01& ALIAS "Test01" ( _ BYVAL Id& _ )EXPORT SELECT CASE Id& CASE 1 FUNCTION = CODEPTR(One&) CASE 2 FUNCTION = CODEPTR(Two&) CASE 3 FUNCTION = CODEPTR(Three$) END SELECT END FUNCTION '------------------------------------------------------------------------------ FUNCTION _ Test02& ALIAS "Test02" ( _ IdArray???() _ )EXPORT IF UBOUND(IdArray???) < 3 THEN FUNCTION = -1 EXIT FUNCTION END IF IdArray???(1) = CODEPTR(One&) IdArray???(2) = CODEPTR(Two&) IdArray???(3) = CODEPTR(Three&) END FUNCTION '============================================================================== '=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* 'Test Code 'Method #1 '=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* #COMPILE EXE #DIM ALL #REGISTER NONE '------------------------------------------------------------------------------ DECLARE _ FUNCTION _ Test LIB "MYWAY.DLL" ALIAS "Test01" ( _ BYVAL Id& _ ) AS DWORD '------------------------------------------------------------------------------ FUNCTION _ One& ( _ BYVAL a& _ ) LOCAL pAdd??? pAdd??? = Test(1) CALL DWORD pAdd USING One&(a&) !mov FUNCTION,eax END FUNCTION '------------------------------------------------------------------------------ FUNCTION _ Two& ( _ BYVAL a&, _ BYVAL b& _ ) LOCAL pAdd??? pAdd??? = Test(2) CALL DWORD pAdd USING Two&(a&,b&) !mov FUNCTION,eax END FUNCTION '------------------------------------------------------------------------------ FUNCTION _ Three$ ( _ StrIn$ _ ) LOCAL pAdd??? pAdd??? = Test(3) CALL DWORD pAdd USING Three$(StrIn$) !mov FUNCTION,eax END FUNCTION '------------------------------------------------------------------------------ FUNCTION _ PBMain ( _ ) AS LONG LOCAL RetVal& ,Temp$ RetVal& = One&(1) MsgBox "RetVal From One = " +FORMAT$(RetVal&) RetVal& = Two&(1,2) MsgBox "RetVal From Two = " + FORMAT$(RetVal&) Temp$ = Three$("some text") MsgBox Temp$ END FUNCTION '============================================================================== '=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* 'Test Code 'Method #2 '=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* #COMPILE EXE #DIM ALL #REGISTER NONE '------------------------------------------------------------------------------ DECLARE _ FUNCTION _ Test LIB "MYWAY.DLL" ALIAS "Test02" ( _ IdArray???() _ ) AS DWORD '------------------------------------------------------------------------------ GLOBAL IdArray???() '------------------------------------------------------------------------------ FUNCTION _ One& ( _ BYVAL a& _ ) CALL DWORD IdArray???(1) USING One&(a&) !mov FUNCTION,eax END FUNCTION '------------------------------------------------------------------------------ FUNCTION _ Two& ( _ BYVAL a&, _ BYVAL b& _ ) CALL DWORD IdArray???(2) USING Two&(a&,b&) !mov FUNCTION,eax END FUNCTION '------------------------------------------------------------------------------ FUNCTION _ Three$ ( _ StrIn$ _ ) CALL DWORD IdArray???(3) USING Three$(StrIn$) !mov FUNCTION,eax END FUNCTION '------------------------------------------------------------------------------ FUNCTION _ PBMain ( _ ) AS LONG LOCAL RetVal& ,Temp$ REDIM IdArray???(1:3) RetVal& = Test(IdArray()) RetVal& = One&(1) MsgBox "RetVal From One = " +FORMAT$(RetVal&) RetVal& = Two&(1,2) MsgBox "RetVal From Two = " + FORMAT$(RetVal&) Temp$ = Three$("some text") MsgBox Temp$ END FUNCTION
------------------
Leave a comment: