PDA

Click to See Complete Forum and Search --> : How to disallow other people to use my dll?


softwareguy74
Dec 26th, 2000, 06:53 PM
Thanks for the advice.. I was starting to think about doing something like that but just thought there might be a more "official" way of doing it.. I'm still curious though how other vendors are able to design their dll's as to not even allow you to reference them from your project...

thanks..

Dan

agent
Jan 1st, 2001, 04:11 PM
the dlls you add through the "References" window must be ActiveX dlls. If they aren't then you'll get an error. This does not, however, mean that you can't access the function in that dll. If you have a list of functions and parameters, you can access the function in a dll through the Declare statement.

Though vb can access this type of dll, it can't compile them. If you want to make a dll that is "Secure" from other programmers, use vc++ and don't release the function list.

Jan 4th, 2001, 01:52 AM
The best way is to have your DLL implement a private interface that your application also implements.

So, create a DLL project called ISecure, or something like that, and add on sub called 'AllowAccess'. Don't put any code in the sub (just a comment to stop VB thinking that it is a blank sub and deleting it).

Compile this DLL.

In your DLL, reference the DLL you just compiled, and at the top of each public class, add the line:

Implements ISecure


In your DLL, have a module level var called mlngAllowAccess or something like that, and add this code

Private Sub ISecure_AllowAccess()
mlngAllowAccess = True
End Sub


Then, use the mlngAllowAccess to decide if the DLL is going to perform the operation (raise an error or something similar)

Finally, in the app calling the DLL, you will need to add a reference to the ISecure DLL, and before using your DLL, cast it to an ISecure variable and call the AllowAccess sub

Dim lobjTest as MyDll.ClassName ' the DLL we have secured
Dim lobjISecure as ISecure ' the secure DLL

Set lobjTest = new MyDll.ClassName ' init you DLL
' init the secure interface, and
'set cast it to an ISecure object
Set lobjISecure = lobjTest

'Turn the security on
lobjISecure.AllowAccess

'Now you can do whatever you want to the actuall DLL
lobjTest.PerformFunction


Then, when you compile the application and distribute it, don't distribute the ISecure DLL. It isn't need because your app has a reference to uit in its Vtable, and that all it needs as there is no code in the DLL itself.

This method can be worked around if someone was to look at the export functions of the DLL, create a DLL that was identical to the ISecure DLL, and then load your DLL late-bound, but it's far more complex than just adding a reference. An improvement to this approach is to map every function in the DLL to a matching function in the ISecure interface, and just call the interface functions instead of directly calling the DLL functions.

The biggest advantage is that the ISecure_AllowAccess is PRIVATE in the DLL, not public, so it will never appearin the dropdown. Map all your functions in this way, and nothing will appear in the dropdown is someone was to add a reference.

- gaffa

samwise
Jan 4th, 2001, 11:07 AM
What about taking the entire classes that are part of the dll, and putting it into your VB program? That way, there will be no seperate dll. It has the unfortunate effect of making a larger VB exe, and upgrades on the dll would be impossible, though.

Samwise Galenorn
sam@galenorn.com