Software Distributor
Free Copy Protection
Software Downloads
Help>How To Use DLL
Software Distributor
Copy Protection
Menu
Info
Company
Resources
How To Use Dynamic Link Libraries

Using ShareGuard Without DLLs

Attention ShareGuard Users: These are some new DLLs for simplifying coding. This is the brand new ShareGuard Lock DLL. It is included in V1.5. The Visual Basic dll is not included in V1.5 yet. It will be added to the ZIP file in the near future.

DOWNLOAD COMPLETE SAMPLE PROGRAM USING THE NEW LOCK DLL for C++ - this is new 2004/02/07.

NEW 2004/02/07: This DLL is designed to work in Visual Basic and Microsoft Access and FoxPro. This uses the BSTR string type and OLE2 Automation. This converts from ANSI double wide string automatically.

DOWNLOAD LOCK DLL for Visual Basic, MS Access and FoxPro - this is new.
function ShareGuardLock(lpProgramName: LPSTR): TBSTR; stdcall;

NEW 2004/02/07: This DLL is designed to work in C++ and Delphi. This uses the PCHAR type. This DLL does all of the work for you. Just pass in the ShareGuard Lock parameters and it will return a reason code. See the on-line for further details.

DOWNLOAD LOCK DLL for C++, Delphi - this is new.
function ShareGuardLock(lpProgramName: PChar): PChar; stdcall;

DOWNLOAD CRC CHECK DLL for C++ - this is an update - field size is 8 bytes with no garbage data at the end.
function CRC32FileCheck(lpFileName: PChar): PChar; stdcall;

Visual Basic and MS Access have a problem with DLLs. You cannot easily return a string within a function call. This is the way that OLE Automation (now called Automation) works. In order to get around this problem, I have created two other DLLs for you to try. These may be easier to work with.

NEW 2003/03/14: This DLL is designed to work in Visual Basic, Microsoft Access and FoxPro. This uses the BSTR string type and OLE2 Automation. This converts from ANSI double wide string automatically. Your return result is 16 byte widestring. The compare statement should work fine.

ZSSGCRCOLE2.dll Specifications:
Function Name: CRC32FileCheck
Parameter: FileName (this is a pointer to a BSTR string)
Result: String (Hex Value of FileName in 16 byte wide string format)

DOWNLOAD DLL for Visual Basic, MS Access and FoxPro

NEW 2003/03/14: This DLL is designed to work with C and C++ and contains a working sample of code.

ZSSGCRC32.dll Specifications:
Function Name: CRC32FileCheck
Parameter: FileName (this is a pointer to a LPSTR string)
Result: String (Hex Value of FileName)

DOWNLOAD DLL for C/C++ (older version)

NOTE: Please use the newer DLL instead of the one above. The direct link for the newer (2004/02/07) version is right here.

Delphi Pascal Users: Use ZSSGCRC.DLL already contained in the normal ShareGuard ZIP file download.

Here are some links to provide more information on how to use DLL for your programming language. This also includes a link to a web page on using Java Native Interface. You should be able to execute the ShareGuard Lock and call the dynamic link library using the JNI under Java. These articles should help you set the ShareGuard copy protection for VB and MS Access. For using ShareGuard copy protection for Java then please refer to the Java JNI documents. ShareGuard will work with Java. The Java must however, be intended to run on Windows 32 platforms.

How To Use JNI Java Native Interface for calling Windows 32 API
See these 3 great articles on how to implement the Java Native Interface. This will permit you to use ShareGuard for Java Copy Protection.

A Brief Introduction to Java Native Interface

This article details the process of calling native C/C++ code (in a DLL) from Java using JNI (Java Native Interface).

Calling from a .dll using Java and JNI - by Borland Developer Support Staff

Using ShareGuard With Java? Use JNI - see the above links and/or search the internet for Java JNI which is the Java Native Interface.

Windows API Calling MSDN
See the MSDN DLL Technical Reference for Accessing DLLs and the Windows API

See this great article on:
How To Write DLLs and Load Using Visual Basic

DLL for VB and MS Access

How To Use DLL for VB

DLL for VB and MS Access

VB Runtime Files For Download

NOTE: Your "Calling Program" is the VB runtime executable
e.g. vbrun60sp5.exe. ALSO: If you use the LOCK DLL then you can test the return code to shut down your application.

The same is true for any language that requires a runtime system. You will place the name of the executable runtime system in the "Calling Program" field.

Still Not Working?
Did you set the current directory to the application path before trying to load the DLL and run the EXE?

You can register the DLL but you should not have to as you are doing a dynamic load with the pathing set.

You register a DLL by going to the MS DOS command prompt into the appropriate directory and then typing
REGSVR32.EXE ZSSGCRCOLE2.DLL
REGSVR32.EXE ZSSGLOCKOLE2.DLL

or try this inside of your program:

shell("c:\windows\system\regsvr32.exe ZSSGCRCOLE2.DLL")
shell("c:\windows\system\regsvr32.exe ZSSGLOCKOLE2.DLL")

I think that this would require placing the DLL in the Windows System directory or you could path everything out.

Register a DLL from a Visual Basic application

The Windows API Viewer for Visual Basic

Using ShareGuard Without DLLs:
If you are having problems with the 2 DLLs then you can replace them both. Try using another CRC ActiveX control and then we will replace the ZSSGLOCKOLE2.DLL with real code so there will be no DLLs involved. This is a free ActiveX component called esCRC. It does the same thing - checks the CRC value of a file. Download ActiveX esCRC DLL

Reference Manual: Reference Manual

So install and use the ActiveX control and then include the ZSSGLOCKOLE2.DLL code. This is in Pascal so you must convert it to VB or MS Access or any other language. Remember you must replace the CRC checking here with your own ActiveX CRC checking.

ZSSGLOCKOLE2.DLL Code:

function ShareGuardLock(lpProgramName: LPSTR): TBSTR; stdcall;
type TCRC32FileCheck = function(FileName: PChar): PChar; stdcall;
var
Show: Integer;
ProgramEXE: String;
DLLInstance : THandle;
CRC32FileCheck : TCRC32FileCheck;
Value: ShortString;
sProductKey: String;
sKey: String;
sItem: String;
iDefVal: Integer;
iReasonCode: Integer;
sReturnValue: String;
iLengthProgramEXE: Integer;
I: Integer;
sFileName: String;
sReasonCode: String;
begin
sReasonCode := '0'; // Default to valid
sProductKey := '';
sFileName := 'ZSSGL.EXE';
// Use Delphi Version as it is already used in Lock Program DLLInstance := LoadLibrary('ZSSGCRC32.DLL');
if DLLInstance = 0 then
sReasonCode := '1';
@CRC32FileCheck := GetProcAddress(DLLInstance, 'CRC32FileCheck');
if @CRC32FileCheck <> nil then
Value := CRC32FileCheck(PChar(sFileName))
else
sReasonCode := '1';
FreeLibrary(DLLInstance);
if Value <> '3F87F19B' then // V2.0 Lock - use the Locksmith Tools CRC Check for CRC
sReasonCode := '2';
ProgramEXE := lpProgramName;
Show := 1;
if WinExec(PChar(ProgramEXE),Show) < 32 then
sReasonCode := '7';
// Check the Registry settings to ensure that user does not try anything fraudulent
Sleep(2000); // Wait for ShareGuard Lock to dump out registry settings - otherwise we might get last run settings
iLengthProgramEXE := Length(ProgramEXE);
for I := 1 to iLengthProgramEXE
do begin
if Copy(ProgramEXE,I,2) = '/K' then
sProductKey := Copy(ProgramEXE,I+2,16);
end;

sKey := 'Software\ShareGuard\' + sProductKey;
sItem := 'ReasonCode'; // Get the Reason Code dumped out by
ShareGuard
iDefVal := 8; // Set default to 8 - No registry entry found
iReasonCode := ZsRegistry1.LoadIntegerFromRegistry(sKey, sItem, iDefVal);

if (sReasonCode = '0') then // Do not assign the registry value if CRC check failed
sReasonCode := IntToStr(iReasonCode);
sReturnValue := sReasonCode;
SetLength(sReturnValue,Length(sReturnValue));

sReturnValue + (1 byte for termination char)

SetLength(sReturnValue,1);
Result := StringToOleStr(sReturnValue);
end;


Access DLL 'Bad DLL Calling Convention - Error 49'
Open the problem file using the /decompile startup option. Re-compile your MS Access project.

Runtime error 53: File Not Found
This problem can be corrected by one of the following methods:
(1) Ensure that the files are in the same directory as the executable file. If you are using a runtime system then files should be in this directory.
(2) Put the files in a directory path which is always loaded:
c:\winnt\system32
c:\windows\system
(3) Put the files in the environment path of your application

The files will be:
(a) ZSSGL.EXE
(b) ZSSGCRC.DLL
(c) ZSSGK.EXE (after the customer purchases)

Visual Basic Load DLL Example Problem and Solution

How To Integrate Visual Basic With DLL

Name Mangling
Watch out for Name Mangling. Name mangling occurs when the application creates its own entry point like _CRC32FileCheck@1 or use Alias "#1" and see if that works for your language. See your the documentation for your programming language to ensure that name mangling does not occur. You will be alerted to this type of problem when the DLL loads OK but the function call fails. You can read this article about Name Mangling of Visual Basic With Clarion to help you understand the problem.

You can read this article about why you MUST create a .DEF file:
Create a .DEF to avoid Name Mangling of Visual Basic

Summary: To avoid Name Mangling in VB then create a .DEF file that contains:

EXPORTS
CRC32FileCheck


...or try this one with ordinal number:

LIBRARY ZSSGCRC
DESCRIPTION DLL FOR ZSSGCRC DLL
EXPORTS
CRC32FileCheck    @1


Then in your source code you will define:

Declare Function CRC32FileCheck Lib "ZSSGCRC.DLL" (ByVal sFileName As String) As String

Another option to make it really easy to call from VB, you can create a type library. This requires that you create and compile an ODL (object description language) file. This file should include the following lines:

module MyModule {
[
helpstring("Returns the CRC Value of a given filename."),
entry("CRC32FileCheck")
]
short _stdcall CRC32FileCheck([in] string sFileName, [in] string sCRCValue);
};


Object Loads but will not execute function? Try one of these with the ALIAS directive:

Public Declare Function CRC32FileCheck Lib "ZSSGCRC.DLL" Alias "#1" (ByVal FileName As String) As String

Public Declare Function CRC32FileCheck Lib "C:\Program Files\ShareGuard\ZSSGCRC.DLL" Alias "#1" (ByVal FileName As String) As String

Public Declare Function CRC32FileCheck Lib "ZSSGCRC.DLL" Alias "_CRC32FileCheck@1" (ByVal FileName As String) As String

Public Declare Function CRC32FileCheck Lib "ZSSGCRC.DLL" Alias "CRC32FileCheck" (ByVal FileName As String) As String

Try upper case in the alias:
Public Declare Function CRC32FileCheck Lib "ZSSGCRC.DLL" Alias "CRC32FILECHECK" (ByVal FileName As String) As String

Standard Call
The ZSSGCRC.DLL is standard call STDCALL so ensure that your language interfaces with STDCALL (works with VB) and NOT with CDECL (C/C++).

Visual Basic DLLs are NOT the same as regular DLLs. This can be a very important point to remember. There are other languages out there that also create DLLs but are not proper DLLs. The DLL MUST be written in C/C++ or Pascal or Assembler to function properly. There may be exceptions to this but this is a general rule, so watch out. The ZSSGCRC.DLL is a properly written DLL and should perform across all platforms.

Definition of ZSSGCRC.DLL has a function called CRC32FileCheck with one input parameter (FileName) which is a shortstring and returns one output parameter which is a shortstring (CRC Value of the file).

Visual Basic and Calling Static DLLs:
Instead of this:
Public Declare Function CRC32FileCheck Lib "ZSSGCRC.DLL" (ByVal FileName As String) As String

Try this Static Loading with explicit pathing:

Enter the following Declare as one, single line:
Declare Function CRC32FileCheck Lib "c:\Program Files\ShareGuard\ZSSGCRC.dll" (ByVal filename As String) As String

Once the function is declared, you can use it in a form or event code. The following example uses a function from the DLL in the Cmd1 Click event code:

Sub Cmd1_Click ()
Dim filename As String * 64
Dim result As String * 8
filename = 'c:\Program Files\ShareGuard\ZSSGL.EXE'
result = CRC32FileCheck(filename)

if result = '00000000' then
'... the file was not found but the DLL executed
else
'... need some code here to shutdown with an
'... error message about Lock program missing.
if result = '12345678' then
'... the file was found and the
'... DLL executed and returned 12345678 as the CRC value
'... Check what the current CRC value should be for
'... ZSSGL.EXE (see ShareGuard Tools)
'... This means that ZSSGL.EXE is correct and has
'... not been modified by a cracker.
else
'... need some code here to shutdown with an error message
'... about Lock program being modified.
End Sub


Debugging for Visual Basic 6 and VB.NET Use VB6 or VB.NET to test for Windows OS exported functions and functions in any EXE or DLL loadable into Windows. Detect Windows Version Directly

Visual Basic Dynamic Loading of DLLs
This approach may be easier for some to use and to debug. You may have to add pathing and the prototype may not be required. Try both ways. Add some message boxes to show status inside of the function call.

This function will be called like:
sFileName = 'ZSSGL.EXE'
sCRC = MyCRC32FileCheck(sFileName)

Public Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long

Public Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long

Public Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long

Function MyCRC32FileCheck(ByVal sFileName As String) As String
' Function Prototype
Declare Function CRC32FileCheck Lib "ZSSGCRC.DLL" (ByVal sFileName As String) As String
Dim hMod As Long ' module handle
Dim lpfn As Long ' reg/unreg function address
Dim fSuccess As Boolean ' if things worked
Dim sCRCValue As String * 8 ' 8 byte hex CRC value
Dim sDLLName As String ' DLL Name
Dim sFileNameParm As String * 255 ' File Name to get CRC value

  sFileNameParm = sFileName
  sDLLName = 'ZSSGCRC.DLL'

' Load the CRC File Check function into memory
  hMod = LoadLibrary(sDLLName)

' Get the specified function's address
  lpfn = GetProcAddress(hMod, "CRC32FileCheck")

' If we got a function address...
  If lpfn Then
   sCRCValue = CRC32FileCheck(sFileNameParm)
  fSuccess = True
End If ' lpfn

' Free CRC check dll if we loaded it.
  If hMod Then
   Call FreeLibrary(hMod)

  If fSuccess Then
   MyCRC32FileCheck = sCRCValue
Else
   MyCRC32FileCheck = "99999999"
  End If

End Function


More details on using DLLs

More details on using DLLs

Microsoft Access: Using Library Databases and Dynamic Link Libraries

Sample Microsoft Access Code:

(1) Put ZSSGCRC.DLL in c:\windows\system or c:\winnt\system32 or in a library path that is known to MS Access.

(2) Declare the function in one of the following manners:
Using the ordinal number (which is 1 for CRC32FileCheck)

Declare Function CRC32FileCheck Lib "ZSSGCRC.DLL" Alias "#1" (ByVal sFileName As String) As String

OR

Declare Function CRC32FileCheck Lib "ZSSGCRC.DLL" Alias "CRC32FileCheck" (ByVal sFileName As String) As String

OR

Declare Function CRC32FileCheck Lib "C:\Windows\System\ZSSGCRC.dll" (ByVal sFileName As String) As String

Define and then call this test function:

Function DisplayCRC ()

Const sFileName = "C:\Program Files\ShareGuard\ZSSGL.EXE"

MsgBox "CRC Value = " & CRC32FileCheck(sFileName)

End Function


NOTE: Please ensure that your programming language supports dynamic loading of DLLs. If it does not then use static loading. Conversely, check to ensure that your language supports static loading, if not then use the dynamic loading approach. It may require some type of library definition to get it to work. All languages should support the last dynamic loading approach as it uses the Windows runtime system DLLs.
Get The FREE Software:
API and DLL Summary:

- Working directory path not set correctly

- Changing to a different directory

- Understanding how load a DLL

- Understanding how call an executable usinng Windows API

- Use Java Native Interface for copy protecction using ShareGuard

- See the MSDN Technical Reference

- Watch for Name Mangling

- Use Standard Call (STDCALL)

- Create a .DEF file in Visual Basic to avooid name mangling

- Create an .ODL file in MS Access to avoidd name mangling

Products and Services for Windows and IBM

Software Distributor

Copyright © 1995-2002 Zapper Software 510862 B.C. Ltd. All rights reserved. Privacy Policy
1 1 1 1 1 1