Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

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

errors while creating a DLL

Hi guys,

this is a very basic question for all you veterans in delphi.

I am creating a DLL in delphi tht I can't compile. I get an error message saying:

Unsatisfied forward or external declaration <procedurename>

wht does this mean???? and how do I fix the bug? right now I declare the function header at the top of the unit and also before the code in the implementation section. In my main project file I just list the name of the function under exports. Is this the right method for creating DLLs??

Also what does Self.<something> mean in delphi??? Is this a fucntion or type? how do we declare this in a project unit?

thanks,
ice
0
iceblue_22
Asked:
iceblue_22
  • 3
  • 3
  • 2
  • +2
1 Solution
 
ziolkoCommented:
typical DLL:

library std;

uses
  SysUtils,
  Classes;
{$R *.RES}

function SomeFunction:Integer; stdcall;
begin
  Result:=0;
end;

exports
  SomeFunction index 1 name 'SomeFunction';
 
begin
end.

ziolko.
0
 
pderuiterCommented:
k, in Delphi you have 2 "zones", an INTERFACE zone and an IMPLEMENTATION zone.
in the interface, you forward declare a function or procedure that you implement in the implementation zone.
If you put a function call in the interface zone, but not the implementation you will get this error.

straight from the help:

Within the implementation of a method, the identifier Self references the object in which the method is called.

In form form1 of type TForm1, self will reference form1
0
 
iceblue_22Author Commented:
Hi ziolko,

so far I have created two types of files
type 1: the main project file which looks like this

library sappdll;

{ 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,
  define_types in 'define_types.pas',
  dicom in 'dicom.pas',
  analyze in 'analyze.pas',
  decompress in 'decompress.pas',
  lsjpeg in 'lsjpeg.pas',
  sapp_image_reader in 'sapp_image_reader.pas';

{$R *.RES}

exports
 read_afni_data,
 read_ecat_data,
 read_siemens_data,
 read_ge_data,
 read_voxbo_data,
 read_PAR_data,
 read_VFF_data,
 read_picker_data,
 write_dicom,
 read_tiff_data,
 read_dicom_data,
 clear_dicom_data,
 write_interfile_hdr,
 SaveAnalyzeHdr,
 OpenAnalyze,
 DecompressRLE8,
 DecompressRLE16,
 DecompressRLE16toRGB,
 DecompressGE,
 decompressJPEG8,
 decompressJPEG24,
 DecodeJPEG,
 DisplayImage;

begin
end.

type 2: units in which I have the code which looks like this

unit decompress;
//This unit decompresses images encoded by RunLengthEncoding (RLE), lossyJPEG or GE's proprietary compression algorithm
//Note: lossless JPEG are decoded by the separate unit 'lsjpeg.pas'

interface
{$ifdef Linux}
uses sysUtils,define_types,Qdialogs;
{$else}
uses dialogs,sysutils,windows,classes,jpeg,Graphics,define_types;
{$endif}
//declarations
procedure DecompressRLE8(var infp: file; var lOutputBuff: ByteP0;lSamplesPerPixel,lAllocSliceSz,lCompressOffset,lCompressSz: integer); stdcall; export;
procedure DecompressRLE16(var infp: file; var lOutputBuff: SmallIntP0;lImageVoxels,lCompressOffset,lCompressSz: integer); stdcall; export;
procedure DecompressRLE16toRGB(var infp: file; var lOutputBuffRGB: ByteP0;lImageVoxels,lCompressOffset,lCompressSz,lRedLUTOffset,lGreenLUTOffset,lBlueLUTOffset,lRedLUTSz,lGreenLUTSz,lBlueLUTSz: integer); stdcall; export;
procedure DecompressGE(var infp: file; var lOutputBuff: SmallIntP0;lImageStart,lImgWid,lImgHt,lGenesisPackHdr: integer); stdcall; export;
procedure decompressJPEG8 (lFilename: string; var lOutputBuff{gBuff8}: ByteP0; lAllocSliceSz,lImageStart{gECATposra[lSlice]}: integer); stdcall; export;
procedure decompressJPEG24 (lFilename: string; var lOutputBuff: ByteP0; lImageVoxels,lImageStart{gECATposra[lSlice]}: integer); stdcall; export;


implementation

//code for the above functions with exactly the same header as above.

end.

I belive I have done what you have said earlier...I think I have having problems with the way I put in my stdcall; and export; directives. Right now both of these only appear in the interface section, not the implementation section.

pderuiter,

righto so self is like this in java right? but from what all i have read I can't used "self.<something>" in a DLL...is this correct? if so what do i need to do to make sure that i get the same behaviour in the code without the self? right now I have commented out this like. my aim is to get this dll loaded into a VC++ enviroment so I use the functions in it there.

thanks guys for all your help.

ice







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.

 
iceblue_22Author Commented:
Hi ziolko,

so far I have created two types of files
type 1: the main project file which looks like this

library sappdll;

{ 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,
  define_types in 'define_types.pas',
  dicom in 'dicom.pas',
  analyze in 'analyze.pas',
  decompress in 'decompress.pas',
  lsjpeg in 'lsjpeg.pas',
  sapp_image_reader in 'sapp_image_reader.pas';

{$R *.RES}

exports
 read_afni_data,
 read_ecat_data,
 read_siemens_data,
 read_ge_data,
 read_voxbo_data,
 read_PAR_data,
 read_VFF_data,
 read_picker_data,
 write_dicom,
 read_tiff_data,
 read_dicom_data,
 clear_dicom_data,
 write_interfile_hdr,
 SaveAnalyzeHdr,
 OpenAnalyze,
 DecompressRLE8,
 DecompressRLE16,
 DecompressRLE16toRGB,
 DecompressGE,
 decompressJPEG8,
 decompressJPEG24,
 DecodeJPEG,
 DisplayImage;

begin
end.

type 2: units in which I have the code which looks like this

unit decompress;
//This unit decompresses images encoded by RunLengthEncoding (RLE), lossyJPEG or GE's proprietary compression algorithm
//Note: lossless JPEG are decoded by the separate unit 'lsjpeg.pas'

interface
{$ifdef Linux}
uses sysUtils,define_types,Qdialogs;
{$else}
uses dialogs,sysutils,windows,classes,jpeg,Graphics,define_types;
{$endif}
//declarations
procedure DecompressRLE8(var infp: file; var lOutputBuff: ByteP0;lSamplesPerPixel,lAllocSliceSz,lCompressOffset,lCompressSz: integer); stdcall; export;
procedure DecompressRLE16(var infp: file; var lOutputBuff: SmallIntP0;lImageVoxels,lCompressOffset,lCompressSz: integer); stdcall; export;
procedure DecompressRLE16toRGB(var infp: file; var lOutputBuffRGB: ByteP0;lImageVoxels,lCompressOffset,lCompressSz,lRedLUTOffset,lGreenLUTOffset,lBlueLUTOffset,lRedLUTSz,lGreenLUTSz,lBlueLUTSz: integer); stdcall; export;
procedure DecompressGE(var infp: file; var lOutputBuff: SmallIntP0;lImageStart,lImgWid,lImgHt,lGenesisPackHdr: integer); stdcall; export;
procedure decompressJPEG8 (lFilename: string; var lOutputBuff{gBuff8}: ByteP0; lAllocSliceSz,lImageStart{gECATposra[lSlice]}: integer); stdcall; export;
procedure decompressJPEG24 (lFilename: string; var lOutputBuff: ByteP0; lImageVoxels,lImageStart{gECATposra[lSlice]}: integer); stdcall; export;


implementation

//code for the above functions with exactly the same header as above.

end.

I belive I have done what you have said earlier...I think I have having problems with the way I put in my stdcall; and export; directives. Right now both of these only appear in the interface section, not the implementation section.

pderuiter,

righto so self is like this in java right? but from what all i have read I can't used "self.<something>" in a DLL...is this correct? if so what do i need to do to make sure that i get the same behaviour in the code without the self? right now I have commented out this like. my aim is to get this dll loaded into a VC++ enviroment so I use the functions in it there.

thanks guys for all your help.

ice







0
 
ziolkoCommented:
I'll post some comments next week
ziolko.
0
 
pderuiterCommented:
I dont think you really need the export; directives. as long as your function is in the exports clause in your main unit, it will be useable.

Self can only be used within a method declared in a class. a "loose" method can't use self. i'm not sure what you want with "self".
0
 
ziolkoCommented:
pderuiter is right You dont need export clausule, and remember that in EXE wich will use this DLL functions headers olso must have stdcall. About Self delphi help says:  the identifier Self references the object in which the method is called.

so self is used in objects and its refernece of object to itself.

ziolko.
0
 
pderuiterCommented:
very probable that is the answer: A funciton with or without the stdcall: it will see them as different functions
0
 
CleanupPingCommented:
iceblue_22:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
kacorretiredCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:
       to split points between ziolko and pderuiter
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Some days and here is the Christmas Time. I wish good luck and good health for you all and for your loved ones

kacor
EE Cleanup Volunteer
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now