Solved

DLL and Strings parameters

Posted on 1998-12-22
6
266 Views
Last Modified: 2010-04-04
Hi all,

How can I send String parameters to DLL?
I'm observing to put ShareMem in USES clauses in both DLL and Caller and making Delphi3MM.dll available.
What should be wrong?
What about to include ShareMem in USES clause if the program I need to use the .dll(created by Delphi) isn't one Delphi program?

I hope to be clear.
Regards
Paulo
0
Comment
Question by:sergio_2001
[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
6 Comments
 
LVL 3

Expert Comment

by:KE
ID: 1352614
How long are the strings you want to send, and would you need other datatypes to go along ?

0
 
LVL 3

Accepted Solution

by:
williams2 earned 50 total points
ID: 1352615
You actually don't need to use the ShareMem feature if you follow the rules of handling different memory managers.

This can be done by declaring Char pointers in a special way:

The rules is:
1) The client will have to allocate the needed space for the retrieved string. The library method may NOT touch this allocation, since the other memory manager ****s this up.

Example:

library Project1;

uses
  Unit1 in 'Unit1.pas';

  {$R ICON.res}

exports
  getInfo       index 1 name 'GetInfo',

begin
end.
----------------------------------------
unit Unit1;

interface

  Uses SysUtils;

  procedure getInfo(Name: pChar); stdcall; export;

implementation

  procedure getInfo(Name: pChar); stdcall;
  Begin
    //Do NOT use name:= 'Something'
    StrPCopy(Name,'This is dll');
  End;

end.

 At the project using the code, you should allocate as much memory to fit the largest string of them all, but it's fast and it works. The Windows libraries typically do the same.

Regards,
Williams
0
 
LVL 3

Expert Comment

by:williams2
ID: 1352616
..sorry, the {$R ICON.res} is just an example of how to include an Icon ressource to a dll, you should just remove it, or it wll fail to compile :-)

but to other guys:
I do not want to hear any objections on that the functions can be done more easy, because I do not share the opinion that every shared function should be located in the root source, though I have been corrected every time I come up with an example using this. :-)

Cheers and merry X-mas,
Williams


0
Industry Leaders: 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!

 
LVL 3

Expert Comment

by:philipleighs
ID: 1352617
Just to be on the safe side, you should getInfo should have another parameter which is the buffer size. This is what the WinAPI functions do. You could then prevent StrPCopy causing AVs by using StrPLCopy or whatever it is.

Now willy, before you go getting all defensive, know that I'm not trying to start another war. It's christmas man. I know you said something about the caller having the responsibility of ensuring that the buffer is long enough, so that's cool.

Oh and thanks for the xmas wishes, I'll drink to that and same to you. You know, by the time you have your first bevvy, I'll be (Edited by Computer101) in triplicate because we're 12 hours ahead!

Cheers!


0
 

Author Comment

by:sergio_2001
ID: 1352618
Hi Williams,

Thanks again for your answer.
Yet about my old question (mult-tiered application remember?) traking your tip to look for
Francois Piette I found anything very interesting. Look:
www.dbOvernet.com

Regards
Paulo
0
 
LVL 3

Expert Comment

by:williams2
ID: 1352619
Hi Paulo,

I think I have seen an add pointing to this URL. it sounds well, but I'm not sure I'll recommend anyone to a site whích is not freeware, but if the price is effortable (from 149$) I guess this must be the way to do it.

To Philipleighs:
hahahahaha.. You can (Edited by Computer101) in triplicates all that you want :-) ..I've was just having a little ironic-satiric moment, why prople ALWAYS post 5+ comments on how to export functions more easy than the other, sooo.. I guess your right about the buffer convertion.

I actually tried to allocate the needed memory inside the exported function, but I received a pointer error instead :-(

Cheers and more happy x-mas
Williams
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
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…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month4 days, 11 hours left to enroll

636 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