AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Problem with DLL in Delphi

Ein Thema von WojTec · begonnen am 21. Aug 2014 · letzter Beitrag vom 22. Aug 2014
Antwort Antwort
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#1

Problem with DLL in Delphi

  Alt 21. Aug 2014, 14:10
Delphi-Version: XE5
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.dllname 'DIE_scanA';
function DIE_scanW(pszFileName, pszOutBuffer: PWideChar; nOutBufferSize: Cardinal; nFlags: Cardinal): Integer; stdcall;
  external 'diedll.dllname 'DIE_scanW';
function DIE_scanExA(pszFileName, pszOutBuffer: PAnsiChar; nOutBufferSize: Cardinal; nFlags: Cardinal; pszDataBase: PAnsiChar): Integer; stdcall;
  external 'diedll.dllname 'DIE_scanExA';
function DIE_scanExW(pszFileName, pszOutBuffer: PWideChar; nOutBufferSize: Cardinal; nFlags: Cardinal; pwszDataBase: PWideChar): Integer; stdcall;
  external 'diedll.dllname 'DIE_scanExW';
function DIE_versionA: PAnsiChar; stdcall;
  external 'diedll.dllname 'DIE_versionA';
function DIE_versionW: PWideChar; stdcall;
  external 'diedll.dllname '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.dllname '_DIE_scanA@16';
function DIE_scanW(pszFileName, pszOutBuffer: PWideChar; nOutBufferSize: Cardinal; nFlags: Cardinal): Integer; stdcall;
  external 'diedll.dllname '_DIE_scanW@16';
function DIE_scanExA(pszFileName, pszOutBuffer: PAnsiChar; nOutBufferSize: Cardinal; nFlags: Cardinal; pszDataBase: PAnsiChar): Integer; stdcall;
  external 'diedll.dllname '_DIE_scanExA@20';
function DIE_scanExW(pszFileName, pszOutBuffer: PWideChar; nOutBufferSize: Cardinal; nFlags: Cardinal; pwszDataBase: PWideChar): Integer; stdcall;
  external 'diedll.dllname '_DIE_scanExW@20';
function DIE_versionA: PAnsiChar; stdcall;
  external 'diedll.dllname '_DIE_versionA@0';
function DIE_versionW: PWideChar; stdcall;
  external 'diedll.dllname '_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
  Mit Zitat antworten Zitat
gammatester

Registriert seit: 6. Dez 2005
999 Beiträge
 
#2

AW: Problem with DLL in Delphi

  Alt 21. Aug 2014, 14:52
Here you work with AnsiChar:
Delphi-Quellcode:
function DIE_scanA(pszFileName, pszOutBuffer: PAnsiChar; nOutBufferSize: Cardinal; nFlags: Cardinal): Integer; stdcall;
  external 'diedll.dllname '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.
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#3

Re: AW: Problem with DLL in Delphi

  Alt 21. Aug 2014, 15:09
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?
  Mit Zitat antworten Zitat
Benutzerbild von DeddyH
DeddyH

Registriert seit: 17. Sep 2006
Ort: Barchfeld
27.540 Beiträge
 
Delphi 11 Alexandria
 
#4

AW: Problem with DLL in Delphi

  Alt 21. Aug 2014, 15:19
What about
DIE_scanW('C:\Windows\notepad.exe', @Buffer[Low(Buffer)], SizeOf(Buffer), DIE_SHOWOPTIONS or DIE_SHOWVERSION); ?
Detlef
"Ich habe Angst vor dem Tag, an dem die Technologie unsere menschlichen Interaktionen übertrumpft. Die Welt wird eine Generation von Idioten bekommen." (Albert Einstein)
Dieser Tag ist längst gekommen
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#5

Re: Problem with DLL in Delphi

  Alt 21. Aug 2014, 15:24
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++?


Geändert von WojTec (21. Aug 2014 um 15:30 Uhr) Grund: Question
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu
Online

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.137 Beiträge
 
Delphi 12 Athens
 
#6

AW: Problem with DLL in Delphi

  Alt 21. Aug 2014, 15:25
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.
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#7

Re: AW: Problem with DLL in Delphi

  Alt 21. Aug 2014, 15:40
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.dllname '_DIE_scanA@16';
function DIE_scanW(pszFileName: PWideChar; pszOutBuffer: PAnsiChar; nOutBufferSize: Cardinal; nFlags: Cardinal): Integer; stdcall;
  external 'diedll.dllname '_DIE_scanW@16';
function DIE_scanExA(pszFileName, pszOutBuffer: PAnsiChar; nOutBufferSize: Cardinal; nFlags: Cardinal; pszDataBase: PAnsiChar): Integer; stdcall;
  external 'diedll.dllname '_DIE_scanExA@20';
function DIE_scanExW(pszFileName: PWideChar; pszOutBuffer: PAnsiChar; nOutBufferSize: Cardinal; nFlags: Cardinal; pwszDataBase: PWideChar): Integer; stdcall;
  external 'diedll.dllname '_DIE_scanExW@20';
function DIE_versionA: PAnsiChar; stdcall;
  external 'diedll.dllname '_DIE_versionA@0';
function DIE_versionW: PWideChar; stdcall;
  external 'diedll.dllname '_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?
  Mit Zitat antworten Zitat
Benutzerbild von baumina
baumina

Registriert seit: 5. Mai 2008
Ort: Oberschwaben
1.275 Beiträge
 
Delphi 11 Alexandria
 
#8

AW: Problem with DLL in Delphi

  Alt 21. Aug 2014, 15:46
Dont know if it helps : http://pastebin.com/0jFiqDY7
Hinter dir gehts abwärts und vor dir steil bergauf ! (Wolfgang Ambros)
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#9

Re: Problem with DLL in Delphi

  Alt 21. Aug 2014, 17:04
No, still the same error
  Mit Zitat antworten Zitat
EWeiss
(Gast)

n/a Beiträge
 
#10

AW: Problem with DLL in Delphi

  Alt 22. Aug 2014, 09:04
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
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 12:40 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