PDA

View Full Version : ساخت یک Dll آسان



Laia2005
سه شنبه 11 بهمن 1384, 13:55 عصر
من می خواهم یک Dll بسازم که توش یک تابع باشه این تابع یک عدد بگیره و بعد آن عدد را در 3 ضرب کنه .

یکی زحمت بکشه و بگه کدش را چه جوری بنویسم ؟

Touska
سه شنبه 11 بهمن 1384, 13:58 عصر
اینم مثال نه اون چیزی که می خواهی :

library Persian;

{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }

uses
SysUtils,
Classes,
DateUtils,
Utils;

{$R *.res}

Function PrintDate: ShortString;
begin
Result := datetostr(date);
End;


Exports
PrintDate;

begin
end.

Laia2005
سه شنبه 11 بهمن 1384, 15:38 عصر
آقای توسکا خیلی ممنون

من همه ای اون کدهایی که شما نوشتید را استفاده کردم همه مراحل خوب پیش میره حتی تو پروژه ای که هم که از آن Dll استفاده می کنم قشنگ تابع را میشناسه

اما

موقع اجرای برنامه این خطا را میدهد

راستی شما بعد از این که اون کدها را نوشتید دیگه چه کارهایی می کنید به طور مثال کامپایل می کنید یا کارهای دیگه

Touska
سه شنبه 11 بهمن 1384, 19:48 عصر
شما چه جوری ازش استفاده کردید کد استفاده رو بنویسید.

Laia2005
سه شنبه 11 بهمن 1384, 21:06 عصر
library Project1;

{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }

uses
SysUtils,
Classes;

{$R *.res}

Function Test: ShortString;
begin
Result := 'Laia' ;
End;

Exports
Test;

begin
end.

Laia2005
سه شنبه 11 بهمن 1384, 21:08 عصر
آقای توسکا شما بعد از این که کد را نوشتید چی کار می کنید ؟

از برنامه خارج می شوید .!
کامپایل می کنید .!

vcldeveloper
چهارشنبه 12 بهمن 1384, 07:09 صبح
من نه در کد شما و نه در کد آقای Touska تابعی به اسم PrintNormal نمی بینم. پیغام خطا هم میگه که همچین تابعی در DLL مربوطه وجود نداره

Touska
چهارشنبه 12 بهمن 1384, 08:18 صبح
چالبش همینه !

Laia2005
چهارشنبه 12 بهمن 1384, 13:58 عصر
آقای Touska شما چگونه تابع را از Dll فراخوانی می کنید ؟

Touska
چهارشنبه 12 بهمن 1384, 18:43 عصر
به این شکل البته بصورت استاتیک :


Function PrintDate: ShortString;
External 'persian.dll';


بعد ازش استفاده می کنم.

Laia2005
چهارشنبه 12 بهمن 1384, 18:48 عصر
اینم مثال نه اون چیزی که می خواهی :

library Persian;

{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }

uses
SysUtils,
Classes,
DateUtils,
Utils;

{$R *.res}

Function PrintDate: ShortString;
begin
Result := datetostr(date);
End;


Exports
PrintDate;

begin
end.


از این روش هم برای خواندن استفاده کردم اما بازم همون خطای با لا را میده
Function PrintDate: ShortString;
External 'persian.dll';

آقای توسکا خیلی ممنون که پیگیر این مسئله شده اید

میشه پروژه Dll را ذخیره کرده و اینجا آپلود کنید ؟

Touska
چهارشنبه 12 بهمن 1384, 18:57 عصر
اینم مثال :