How tos

How To install an OCX/DLL on the client’s PC when needed (at run-time)?

Author
Luc Van Dyck
Date
11/03/2003
Size
14,73 KB
Downloads
2854
Rating
43211
Popularity
Downloaded 5 times in the last two weeks
OCX or DLL routines are a great way to extend the functionality of Microsoft Business Solutions - Navision. The problem however is that you need to install the OCX/DLL on every client's PC that is going to use these routines. When eg. a sales person is not available in the office at the time you are installing the routines, and he starts the program (with your modification) the next day, he will see an error-message like this:

This message simply means that the required OCX/DLL was not found on the PC.

What you then need to do is to find out the name of the OCX/DLL that is being used (eg. "navision pad21.dll"), and copy this file FROM a PC where it has been installed to the PC where it is missing. It normally does not matter where you place the file, but it is good practice to put it in the Navision-directory (where the fin.exe/finsql.exe are located), or in the \Program Files\Common Files\Navision directory. Then you start the Command Prompt and use regsvr32.exe to register this OCX/DLL in the registry of Windows:

cd \Program files\Common Files\Navision
regsvr32 "navision pad21.dll"

When registration is successful, following message is displayed:

From now on, this OCX/DLL can be used in your Navision application.

Here is a method to do all this, using Navision C/AL code. This code will check first if the required OCX/DLL is installed on the PC. If not, the OCX/DLL (which we have imported in a BLOB-field in the database) is copied to that PC. Finally, regsvr32.exe is called to register this OCX/DLL.

Note: This example uses the Navision Pad DLL, that you can download on this site (available here).
The DLL is included in this download, for your convenience.

OnRun()
fctStartNavisionPad;

fctImportOCXDLL()
IF NOT(recOCXDLLSetup.GET) THEN
 recOCXDLLSetup.INSERT;

recOCXDLLSetup."Notepad DLL".IMPORT('navision pad21.dll',TRUE);
recOCXDLLSetup."Notepad Name" := 'navision pad21.dll';
recOCXDLLSetup."Notepad Registry Name" := 'Navpad20';
recOCXDLLSetup."Notepad Version" := '1.0';
recOCXDLLSetup.MODIFY;

fctIsOCXDLLInstalled(ptxtRegistryName : Text[100];ptxtVersion : Text[30]) : Boolean
lrecAutServers.SETRANGE(Name,ptxtRegistryName);
lrecAutServers.SETRANGE(Version,ptxtVersion);
EXIT(lrecAutServers.FIND('-'));

fctInstallOCXDLL()
recOCXDLLSetup.GET;
recOCXDLLSetup.CALCFIELDS("Notepad DLL");
IF NOT(recOCXDLLSetup."Notepad DLL".HASVALUE) THEN
 ERROR('Cannot find %1 in %2',recOCXDLLSetup."Notepad DLL",recOCXDLLSetup.TABLECAPTION);

ltxtFile := 'c:\program files\common files\navision\' + recOCXDLLSetup."Notepad Name";
recOCXDLLSetup."Notepad DLL".EXPORT(ltxtFile,FALSE);
lintReturn := SHELL('regsvr32.exe /s ' + '"' + ltxtFile + '"');
IF lintReturn <> 0 THEN
 ERROR('Unable to register %1',ltxtFile);

fctStartNavisionPad()
IF NOT(recOCXDLLSetup.GET) THEN
 fctImportOCXDLL;

IF NOT(fctIsOCXDLLInstalled(recOCXDLLSetup."Notepad Registry Name",
 recOCXDLLSetup."Notepad Version")) THEN
 fctInstallOCXDLL;

lcduStartNavisionPad.RUN;
Steps to install & test this How To
  • Copy the Navision Pad DLL-file to a directory eg. c:\delme
    Do not use regsvr32.exe to register this DLL yet. This will be done using Navision C/AL.
  • Import the howto5.fob into a MBS-Navision database
  • Run codeunit 50001 to start Navision Pad.
    You'll see an error message saying the Automation Server cannot be found.
  • Run codeunit 50000.
    You'll be asked to select the "navision pad21.dll"-file. This file will be imported in a BLOB-field. Browse to c:\delme and import "navision pad21.dll".
    Now Navision Pad is executed properly.
  • Copy the database to another PC, where the Navision Pad DLL hasn't been installed before.
  • Run codeunit 50000 on that PC.
    You'll see that Navision Pad is started, and that the DLL has been installed on that PC, automagically!
Download code

Screenshots