Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

DLL and Strings parameters

Posted on 1998-12-22
6
Medium Priority
?
270 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
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 150 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

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

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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

886 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