Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 273
  • Last Modified:

DLL and Strings parameters

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
sergio_2001
Asked:
sergio_2001
1 Solution
 
KECommented:
How long are the strings you want to send, and would you need other datatypes to go along ?

0
 
williams2Commented:
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
 
williams2Commented:
..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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
philipleighsCommented:
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
 
sergio_2001Author Commented:
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
 
williams2Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now