Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 06-22-2012, 06:16 AM
abcd abcd is offline
Senior Member
 
Join Date: Nov 2009
Posts: 132
Default String inside DLL

I prevent to use sharemem unit in my DLL file so I don't use string variable as the parameter.


Code:
function Test(const Filename:widestring;var output:widestring):boolean;stdcall;
begin
if Test2(Filename,output) then
bla
end;

functon Test2(const Filename:string;var output:string):boolean;
begin
;
end;

exports Test;
My question, is it safe to use any string variable inside DLL function , even the string variable is not located in function that being exported.

Last edited by abcd; 06-28-2012 at 03:33 AM.
Reply With Quote
  #2  
Old 06-28-2012, 03:34 AM
abcd abcd is offline
Senior Member
 
Join Date: Nov 2009
Posts: 132
Default

Sorry for bumping the question. Perhaps someone missed my thread.
Reply With Quote
  #3  
Old 06-28-2012, 04:23 PM
Ouiji Ouiji is offline
Senior Member
 
Join Date: Nov 2001
Location: US of A
Posts: 478
Send a message via AIM to Ouiji
Default

I think I have read over this post about 15 times trying to understand what it is you are asking, by "safe" are you meaning in terms of memory leaks and internal string issues? Or are you meaning something entirely different like reverse engineering, or something else I am not smart enough to comprehend? If you could provide a little more detail I think you would get some decent replies.
__________________
"not quite smart enough to be dumb"
Extended Stats No Longer Available Due To Changes To The Forum.
Reply With Quote
  #4  
Old 06-29-2012, 09:21 AM
abcd abcd is offline
Senior Member
 
Join Date: Nov 2009
Posts: 132
Default

If I use a string as parameter in exported function without sharemem unit then that is "not safe" (causing access violation/memory allocation issue). That's what I mean about safe or not safe. I hope you can understand my question.
Reply With Quote
  #5  
Old 07-06-2012, 12:00 AM
major major is offline
Member
 
Join Date: Jun 2011
Posts: 42
Default

It is perfectly safe to use Strings within your DLL (passing them between functions and procedures within the DLL) The memory issue only arises when you are passing strings to/from your program and a DLL.

To get around the need to include Sharemem in your program and DLL, you could use PChars, or to simplify the process, declare the values being passed as WideString. See here for an explanation: http://stackoverflow.com/a/9331077
Reply With Quote
  #6  
Old 07-17-2012, 02:45 AM
abcd abcd is offline
Senior Member
 
Join Date: Nov 2009
Posts: 132
Default

Thanks for your explanation major. Now I pass my value as WideString. Somehow sometimes I got crash and madexcept could not report the error. Probably this crash is another problem. Anyway, if I use WideString, is it safe to compile my program and DLL with different version of compiler?
Reply With Quote
Reply

Tags
dll

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 02:05 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.