Solved

DLL

Posted on 2001-09-04
4
271 Views
Last Modified: 2010-04-06
How can I create dll's and then use them in VB?
0
Comment
Question by:trunin
[X]
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
  • 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses
Course of the Month5 days, 21 hours left to enroll

626 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