![]() |
DLL Einbindung in VB, VBA bzw. Lotus-Script
Ich habe eine dll mit Delphi erstellt und will diese nun z.B. in VBA nutzen,
Exports meiner dll
Delphi-Quellcode:
GetMails_File habe ich momentan als Work-Around für VB in meinem Projekt, da ich keien Plan habe wie ich in VB mit Pointern (Mails: PChar) umgehen soll. Deshalb schreibe ich den text jetzt in eine Datei die man nach dem Aufruf einlesen kann:
...
exports GetMails(Mails: PChar; KillDuplicates, RealNameEnabled, RealNameSimulated, FromOutlook, FromOpera, FromNetscape, FromLotusNotes, FromEudora, FromPegasus: boolean)name 'GetMails', GetMails(Mailfile: string; KillDuplicates, RealNameEnabled, RealNameSimulated, FromOutlook, FromOpera, FromNetscape, FromLotusNotes, FromEudora, FromPegasus: boolean)name 'GetMails_File'; ...
Code:
Hat jemand eine Idee, wie ich die Sache ohne die Textdatei lösen könnte (also über PChar -> 1. Export der dll)? Wenn ich versuche die Funktion mit dem Pointer aufzurufen crasht mir jedenfalls VBA bzw. Lotus-Notes :? ...
Declare Function GetMails Lib "localmail.dll" Alias "GetMails_File" (ByVal Mialfile As String, ByVal KillDuplicates As Integer, ByVal RealNameEnabled As Integer, ByVal RealNameSimulated As Integer, ByVal FromOutlook As Integer, ByVal FromOpera As Integer, ByVal FromNetscape As Integer, ByVal FromLotusNotes As Integer, ByVal FromEudora As Integer, ByVal FromPegasus As Integer) As Integer
Sub ReadMails() Dim txt As String Dim fileName As String Dim fileNum As Integer Dim counter As Integer ReDim Mails(0) As String txt$ = "" fileName = "MyMails.txt" fileNum% = FreeFile() counter% = 0 GetMails fileName, 1, 1, 1, 1, 1, 1, 1, 1, 1 Open fileName For Input As fileNum% Do While Not EOF(fileNum%) ReDim Preserve Mails(counter%) As String Line Input #fileNum%, txt$ Mails(counter%) = txt$ counter% = counter% + 1 Loop Close fileNum% For n = 0 To counter - 1 MsgBox Mails(n) Next Kill fileName End Sub |
Re: DLL Einbindung in VB, VBA bzw. Lotus-Script
Code:
gibt ein Handle (intern ein Pointer) zurück auf den Delphi Buffer.
function CreateMails(byval dwFlags as long) as long
dwFlags kann man auch als Enumeration machen (interesse frag danach)
Code:
gibt speicher wieder frei
function CloseMails(byval dwHandle as long) as boolean
Code:
gibt anzahl zurück
function CountMails(byval dwHandle as long) as integer
Code:
holt eine Mail ab
function GetMail(byval dwHandle as long, byval sBuf as string, byval iLen as long) as long
sBuf speicher von zeichen z.B. String(1024, " ") iLen länge des Buffer's 1024
Code:
ganz du dir darunter was vorstellen!
dim hMails as long
dim iCount as long ' Anzahl der Mails dim iLen as long ' Länge der zurückgegebenen Zeichengette dim sBuf as string ' Buffer für Rückgabe der Mail hMails = CreateMails(MAIL_OUTLOOK or MAIL_OPERA) if hMails <> 0 then iCount = CountMails(hMails) for I = 0 to iCount - 1 sBuf = String(1024) iLen = GetMail(hMails, sBuf, 1024) ' beachte das du in Delphi mit StrCopy arbeitest, keine zuweisung ala := if iLen > 0 then sBuf = Mid(sBuf, 1, iLen) ? sBuf end if next CloseMails(hMails) end if |
Re: DLL Einbindung in VB, VBA bzw. Lotus-Script
Tut mir leid,aber was haben die Beispiele mit meiner dll oder deren Einbindung zu tun?
Ich will ganz einfach einen Null-Terminierten String übergeben. Delphi Beispiel:
Delphi-Quellcode:
Warscheilich habe ich Probleme, weil ich in VB keinen Speicher zugewiesen habe... aber wie geht das?
function GetMailsEx(Mails: PChar; KillDuplicates, RealNameEnabled,
RealNameSimulated, FromOutlook, FromOpera, FromNetscape, FromLotusNotes, FromEudora, FromPegasus: boolean): boolean; stdcall; external 'B:\Projekte\Komponenten\LocalMail\dll\localmail.dll' name 'GetMails'; ... var Antwort: PChar; begin Antwort := StrAlloc(MAX_RESULT); if GetMailsEx(Antwort, True, True, True, True, True, True, True, True, True) = True then ShowMessage(Antwort); end; |
Re: DLL Einbindung in VB, VBA bzw. Lotus-Script
Das Problem liegt doch im detail,
bei großen mail-mengen bräuchtest du doch einen großen Buffer. Daher habe ich das ganze in kleine häppchen aufgespaltet.
Code:
geht zwar auch ist aber nicht gerade schön.
dim Antwort as string
Antwort := String(MAX_RESULT); if GetMailsEx(Antwort, 1, ... Würde ich z.B. als schnittstelle nicht akzeptieren. |
Re: DLL Einbindung in VB, VBA bzw. Lotus-Script
Zitat:
Aber das hilft mir noch nicht, das ganze in VB einzubinden... |
Re: DLL Einbindung in VB, VBA bzw. Lotus-Script
Es steht zwar alles dar aber vielleicht fehlt dir das noch!
Code:
function GetMailsEx(byval Mails as String, byval KillDuplicates as long, ...
|
Re: DLL Einbindung in VB, VBA bzw. Lotus-Script
Das habe ich schon längst gemacht...
Code:
Allerdings führt der Aufruf, wie gesagt zu einer Schutzverletzung und zum kompletten Absturz, sowohl von VBA, als auch von Lotus Notes
Declare Function GetMails Lib "B:\Projekte\Komponenten\LocalMail\dll\localmail.dll" (ByVal Mails As String, ByVal KillDuplicates As Integer, ByVal RealNameEnabled As Integer, ByVal RealNameSimulated As Integer, ByVal FromOutlook As Integer, ByVal FromOpera As Integer, ByVal FromNetscape As Integer, ByVal FromLotusNotes As Integer, ByVal FromEudora As Integer, ByVal FromPegasus As Integer) As Integer
Code:
GetMails Antwort, 1, 1, 1, 1, 1, 1, 1, 1, 1
|
Re: DLL Einbindung in VB, VBA bzw. Lotus-Script
Ich hoffe du arbeitest intern mit StrCopy
|
Re: DLL Einbindung in VB, VBA bzw. Lotus-Script
Ich arbeite intern mit StrLCopy...
Delphi-Quellcode:
Es macht aber keinen Unterschied, ob ich mit StrCopy oder StrLCopy arbeite... in beiden Fällen funktioniert der DLL Aufruf über ein Delphi-Program probemlos, aber VBA crasht :cry: ...
const
MAX_RESULT = 4000; ... function GetMails(Mails: PChar; KillDuplicates, RealNameEnabled, RealNameSimulated, FromOutlook, FromOpera, FromNetscape, FromLotusNotes, FromEudora, FromPegasus: boolean): Boolean; overload; export; stdcall; var MyMailList: TFr_LocalMail; begin MyMailList := nil; Result := False; try MyMailList := TFr_LocalMail.Create(nil); MyMailList.KillDuplicates := KillDuplicates; MyMailList.RealNameEnabled := RealNameEnabled; MyMailList.RealNameSimulated := RealNameSimulated; MyMailList.FromOutlook := FromOutlook; MyMailList.FromOpera := FromOpera; MyMailList.FromNetscape := FromNetscape; MyMailList.FromLotusNotes := FromLotusNotes; MyMailList.FromEudora := FromEudora; MyMailList.FromPegasus := FromPegasus; StrLCopy(Mails, PCHar(MyMailList.Mails.CommaText), MAX_RESULT); result := True; finally MyMailList.Free; end; end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 21:35 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz