Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Problem with DLL in Delphi (https://www.delphipraxis.net/181517-problem-dll-delphi.html)

WojTec 21. Aug 2014 14:10

Delphi-Version: XE5

Problem with DLL in Delphi
 
I want to use this DLL:

Code:
http://ntinfo.biz/files/diedll.zip
in Delphi.

C header is:

Code:
#ifndef DIEDLL_H
#define DIEDLL_H

#include <windows.h>

// flags
#define DIE_SHOWERRORS             0x00000001
#define DIE_SHOWOPTIONS            0x00000002
#define DIE_SHOWVERSION            0x00000004
#define DIE_SHOWENTROPY            0x00000008
#define DIE_SINGLELINEOUTPUT       0x00000010
#define DIE_SHOWFILEFORMATONCE     0x00000020

#ifdef __cplusplus
extern "C" {
#endif

int __declspec(dllexport) __stdcall DIE_scanA(char *pszFileName,char *pszOutBuffer,int nOutBufferSize,unsigned int nFlags);
int __declspec(dllexport) __stdcall DIE_scanW(wchar_t *pwszFileName,char *pszOutBuffer,int nOutBufferSize,unsigned int nFlags);
int __declspec(dllexport) __stdcall DIE_scanExA(char *pszFileName,char *pszOutBuffer,int nOutBufferSize,unsigned int nFlags,char *pszDataBase);
int __declspec(dllexport) __stdcall DIE_scanExW(wchar_t *pwszFileName,char *pszOutBuffer,int nOutBufferSize,unsigned int nFlags,wchar_t *pwszDataBase);
PCHAR __declspec(dllexport) __stdcall DIE_versionA(void);
PWCHAR __declspec(dllexport) __stdcall DIE_versionW(void);


#ifdef UNICODE
#define DIE_scan DIE_scanW
#define DIE_scanEx DIE_scanExW
#define DIE_version DIE_versionW
#else
#define DIE_scan DIE_scanA
#define DIE_scanEx DIE_scanExA
#define DIE_version DIE_versionA
#endif

#ifdef __cplusplus
}
#endif

#endif // DIEDLL_H
I ported it to Delphi:

Delphi-Quellcode:
unit diedll;

interface

const
  DIE_SHOWERRORS = $00000001;
  DIE_SHOWOPTIONS = $00000002;
  DIE_SHOWVERSION = $00000004;
  DIE_SHOWENTROPY = $00000008;
  DIE_SINGLELINEOUTPUT = $00000010;
  DIE_SHOWFILEFORMATONCE = $00000020;

function DIE_scanA(pszFileName, pszOutBuffer: PAnsiChar; nOutBufferSize: Cardinal; nFlags: Cardinal): Integer; stdcall;
  external 'diedll.dll' name 'DIE_scanA';
function DIE_scanW(pszFileName, pszOutBuffer: PWideChar; nOutBufferSize: Cardinal; nFlags: Cardinal): Integer; stdcall;
  external 'diedll.dll' name 'DIE_scanW';
function DIE_scanExA(pszFileName, pszOutBuffer: PAnsiChar; nOutBufferSize: Cardinal; nFlags: Cardinal; pszDataBase: PAnsiChar): Integer; stdcall;
  external 'diedll.dll' name 'DIE_scanExA';
function DIE_scanExW(pszFileName, pszOutBuffer: PWideChar; nOutBufferSize: Cardinal; nFlags: Cardinal; pwszDataBase: PWideChar): Integer; stdcall;
  external 'diedll.dll' name 'DIE_scanExW';
function DIE_versionA: PAnsiChar; stdcall;
  external 'diedll.dll' name 'DIE_versionA';
function DIE_versionW: PWideChar; stdcall;
  external 'diedll.dll' name 'DIE_versionW';

implementation

end.
No I tried use it:

Delphi-Quellcode:
var
  Buffer: array [0..1023] of Char;
begin
  Caption := DIE_versionW;
  DIE_scanW('C:\Windows\notepad.exe', Buffer, 1024, DIE_SHOWOPTIONS or DIE_SHOWVERSION);
  ShowMessage(string(Buffer));
end;
Message: Function entry point not found in diedll.dll.
I checked what is exported from DLL and make changes in unit:

Delphi-Quellcode:
function DIE_scanA(pszFileName, pszOutBuffer: PAnsiChar; nOutBufferSize: Cardinal; nFlags: Cardinal): Integer; stdcall;
  external 'diedll.dll' name '_DIE_scanA@16';
function DIE_scanW(pszFileName, pszOutBuffer: PWideChar; nOutBufferSize: Cardinal; nFlags: Cardinal): Integer; stdcall;
  external 'diedll.dll' name '_DIE_scanW@16';
function DIE_scanExA(pszFileName, pszOutBuffer: PAnsiChar; nOutBufferSize: Cardinal; nFlags: Cardinal; pszDataBase: PAnsiChar): Integer; stdcall;
  external 'diedll.dll' name '_DIE_scanExA@20';
function DIE_scanExW(pszFileName, pszOutBuffer: PWideChar; nOutBufferSize: Cardinal; nFlags: Cardinal; pwszDataBase: PWideChar): Integer; stdcall;
  external 'diedll.dll' name '_DIE_scanExW@20';
function DIE_versionA: PAnsiChar; stdcall;
  external 'diedll.dll' name '_DIE_versionA@0';
function DIE_versionW: PWideChar; stdcall;
  external 'diedll.dll' name '_DIE_versionW@0';
So, function to check version looks to be ok, but in scans is something wrong:

Code:
---------------------------
Debugger Exception Notification
---------------------------
Project DIE.exe raised exception class $C0000090 with message 'floating point invalid operation at 0x6c09023f'.
---------------------------
Break  Continue  Help  
---------------------------
Help make it working, please :(

gammatester 21. Aug 2014 14:52

AW: Problem with DLL in Delphi
 
Here you work with AnsiChar:
Delphi-Quellcode:
function DIE_scanA(pszFileName, pszOutBuffer: PAnsiChar; nOutBufferSize: Cardinal; nFlags: Cardinal): Integer; stdcall;
  external 'diedll.dll' name 'DIE_scanA';
But this is not Ansi:
Delphi-Quellcode:
var
  Buffer: array [0..1023] of Char;
Try this instead
Delphi-Quellcode:
var
  Buffer: array [0..1023] of AnsiChar;
but maybe there are other problems.

WojTec 21. Aug 2014 15:09

Re: AW: Problem with DLL in Delphi
 
Zitat:

Zitat von gammatester (Beitrag 1269427)
Here you work with AnsiChar:

Call is correct:

Delphi-Quellcode:
var
  Buffer: array [0..1023] of Char;
begin
  Caption := DIE_versionW;
  DIE_scanW('C:\Windows\notepad.exe', Buffer, SizeOf(Buffer), DIE_SHOWOPTIONS or DIE_SHOWVERSION);
  ShowMessage(StrPas(Buffer));
end;
Otherwise compiler tell me that types must be compatible.

Somebody has used this DLL?

DeddyH 21. Aug 2014 15:19

AW: Problem with DLL in Delphi
 
What about
Delphi-Quellcode:
DIE_scanW('C:\Windows\notepad.exe', @Buffer[Low(Buffer)], SizeOf(Buffer), DIE_SHOWOPTIONS or DIE_SHOWVERSION);
?

WojTec 21. Aug 2014 15:24

Re: Problem with DLL in Delphi
 
Same result:

Code:
---------------------------
Debugger Exception Notification
---------------------------
Project DIE.exe raised exception class $C0000090 with message 'floating point invalid operation at 0x6bfc023f'.
---------------------------
Break  Continue  Help  
---------------------------
Maybe some can try it in C++?

:(

himitsu 21. Aug 2014 15:25

AW: Problem with DLL in Delphi
 
Code:
int __declspec(dllexport) __stdcall DIE_scanA  (char    *pszFileName,  char *pszOutBuffer, int nOutBufferSize, unsigned int nFlags);
int __declspec(dllexport) __stdcall DIE_scanW  (wchar_t *pwszFileName, char *pszOutBuffer, int nOutBufferSize, unsigned int nFlags);
int __declspec(dllexport) __stdcall DIE_scanExA(char    *pszFileName,  char *pszOutBuffer, int nOutBufferSize, unsigned int nFlags, char    *pszDataBase);
int __declspec(dllexport) __stdcall DIE_scanExW(wchar_t *pwszFileName, char *pszOutBuffer, int nOutBufferSize, unsigned int nFlags, wchar_t *pwszDataBase);
The output buffer is always AnsiChar,

but that still does not explain the error message. :gruebel:

WojTec 21. Aug 2014 15:40

Re: AW: Problem with DLL in Delphi
 
Zitat:

Zitat von himitsu (Beitrag 1269439)
The output buffer is always AnsiChar

You've right, fixed:

Delphi-Quellcode:
function DIE_scanA(pszFileName, pszOutBuffer: PAnsiChar; nOutBufferSize: Cardinal; nFlags: Cardinal): Integer; stdcall;
  external 'diedll.dll' name '_DIE_scanA@16';
function DIE_scanW(pszFileName: PWideChar; pszOutBuffer: PAnsiChar; nOutBufferSize: Cardinal; nFlags: Cardinal): Integer; stdcall;
  external 'diedll.dll' name '_DIE_scanW@16';
function DIE_scanExA(pszFileName, pszOutBuffer: PAnsiChar; nOutBufferSize: Cardinal; nFlags: Cardinal; pszDataBase: PAnsiChar): Integer; stdcall;
  external 'diedll.dll' name '_DIE_scanExA@20';
function DIE_scanExW(pszFileName: PWideChar; pszOutBuffer: PAnsiChar; nOutBufferSize: Cardinal; nFlags: Cardinal; pwszDataBase: PWideChar): Integer; stdcall;
  external 'diedll.dll' name '_DIE_scanExW@20';
function DIE_versionA: PAnsiChar; stdcall;
  external 'diedll.dll' name '_DIE_versionA@0';
function DIE_versionW: PWideChar; stdcall;
  external 'diedll.dll' name '_DIE_versionW@0';
Have you looked on SDK? There is folder with signatures, if function doesn't see it, it returns string that nothing found (and no exceptions), this may be DLL internal exception?

baumina 21. Aug 2014 15:46

AW: Problem with DLL in Delphi
 
Dont know if it helps : http://pastebin.com/0jFiqDY7

WojTec 21. Aug 2014 17:04

Re: Problem with DLL in Delphi
 
No, still the same error :(

EWeiss 22. Aug 2014 09:04

AW: Problem with DLL in Delphi
 
why your use __cplusplus and __stdcall?

sample..
use
Code:
#ifdef __cplusplus
extern "C" {
#endif
instead of define
Zitat:

__stdcall by Hand
define exports inside your dll is written in Delphi
sample
Code:
#ifndef TAGSLIBDEF
#define TAGSLIBDEF(f) WINAPI f
#endif
Delphi
Code:
TagsLibrary_Free  name 'TagsLibrary_Free@HereTheByteWhichHTAGSHas' Sample (TagsLibrary_Free@4) if HTAGS = Integer
Create the DEF File with DumpBin
dumpbin /exports TagsLib.dll >TagsLib.def

Create a lib
LIB /DEF:TagsLib.DEF

Sample Header
Code:
#ifndef TAGSLIBDEF_H
#define TAGSLIBDEF_H

#include <wtypes.h>

#ifdef __cplusplus
extern "C" {
#endif

#ifndef TAGSLIBDEF
#define TAGSLIBDEF(f) WINAPI f
#endif


// Your Exports Header and so on
BOOL TAGSLIBDEF(TagsLibrary_Free)(HTAGS Tags);
int TAGSLIBDEF(TagsLibrary_Load)(HTAGS Tags, LPWSTR FileName, TTagType TagType, BOOL ParseTags);

#ifdef __cplusplus
}
#endif

#endif
def file should then be
Zitat:

LIBRARY TagsLib

DESCRIPTION 'Tags reader-writer component for Delphi'

EXPORTS
TagsLibrary_AddCoverArt
this is a sample also convert it to your DLL.

sorry for my bad english.
this is for static linking DLL not "dynamic linking"

And
your should disable floating point exception inside Delphi


greets


Alle Zeitangaben in WEZ +1. Es ist jetzt 01:37 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz