Solved

DLL - Newbie - String passing - C DLL

Posted on 1997-10-14
2
218 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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

763 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

11 Experts available now in Live!

Get 1:1 Help Now