Returning Visual Basic strings from a DLL
Returning Visual Basic strings from a DLL
This could probably also be in coding questions but since Visual Basic is a Windows only programming language I thought it would fit better here.
I need to write some DLL functions that can return a string to a Visual Basic program. Any tips on where to look for how to do it?
I know I could use the method for getting strings from API calls, such as GetEnvironmentVariable where you create a stirng buffer to receive the data, then send a pointer to the string to the DLL.
But if possible, I'd prefer the function actually return a string to Visual Baic just like Visual Basic's built-in string functions do.
Thanks!
I need to write some DLL functions that can return a string to a Visual Basic program. Any tips on where to look for how to do it?
I know I could use the method for getting strings from API calls, such as GetEnvironmentVariable where you create a stirng buffer to receive the data, then send a pointer to the string to the DLL.
But if possible, I'd prefer the function actually return a string to Visual Baic just like Visual Basic's built-in string functions do.
Thanks!
- the.weavster
- Addict

- Posts: 1581
- Joined: Thu Jul 03, 2003 6:53 pm
- Location: England
I don't think VB has an equivalent of a PeekS() command but you could create one, try this (to be added to a VB code module):
Code: Select all
Public Declare Function lstrlenA Lib "kernel32" (ByVal lpString As Long) As Long
Public Declare Sub RtlMoveMemory Lib "kernel32" (dest As Any, source As Any, ByVal bytes As Long)
Function PeekS(ByVal MemAddress As Long) As String
'...determine the length of the null terminated string at the stated memory address...
length = lstrlenA(MemAddress)
'...now make it available to VB...
PeekS = Space$(length)
RtlMoveMemory ByVal PeekS, ByVal MemAddress, length
End Function-
Edwin Knoppert
- Addict

- Posts: 1073
- Joined: Fri Apr 25, 2003 11:13 pm
- Location: Netherlands
- Contact:
- the.weavster
- Addict

- Posts: 1581
- Joined: Thu Jul 03, 2003 6:53 pm
- Location: England
-
Edwin Knoppert
- Addict

- Posts: 1073
- Joined: Fri Apr 25, 2003 11:13 pm
- Location: Netherlands
- Contact:
- the.weavster
- Addict

- Posts: 1581
- Joined: Thu Jul 03, 2003 6:53 pm
- Location: England
I don't think I'll bother, I have no real interest in VB.Edwin Knoppert wrote:The solution is to read (and learn) about VB strings so check MSDN (TIP: BSTR)
Well, why don't you tell everyone what you think is wrong with it.Edwin Knoppert wrote:Problem is that i seen this kind of code in several occasions and no one seems to verify their code..
-
Edwin Knoppert
- Addict

- Posts: 1073
- Joined: Fri Apr 25, 2003 11:13 pm
- Location: Netherlands
- Contact:
>Well, why don't you tell everyone what you think is wrong with it
Not in this particulair case since it's imo a bad thing to dump some code which was obviously not verified..
and.. why didn't you read stuff instead of waiting for the correct answer?
>I don't think I'll bother, I have no real interest in VB.
That's my point, just dumping some "hey it works" code..
Problem is that this code remains in for years while it's working incorrect.
O well, a monday-moodswing came up
Not in this particulair case since it's imo a bad thing to dump some code which was obviously not verified..
and.. why didn't you read stuff instead of waiting for the correct answer?
>I don't think I'll bother, I have no real interest in VB.
That's my point, just dumping some "hey it works" code..
Problem is that this code remains in for years while it's working incorrect.
O well, a monday-moodswing came up
- the.weavster
- Addict

- Posts: 1581
- Joined: Thu Jul 03, 2003 6:53 pm
- Location: England
-
Edwin Knoppert
- Addict

- Posts: 1073
- Joined: Fri Apr 25, 2003 11:13 pm
- Location: Netherlands
- Contact:
Edwin, Do'h! BSTR! If I had remembered that's what VB strings were called I probably could have found this myself!Edwin Knoppert wrote:http://www.purebasic.fr/english/viewtop ... light=bstr
Anyway, Thank you! That gives me a good place to start.... (and get into trouble...