Solved

DLL - Newbie - String passing - C DLL

Posted on 1997-10-14
2
223 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi: how to implement a User Shortcut mapper? 1 118
Base1 Encode/Decode 3 81
how to change, disabled button color FMX ? 1 40
Firemonkey BASS_Init into a thread 17 30
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

839 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