Solved

DLL

Posted on 2001-09-04
4
258 Views
Last Modified: 2010-04-06
How can I create dll's and then use them in VB?
0
Comment
Question by:trunin
  • 2
4 Comments
 
LVL 6

Expert Comment

by:DrDelphi
ID: 6454223
I have a simple example on my website:

http://www.drdelphi.com/delphi/right/tips/dll.htm

Good luck!!
0
 
LVL 1

Author Comment

by:trunin
ID: 6456091
And how can I use dll in VB? I need a simple example of using delphi dll in VB.
0
 
LVL 3

Expert Comment

by:rondi
ID: 6456149
In a module type something like:

Public Declare Function DelphiFunc Lib "MyDelphiDLL.dll" (ByVal TestInt As Long) As Long

or for a procedure:

Public Declare Sub DelphiProc Lib "MyDelphiDLL.dll" (ByVal TestStr As String)

Your Delphi DLL unit would look something like:


library MyDelphiDLL;

...
....

uses Windows;
...
...

function DelphiFunc(TestInt: integer): integer;
begin
  Result := TestInt * 2;
end;

procedure DelphiProc(TestStr: PChar);
begin
  MessageBox(Application.Handle,TestStr,'DelphiProc', MB_OK or MB_APPMODAL);
end;

...
...

exports DelphiFunc, DelphiProc;
0
 
LVL 6

Accepted Solution

by:
DrDelphi earned 25 total points
ID: 6456218
All true what rondi is saying.... once you've compiled the DLL, you use it like you would any other DLL in VB.

Delphi:
library thedate;

{ Important note about DLL memory management: ShareMem must be the
  first unit in your library's USES clause AND your project's (select
  View-Project Source) USES clause if your DLL exports any procedures or
  functions that pass strings as parameters or function results. This
  applies to all strings passed to and from your DLL--even those that
  are nested in records and classes. ShareMem is the interface unit to
  the DELPHIMM.DLL shared memory manager, which must be deployed along
  with your DLL. To avoid using DELPHIMM.DLL, pass string information
  using PChar or ShortString parameters. }

uses
  SysUtils,
  Classes;
   var mydate:pchar;
      function makeitaday(S:integer):pchar;stdcall;
     var thedate:array[0..20] of char;

      begin
     GetMem(mydate, 200);
     if s=1 then thedate:='Sunday ';
     if s=2 then thedate:='Monday ';
     if s=3 then thedate:='Tuesday ';
     if s=4 then thedate:='Wednesday ';
     if s= 5 then thedate:='Thursday ';
     if s = 6 then thedate:='Friday ';
     if s= 7 then thedate:='Saturday ';
     strpcopy(mydate,thedate);
     makeitaday:=mydate;
     end;
         
 exports makeitaday;
     begin
      end.
 


VB:

Private Declare Function makeitaday Lib "thedate.dll" (ByVal day As Integer) As String


Private Sub Command1_Click()
MsgBox makeitaday(2)
'this shows "Monday"
End Sub


Good luck!!
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question