Solved

DLL

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

734 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