This is for a project i am writing and i found some awesome code that works beautiful, however since i have two forms i have either to create a dll with the function in it or to only use the one function bit not have anything touch the function otherwise... since i feel i will be useing this function again i decided to stuff the function in a dll file. i think that i did something wrong when i created the dll or when i tried to link to it... but it said that i didnt have a function entry point for the dll... the code for the forms and the dll are below... i dont know mayne i am just not doing something right...

'general decs.
Dim x As Long
Private Declare Function FileEncodeAndDecode Lib "TCP.DLL" (ByVal InputFile As String, ByVal OutputFile As String, ByVal PasswordKey As String) As String
Option Explicit

then the main code for the two forms... (general looks the same no need to waste space...

' my splash screen for decoding the files...
If x = 1 Then
    Dim InputFile As String
    Dim OutputFile As String
    Dim PasswordKey As String
    
    InputFile = App.Path & "\TCPData\Readme.txt" ' file to be decrypted
    OutputFile = App.Path & "\TCPData\Readme.txt" ' file being saved to.
    PasswordKey = "sudoyesper"
    Call FileEncodeAndDecode(InputFile, OutputFile, PasswordKey)
    'Call FileEncodeAndDecode(InputFile, OutputFile, PasswordKey)
ElseIf x = 2 Then
    InputFile = App.Path & "\TCPData\FTS Help.txt" ' file to be decrypted
    OutputFile = App.Path & "\TCPData\FTS Help.txt" ' file being saved to.
    PasswordKey = "sudoyesper"
    Call FileEncodeAndDecode(InputFile, OutputFile, PasswordKey)
    'Call FileEncodeAndDecode(InputFile, OutputFile, PasswordKey)
ElseIf x = 3 Then... 'more below looks the same...

' the code from the main form....
Private Sub Command11_Click()

Dim FTS As Object 'set variable for code
Set FTS = CreateObject("Scripting.FileSystemObject") 'setting var to work as an object

If FTS.FileExists(App.Path & "\HOME\logs\log.dll") Then 'sets the logfile
     Open App.Path & "\HOME\logs\log.dll" For Append As #3 'log file key is #253 and will be used here and on form 1
        Print #3, "FTS - DO NOT DELETE!"
        Print #3, "~=({|<|lkjhslkjsdg654dfg654d98fg7987dfs65g13er2g16d5fg498dg746100d8g76d5g16s7g8df7gd6f4g6sd54gsd687jh6jgh4j8y7j6g51hj6f5g4h6j576g8j46gf5j54hflsdhflkajshflkajdfhlkasjdfhlkjadfhlkjashfliuyflakjsbhf7q3869r8q76stf897534897690847ryjsfbhkjhdfkjfafgafhafiuyaoiuheflksajdhfliausydflahsdkjfha3eyli6y87df57a6s4f76as2saf5a87sghfkjle;lkqhfdg4d56g79d64g654s7*|`~!?/=~!?/=?@@%*?^}$]`?!&&~=({|(<`~%)}$><]*\$#~=({|~}/*(]*\$#<|*|`~!?/=~=({|~-{)|`?!&&?^}$]~-{)|)(\*+~!?/=~=({|~!?/=(<`~%~-{)|]*\$#)}$><~=({|(<`~%~}/*(>=!]!~!?/=@/[]%|~~`*^`?\^(&]>`(-)^>{{>/&(&]>`\$-^-@/%!%(-)^>}/~==&&/]_|~~`*{{>/&(-)^>}-<{\?@@%*|~~`*(&]>`\$-^-{{>/&\$-^-@/[]%@}^$/~!?/=<|*|`+%{=#[][^!@/[]%?@@%*(&]>`\$-^-@/[]%}-<{\>=!]![][^!@/[]%~=({|+%{=#(<`~%(&]>`?@@%*\$-^-]*\$#~}/*(`?!&&<!+(<?^}$]~=({|~}/*(}-<{\{{>/&?@@%*\$-^-{{>/&@/[]%+%{=#~}/*(<|*|`+%{=#@/[]%(<`~%~}/*(~!?/=}-<{\>=!]!\$-^-{{>/&~!?/=+%{=#~!?/=}-<{\<|*|`~=({|@}^$/~}/*(}-<{\`?!&&<|*|`~}/*(>=!]!\$-^-}-<{\[][^!@/[]%@}^$/`?!&&?^}$]@}^$/~=({|"
     Close #3 'closeing the file
  Else
     Open App.Path & "\HOME\logs\log.dll" For Output As #3 'tells the file what to do
        Print #3, "FTS - DO NOT DELETE!"
        Print #3, "~=({|<|lkjhslkjsdg654dfg654d98fg7987dfs65g13er2g16d5fg498dg746100d8g76d5g16s7g8df7gd6f4g6sd54gsd687jh6jgh4j8y7j6g51hj6f5g4h6j576g8j46gf5j54hflsdhflkajshflkajdfhlkasjdfhlkjadfhlkjashfliuyflakjsbhf7q3869r8q76stf897534897690847ryjsfbhkjhdfkjfafgafhafiuyaoiuheflksajdhfliausydflahsdkjfha3eyli6y87df57a6s4f76as2saf5a87sghfkjle;lkqhfdg4d56g79d64g654s7*|`~!?/=~!?/=?@@%*?^}$]`?!&&~=({|(<`~%)}$><]*\$#~=({|~}/*(]*\$#<|*|`~!?/=~=({|~-{)|`?!&&?^}$]~-{)|)(\*+~!?/=~=({|~!?/=(<`~%~-{)|]*\$#)}$><~=({|(<`~%~}/*(>=!]!~!?/=@/[]%|~~`*^`?\^(&]>`(-)^>{{>/&(&]>`\$-^-@/%!%(-)^>}/~==&&/]_|~~`*{{>/&(-)^>}-<{\?@@%*|~~`*(&]>`\$-^-{{>/&\$-^-@/[]%@}^$/~!?/=<|*|`+%{=#[][^!@/[]%?@@%*(&]>`\$-^-@/[]%}-<{\>=!]![][^!@/[]%~=({|+%{=#(<`~%(&]>`?@@%*\$-^-]*\$#~}/*(`?!&&<!+(<?^}$]~=({|~}/*(}-<{\{{>/&?@@%*\$-^-{{>/&@/[]%+%{=#~}/*(<|*|`+%{=#@/[]%(<`~%~}/*(~!?/=}-<{\>=!]!\$-^-{{>/&~!?/=+%{=#~!?/=}-<{\<|*|`~=({|@}^$/~}/*(}-<{\`?!&&<|*|`~}/*(>=!]!\$-^-}-<{\[][^!@/[]%@}^$/`?!&&?^}$]@}^$/~=({|"
     Close #3 'closeing the file
  End If
  
  'encoding the file so that it cant be read...
    Dim InputFile As String
    Dim OutputFile As String
    Dim PasswordKey As String
    
    InputFile = App.Path & "\HOME\logs\log.dll"
    OutputFile = App.Path & "\HOME\logs\log.dll"
    PasswordKey = PApashshnd0w1234
    
    Call FileEncodeAndDecode(InputFile, OutputFile, PasswordKey) 'FileEncodeAndDecode(InputFile, OutputFile, PasswordKey)
  'encoding is complete :)
  
'and the last bit to pass the files back through the dll to encode them so that people wont mess with them.

ProgressBar2.Value = u
u = u + 1
'reencrypting the files
    Dim InputFile As String
    Dim OutputFile As String
    Dim PasswordKey As String

If u = 1 Then
    Label41.Caption = "Securing Files... Please Wait"
    InputFile = App.Path & "\TCPData\Readme.txt" ' file to be decrypted
    OutputFile = App.Path & "\TCPData\Readme.txt" ' file being saved to.
    PasswordKey = "sudoyesper"
    Call FileEncodeAndDecode(InputFile, OutputFile, PasswordKey)
ElseIf u = 2 Then
    InputFile = App.Path & "\TCPData\FTS Help.txt" ' file to be decrypted
    OutputFile = App.Path & "\TCPData\FTS Help.txt" ' file being saved to.
    PasswordKey = "sudoyesper"
    Call FileEncodeAndDecode(InputFile, OutputFile, PasswordKey)
ElseIf u = 3 Then '.... looks the same... as the splash screen...

now the dll file code as i am losthere this was the first dll i have ever attempted to write, so this is where i probly went wrong...

'General decl.s and this is it...
Sub FileEncodeAndDecode(InputFile As String, OutputFile As String, PasswordKey As String)
    
    Dim temp As Single
    Dim Char As String * 1
    Dim XORMask As Single
    Dim temp1 As Integer
    Dim x As Long, y As Long, z As Long, Counter As Long
    
    
    Open InputFile For Binary As #1
    Open OutputFile For Binary As #2
    
    For x = 1 To Len(PasswordKey)
        temp = Asc(Mid$(PasswordKey, x, 1))
        For y = 1 To temp
            temp1 = Rnd
        Next y
        
        ' Re-seed to throw off prying eyes
        Randomize temp1
    Next x
        
    
    Counter = 0
    For z = 1 To FileLen(InputFile)
        
        'Generate random mask
        XORMask = Int(Rnd * 256)
        
        'Get the char & change it
        Get 1, , Char
        Char = Chr$((Asc(Char) Xor XORMask))
        Put 2, , Char
        
        Counter = Counter + 1
        If Counter > Len(PasswordKey) Then Counter = 1
        
'        ' Pull random numbers from the hat
        For x = 1 To (Asc(Mid$(PasswordKey, Counter, 1)) * 2)
            temp = Rnd
        Next x
    Next z


    Close #1
    Close #2
    
End Sub

like i said i am not sure what i did wrong...

any help would be appric.

J Fender

Error 453 means the DLL function specified was not found within the DLL. Try making the Sub Public.

Error 453 means the DLL function specified was not found within the DLL. Try making the Sub Public.

Which sub? The one in the dll or the ones in the forms? I will try it when I get the chance. Thank you for the advice... and will let you know if it worked.

Jesse Fender

Error 453 means the DLL function specified was not found within the DLL. Try making the Sub Public.

Ok i tried to switch the general declaration ofthe function to call the dll from private to public and got an error:

Compile Error:
Constants, Fixed-Length strings, Arrays, user-defined types, and Declare statements are not allowed as public members of object modules.

to be specific the error i am getting is:

"Run-time error '453':
Can't find DLL entry point FileEncodeAndDecode in TCP.DLL"

is this due to something in the dll its self or is it just me not seeing the problem?

Jesse

Ok i tried to switch the general declaration ofthe function to call the dll from private to public and got an error:

Compile Error:
Constants, Fixed-Length strings, Arrays, user-defined types, and Declare statements are not allowed as public members of object modules.

to be specific the error i am getting is:

"Run-time error '453':
Can't find DLL entry point FileEncodeAndDecode in TCP.DLL"

is this due to something in the dll its self or is it just me not seeing the problem?

Jesse

Nope didn't work - still get 453 error... i getting tired of having trouble with this- all i want it to do i pass the variables to the dll, and then have the dll do the work so that the code doesn't scramble the files beyond recognition. I have tried it in the declarations and in its own separate declaration... it didn;t work either.
This is the code with the 'Public Sub" added to the dll file and recompiled:

Public Sub FileEncodeAndDecode(InputFile As String, OutputFile As String, PasswordKey As String)
    
    Dim temp As Single
    Dim Char As String * 1
    Dim XORMask As Single
    Dim temp1 As Integer
    Dim x As Long, y As Long, z As Long, Counter As Long
    
    
    Open InputFile For Binary As #1
    Open OutputFile For Binary As #2
    
    For x = 1 To Len(PasswordKey)
        temp = Asc(Mid$(PasswordKey, x, 1))
        For y = 1 To temp
            temp1 = Rnd
        Next y
        
        ' Re-seed to throw off prying eyes
        Randomize temp1
    Next x
        
    
    Counter = 0
    For z = 1 To FileLen(InputFile)
        
        'Generate random mask
        XORMask = Int(Rnd * 256)
        
        'Get the char & change it
        Get 1, , Char
        Char = Chr$((Asc(Char) Xor XORMask))
        Put 2, , Char
        
        Counter = Counter + 1
        If Counter > Len(PasswordKey) Then Counter = 1
        
'        ' Pull random numbers from the hat
        For x = 1 To (Asc(Mid$(PasswordKey, Counter, 1)) * 2)
            temp = Rnd
        Next x
    Next z


    Close #1
    Close #2
    
End Sub

Hi,

the Syntax, you have used to Declare the DLL is not for UserCreated DLL's, It is for WINAPI's..
OK, First Create the DLL and Compile IT.
Then, Go to your Calling Project, open References, and Add the DLL, If the dll is not present in the list, add By Browsing to the folder...
And To Use the DLL,

Declare the Class :

Dim MyCls As New TCP

use the Procedure like this :
Call MyCls.FileEncodeAndDecode(....

Regards
Veena

commented: It worked and i nolonger want to go postal on my computer... +1

Hi,

the Syntax, you have used to Declare the DLL is not for UserCreated DLL's, It is for WINAPI's..
OK, First Create the DLL and Compile IT.
Then, Go to your Calling Project, open References, and Add the DLL, If the dll is not present in the list, add By Browsing to the folder...
And To Use the DLL,

Declare the Class :

Dim MyCls As New TCP

use the Procedure like this :
Call MyCls.FileEncodeAndDecode(....

Regards
Veena

It worked. Few Mods though,
1.

Dim MyCls As New Projectname.classname

2. when you add the DLL file as a name it shows up as the project name not the DLL... this was confusing at first... but I tested it and it seems to work...

Thanks!!!! Lots of HUGS!!!!! :D

Jesse Fender
AKA 'Chuck Jessup'

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.