Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


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
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
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

Technology Partners: 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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

636 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