Solved

DLL - Newbie - String passing - C DLL

Posted on 1997-10-14
2
219 Views
Last Modified: 2010-04-04
Trying to use a third party dll... Here is the relevant information...  Supposed to pass it a DLL handle (I'm doing that ok...) and a pointer to a structure... (I've only shown part of the structure...)  The structure is simply a list of char's which I've converted as you can see...  The function is supposed to return dummy data in the structure, but the ShowMessage always shows 'Jason'...

Can anyone give me a pointer to getting this going?

type
  ptrAddrRec = ^AddressRecord;
  AddressRecord = Record
  Company:            Array[0..50] of Char;
  Address:            Array[0..75] of Char;
  Suite:              Array[0..16] of Char;
  City:               Array[0..28] of Char;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
AddrRec: AddressRecord;
begin
     AddrRec.Company := 'Jason';
     TestStructure(MP4Handle, @AddrRec);
     ShowMessage(String(AddrRec.Company));
end;
0
Comment
Question by:loucks
2 Comments
 

Accepted Solution

by:
AllenC earned 50 total points
ID: 1347590
I think you should give out more informations before anyone can help you. eg. the syntax of the TestStructure import procedure, and what does it do??

Is it like this??

procedrue TestStructure(Handle: THandle; var AddrRec: ptrAddrRec); external;

make sure you use the "var" in the import unit!

http://tcp.home.ml.org/
0
 

Author Comment

by:loucks
ID: 1347591
Well, Now it works!  I had a var in front of MP4Handle, took that out and it returns the data correctly...  I also changed it to an untyped pointer (which I have no idea if I should or not but who cares? it works!!!)  I included the c declarations to hopefully help  someone else who might be having problems.  Thanks so much!!!!!

procedure TestStructure(MP4Handle: LongInt; AddrStr: Pointer); stdcall; external 'MP432.dll' name 'TESTSTRUCTURE';

procedure TForm1.Button1Click(Sender: TObject);
var
AddrRec: AddressRecord;
begin
     AddrRec.Company := 'Jason';
     TestStructure(MP4Handle, @AddrRec);
     ShowMessage(String(AddrRec.Company));
end;

EXTERN MP4RETVAL MP4CALLCONV TestStructure (MP4RETVAL hDllHnd, AddressRecord *);

#define COMPANY_LEN             50
#define ADDRESS_LEN             75
#define SUITE_LEN               16

#pragma pack(1)
typedef struct tagAddressRecord
{
      char company[COMPANY_LEN+1];
      char address[ADDRESS_LEN+1];
      char suite[SUITE_LEN+1];
      char city[CITY_LEN+1];
      char stdCityAbbr[STD_CITY_ABBR_LEN+1];
      char state[STATE_LEN+1];
      char zip[ZIP_LEN+1];
      char plus4[ZIP4_LEN+1];
      char cart[CART_LEN+1];
}
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sending Gmail through Delphi 3 91
delphi exception 7 62
Multiple image collision 13 69
tvirtualstringtree freeze when load too manny images 10 52
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…
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

910 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

21 Experts available now in Live!

Get 1:1 Help Now