Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

DLL

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

808 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