Purebasic DLL - Direkte Rückgabe eines String n. VB6/VB.NET
Verfasst: 21.11.2007 11:48
Bastel gerade eine DLL für mein Kollege der VB6 verwendet.
Die Funktionen sollen aber ein String zurück geben um mit VB einfacher damit arbeiten zu können.
Eine vorherige Umwandlung nach BSTR(Unicode) ist nicht erforderlich, da dieses von VB selber durchgeführt wird.
Beispielcode PB-DLL (vbTest.dll)
VB.NET MainForm (Ein Button)
VB.NET Modul1
Bei VB6 reicht
wenn die DLL im gleichen Verzeichnis liegt.
Viel freude beim programmieren
FF
Die Funktionen sollen aber ein String zurück geben um mit VB einfacher damit arbeiten zu können.
Eine vorherige Umwandlung nach BSTR(Unicode) ist nicht erforderlich, da dieses von VB selber durchgeführt wird.
Beispielcode PB-DLL (vbTest.dll)
Code: Alles auswählen
; Comment : DLL with vbString as Result
; Author : mk-soft
; Version : v1.1
; Date : 2007.11.21
Structure vbString
len.l
text.s
EndStructure
; *************************************************************************************
; This procedure is called once, when the program loads the library
; for the first time. All init stuffs can be done here (but not DirectX init)
;
ProcedureDLL AttachProcess(Instance)
EndProcedure
; Called when the program release (free) the DLL
;
ProcedureDLL DetachProcess(Instance)
EndProcedure
; Both are called when a thread in a program call or release (free) the DLL
;
ProcedureDLL AttachThread(Instance)
EndProcedure
ProcedureDLL DetachThread(Instance)
EndProcedure
; *************************************************************************************
ProcedureDLL concat(text1.s, text2.s)
Static vbResult.vbString
With vbResult
\text = text1 + text2
\len = Len(\text)
EndWith
ProcedureReturn @vbResult\text
EndProcedure
Code: Alles auswählen
Public Class MainForm
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ret As String
ret = concat("Hallo Welt", " ;)")
ret = ret & concat(Chr(10), "Direkte Rückgabe eines Strings")
MsgBox(ret)
End Sub
End Class
Code: Alles auswählen
Module Module1
Declare Ansi Function concat Lib "d:\daten\purebasic4\vbdll\vbTest.dll" (ByVal text1 As String, ByVal text2 As String) As String
End Module
Code: Alles auswählen
Declare Function concat Lib "vbTest.dll" (ByVal text1 As String, ByVal text2 As String) As String
Viel freude beim programmieren
FF
