Solved

DLL - Newbie - String passing - C DLL

Posted on 1997-10-14
2
225 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
[X]
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
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

Independent Software Vendors: 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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

707 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