Hi everybody,
At the moment i work on a freebasic dll which will later be on called by a VB.net Program. >>>>!!! 64 BIT !!!<<<<
VB.net, NOT *VBA*
While mathematical numbers to pass is no problem, strings drives me since days crazy.
in the vb.net dll program ive declared:
Declare Auto Function SendString Lib "D:\FREEBASIC\Projects\fbnet\fbnet.dll" (ByRef s As String) As String 'HOPELESS
Declare Auto Sub OBOX2 Lib "D:\FREEBASIC\Projects\fbnet\fbnet.dll" (ByVal s As String) 'WORKS !
Public Sub OBOX2(Byval s As WString Ptr ) Export
OBOX( *s & "dsadSAD")
Dim As Integer iResult
iResult = MessageBox(0, S, "MSG",MB_YESNO Or MB_ICONQUESTION Or MB_DEFBUTTON2 or MB_SYSTEMMODAL)
End Sub
But if i try to return a string as a function result i just get a error or crash :/
I try to make something similar like that:
Function ADDS(textin as string) As string
dim R as string
r=R & "Hi i am a result"
Return R
End Function
It seems that BSTR is not the Answer for VB.NET
If something could help me out with something as sample code that would be a great help.
Best regards
Thomas
FBC64 dll for VB.NET64 bit String calling conventions
Re: FBC64 dll for VB.NET64 bit String calling conventions
When I do something similar with Delphi, I also have to switch the memory manager to COM. So it could be worthwhile to find out if the 64-bit malloc lib that fb uses is COM compatible.
Re: FBC64 dll for VB.NET64 bit String calling conventions
zstring pointer return would be worth trying.
But maybe try returning string byref first.
But maybe try returning string byref first.
Code: Select all
Function ADDS(textin as string) byref As string export
static R as string
R=textin & "Hi i am a result"
Return R
End Function
function addstring(s as zstring ptr) as zstring ptr export
dim as string ans=*s + " Hello"
dim as zstring ptr ret=callocate(len(ans),1)
*ret=(ans)
function= ret
end function
'print ADDS("Testing, ")
'print *addstring("Hi-")
'sleep
Re: FBC64 dll for VB.NET64 bit String calling conventions
We came so far with - hanks o ST_W from the freebasic irc chat. See below
Bu as you can see there is a nasty Marhal needed and memory allocaion involved.
This code works for simple strings, but if you think a bi further you may recognize that this will be a pain in the ass already and a bigger one if you create UDs.
That will be a coding nighmare. Sure you can first transform everything o a strin, spli it, process it, join i, put i back and finally decode again in VB.ne. Bu i guess this will eat avery speed boost you want o achive.
But maybee some mor advanced byte and bit eater has a splendid idea. Or maybee someone with asm.
I usually just deal with applicaion programming. In fac autocad mainly in VBA. For an civil-engineer it is the most convinient wa to get a result.
Easy and fast enought for mos cases.
But there you can not reach all aspects of the acad api. They left a "few" newer things out . And for sure if you really has to do it in .net then just as less as possible. I really do no like the .net style. Maybee im a bit too oldschool and oldtimer.
Anyhow. My dream would be to write a nice tiny programm which you just let run over the freebasic code and ge the interfaces for VBA and .NE created on the fly :) That is no imossible but the .net thing suxx at the moment.
Thanks so far for the audience and help.
Thomas
Bu as you can see there is a nasty Marhal needed and memory allocaion involved.
This code works for simple strings, but if you think a bi further you may recognize that this will be a pain in the ass already and a bigger one if you create UDs.
That will be a coding nighmare. Sure you can first transform everything o a strin, spli it, process it, join i, put i back and finally decode again in VB.ne. Bu i guess this will eat avery speed boost you want o achive.
But maybee some mor advanced byte and bit eater has a splendid idea. Or maybee someone with asm.
I usually just deal with applicaion programming. In fac autocad mainly in VBA. For an civil-engineer it is the most convinient wa to get a result.
Easy and fast enought for mos cases.
But there you can not reach all aspects of the acad api. They left a "few" newer things out . And for sure if you really has to do it in .net then just as less as possible. I really do no like the .net style. Maybee im a bit too oldschool and oldtimer.
Anyhow. My dream would be to write a nice tiny programm which you just let run over the freebasic code and ge the interfaces for VBA and .NE created on the fly :) That is no imossible but the .net thing suxx at the moment.
Thanks so far for the audience and help.
Thomas
Code: Select all
Extern "windows-ms"
sub freemem(p as any ptr) export
deallocate(p)
end Sub
Function s2zsp (s As String ) As ZString Ptr
Dim As ZString Ptr pstr
pstr = Allocate( len(s) * SizeOf(ZString) )
*pstr = S
Return pstr
End Function
Function getstr(Byval si As ZString Ptr) As ZString Ptr Export
dim s as string
Return s2zsp(UCase (*si))
End Function
'end extern
and VB.net:
Imports System
Imports System.Runtime.InteropServices
Module Module1
<DllImport("D:\FREEBASIC\Projects\fbnet\fbnet.dll", EntryPoint:="freemem")>
Sub freemem_native(p As IntPtr)
End Sub
<DllImport("D:\FREEBASIC\Projects\fbnet\fbnet.dll", EntryPoint:="getstr")>
Function getstr_native(ByVal s As String) As IntPtr
End Function
Function FBSTR(strptr As IntPtr) As String
Dim s As String = Marshal.PtrToStringAnsi(strptr)
freemem_native(strptr)
Return s
End Function
Function getstr() As String
Dim strptr As IntPtr = getstr_native("asaa")
Dim s As String = Marshal.PtrToStringAnsi(strptr)
freemem_native(strptr)
Return s
End Function
Sub Main()
Console.WriteLine("from FreeBasic: " & FBSTR(getstr_native("123456hjk")))
Console.ReadKey()
End Sub
end module
Last edited by counting_pine on Feb 13, 2018 13:27, edited 1 time in total.
Reason: Added [code]...[/code] markers
Reason: Added [code]...[/code] markers