Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.


Using a Delphi 5 dll from

Using a Delphi 5 dll from

Does anyone have any experience using a Delphi 5 DLL from

I have been given a Delphi 5 dll to use for a certain processing.  However, I am having trouble figuring out how to connect to it.  Seems there are type problems.  The Delphi types I need to use are as follows: Byte, Boolean, Pchar, Integer, Double and array of bytes.

Any help would be greatly appreciated.

Thank you!

Pat B

RE: Using a Delphi 5 dll from

I've used Delphi 5 DLL's in VB 6, which should be similar to using them in VB .NET. I had quite a few troubles with type problems when I was first using the DLL in VB 6. It turns out that all my type problems were due to passing strings from my VB 6 program to my Delphi 5 DLL. According to Delphi's documentation, passing strings to a Delphi DLL can cause quite a few problems:


Important note about DLL memory management: ShareMem must be the first unit in your library's USES clause AND your project's (select Project-View 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 BORLNDMM.DLL shared memory manager, which must be deployed along with your DLL. To avoid using BORLNDMM.DLL, pass string information using PChar or ShortString parameters.

At first I followed the advice of the Delphi documentation and programmed my Delphi 5 DLL so that it used the ShareMem library and the BORLNDMM.DLL, along with PChar and ShortString parameters. As it turns out, this won't work when you are calling a Delphi DLL from VB. I had to completely disregard the Delphi advice and reprogram my Delphi 5 DLL, removing the reference to ShareMem and the BORLNDMM.DLL, and take out all PChar parameters and replace them with String parameters. I don't know if you will have the luxury of being able to do this.

You shouldn't have any type problems with the Delphi types Byte, Integer, and Double, because they are all the same size as the equivalent VB .NET data types. A Delphi 5 boolean type is 1 byte, whereas VB .NET will assign up to 2 bytes for a boolean value, though the VB .NET documentation claims that the amount of space allocated for a Boolean value could be platform dependent and use less than 2 bytes. My guess is that the PChar data type is what is causing you problems. There shouldn't be any problems with passing an array of bytes, but I can't say for certain as I don't have any direct experience with passing arrays to a Delphi 5 DLL.

To make a long story short, the problems I experienced with calling a Delphi 5 DLL from VB were problems that I could only really fix from the Delphi 5 side of things, though someone else may be able to prove me wrong.


RE: Using a Delphi 5 dll from


Thanks for your thoughts.  It is indeed the Pchars that are giving me trouble.  VB.Net does not seem to give you a way to get the pointer to a variable.  There was a way in VB6 using VarPtr(), but that has been removed in  :-(

The search goes on...

Pat B

RE: Using a Delphi 5 dll from

This website may have some advice on how to convert strings to pointers in VB .NET:

More specifically, it has a short section on strings and pointers:


Writing and reading strings
In this example we will write a managed string to heap and then read it back.

Dim str as String = "hello world"
Dim ptr As IntPtr = Marshal.StringToHGlobalAuto(str)
Dim mystring As String = Marshal.PtrToStringAuto(ptr)

Here, we used StringToHGlobalAuto() method of marshal class that copies the contents of a managed string into unmanaged memory. We collect the memory address in IntPtr structure. To read the string back we used PtrToStringAuto() method of Marshal class that returns a string at specified memory location.

I haven't tried it myself so I can't say for certain that it will work with PChar's, but it looks promising.


RE: Using a Delphi 5 dll from


It does look promising.  I will be giving it or something similar to it soon.

Thanks for the help.

Pat B

RE: Using a Delphi 5 dll from


You're comments did indeed help me get it working.

Thanks a lot!

Pat B

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close