Solved

DLL

Posted on 2001-09-04
4
255 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now