Calling external DLL, How to declare and get values.

Posted on 2004-10-27
Last Modified: 2010-04-05

I have a DLL I wrote in PowerBasic where I have a function declared like this:

FUNCTION GetAllAdapters(Target2 AS ASCIIZ) EXPORT AS LONG (the long is a lpstr)

In my Delphi code I declared this function like this:

Function GETALLADAPTERS(Target2:lpstr): lpstr;  External 'newnic2.dll';

My question is how to set up the call with the string pointers and read the string from the pointer returned. I have tried a couple of different things, but I cannot narrow down the problem to my declare or the call.

Any help is appreciated.

Question by:KentDRuddick
    LVL 12

    Accepted Solution

    instead of lpstr in delphi use PChar .. delphi should automatically handle type conversions to/from string/PChar
    also set the calling convention to stdcall (as I guess is the only CC basic can use/output)

    Function GETALLADAPTERS(Target2: PChar): PChar;  stdcall; External 'newnic2.dll' name 'GetAllAdapters';

    export/import function names ARE case-sensitive
    Target2 should be preallocated on the caller like:

    var T2: string;
    SetLength(T2, 255);

    Author Comment


    Just what I needed.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Prepare to Pass the CompTIA A+ 900 Series Exam

    CompTIA aims to adapt its A+ Certification to reflect the most current knowledge and skills needed by today's IT professionals--and this year's 2016 exam is harder than ever. This certification is one of the most highly-respected and sought after in IT.

    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…
    Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    884 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now