[Webinar] Streamline your web hosting managementRegister Today


Calling external DLL, How to declare and get values.

Posted on 2004-10-27
Medium Priority
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

Lee_Nover earned 500 total points
ID: 12430356
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

ID: 12432771

Just what I needed.


Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

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

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Is your organization moving toward a cloud and mobile-first environment? In this transition, your IT department will encounter many challenges, such as navigating how to: Deploy new applications and services to a growing team Accommodate employee…
Hi, this video explains a free download that you can incorporate into your Access databases, or use stand-alone for contact management. Contacts -- Names, Addresses, Phone Numbers, eMail Addresses, Websites, Lists, Projects, Notes, Attachments…

591 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