Solved

DLL - Newbie - String passing - C DLL

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi XE2 application frozen on Windows 10 10 310
delphi prevent click fast 2 215
Help on project with Soap 10 53
select query - oracle 16 100
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
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…

776 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