?
Solved

How to use DLL built by Delphi in VB?

Posted on 1999-01-26
6
Medium Priority
?
200 Views
Last Modified: 2010-04-06
I need to know how I can implement a DLL that has been compiled by Delphi 3.0 in a 32 bit VB application.

Can anyone tell me what datatypes are compatible (Delphi versus VB) or how I can modify a parameter's contents when passing it to a DLL function?

For example, when passing a string to a Delphi DLL function from VB: how do I do that?
Does Delphi support the Variant datatype or an equivalent, like VB does?
0
Comment
Question by:kulikuli
[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
  • 3
  • 2
6 Comments
 

Expert Comment

by:lorenkoss
ID: 1363401
I have done these many times.  Basically, I only pass PChars, integers, and pointers.  Be sure also to specify either CDECL or STDCALL in your delphi app so that it puts your variables in the right order.  In your VB app, you will prototype the function with the appropriate CDECL or STDCALL so that the variable go in the right order (pascal type is right to left (i think) and cdecl is left to right) based on the call stack.

I wouldn't play with the Variant type.  I never properly got it work.  As long as you know what type to expect, use pointers to objects.
0
 
LVL 5

Author Comment

by:kulikuli
ID: 1363402
lorenkoss, I have created a function in Delphi that is compiled in a DLL, which expects a PChar like you said.I have specified STDCALL in the DLL-file.
Unfotunately, it keeps crashing......

The dll's source code in Delphi:
----------------------------
library docver;

uses
  SysUtils,
  Classes;

function valid(fname : pchar) : integer; stdcall;
var fs : TFilestream;
    l  : longint;
begin
  fs := TFileStream.create(fname,fmOpenRead);
  fs.Seek(512,soFromBeginning);
  fs.Read(l,3);
  if l = 12690924 then
    valid := 1
  else
    valid := 0;
  fs.destroy;
end;

exports
 valid index 1;

begin
end.
-------------


My module in VB:
--------------Declarations section-----------------
Private Declare Function valid2 Lib "docver.dll" (ByVal strName as String) as Integer
-------------------------------------------------------------
Function Test()

Dim intReturn as Integer
intReturn = Valid2( "Hello" & vbNull ) 'call dll-function with null-terminated string

End Function

0
 
LVL 5

Author Comment

by:kulikuli
ID: 1363403
the VB declaration of course shouldn't be Valid2, but Valid. Sorry.
0
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.

 
LVL 5

Author Comment

by:kulikuli
ID: 1363404
The question is reopened, because I need a solution fast!
0
 

Expert Comment

by:lorenkoss
ID: 1363405
Make sure the valid function is being called by running the DLL from delphi and setting the run parameters in Delphi to point to the "host application" (the VB app).  I have a feeling the error may be happening in your filestream implementation.  Put a break point on the create line and step through..  It should get at least to that line.
0
 
LVL 15

Accepted Solution

by:
simonet earned 60 total points
ID: 1363406
In Delphi 3, use the ShortString type rather than pChar.

You should only use pchar if you're going to change it's value. Otherwise, if it's going to behave as a "const", make it a ShortString.

That said, your Delphi declaration should look like:

function valid(fname : ShortString) : integer; stdcall;
var
  fs : TFilestream;
  l  : longint;
begin
  fs := TFileStream.create(AnsiString(fname), fmOpenRead);
  ...
  ...
  ...

end;

See if that works. If not, drop me a line.

yours,

Alex

   



0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
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…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month13 days, 19 hours left to enroll

800 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