Page 1 of 1

Triangulating between NeoBook, PowerBasic and Visual Basic

PostPosted: Wed Mar 27, 2013 2:18 pm
by David de Argentina
Hi Dave,

I'm doing small samples in order to triangulate between NeoBook, PowerBasic and Visual Basic 6.

First Step: I created a DLL using Visual Basic. DLL is a standart DLL, not an ActiveX DLL.
DLL is called "TestDLL.Dll". It has this Functions:

Code: Select all
Function addition(ByVal a As Double, ByVal B As Double) As Double
  addition = a + B
End Function

Function hola() As String
hola = "FGH"
End Function


Second Step: I created a EXE using PowerBasic. This EXE is the begin of a NeoBook plugin.
This DLL has this code:

Code: Select all
DECLARE Function hola LIB "TestDLL.dll" ALIAS "hola" () as string
DECLARE FUNCTION addition LIB "TestDLL.dll" ALIAS "addition" (BYVAL A AS DOUBLE, BYVAL B AS DOUBLE) AS DOUBLE

FUNCTION PBMAIN()
LOCAL RES AS DOUBLE, stxt AS STRING, dato AS STRING
RES = addition (123,469)
MSGBOX STR$(RES)
MSGBOX hola()
END FUNCTION


When i run the PowerBasic EXE, the first action ( RES = addition (123,469) ) is executed fine, and the result is correct.

The Second action, "MSGBOX hola()" returns the character "F", not the correct "FGH" value that returns the VisualBasic hola function.

I think there is a problem with the definition of the return parameter datatype from the PowerBasic Function.

Do you know any about this ?
Any ideas ?

Thanks in advance,
David de Argentina

Re: Triangulating between NeoBook, PowerBasic and Visual Bas

PostPosted: Thu Mar 28, 2013 3:30 pm
by Neosoft Support
It may be that the type "string" is different between VB and PB. Or that the calling convention (the method used to "export" the function) is not the same.

Re: Triangulating between NeoBook, PowerBasic and Visual Bas

PostPosted: Sat Mar 30, 2013 2:33 am
by pfisterhamj
Hello,

may this helps.

Within windows the string return is not always possible. Within C or no problem because you strings are always referenced. With PowerBasic 10 I use the following:

1. Change the declare
Code: Select all
DECLARE Function hola LIB "TestDLL.dll" ALIAS "hola" () as DWORD


2. Define a little helper function. I think the unicodeversion should work (but I'm not sure).

Unicode version
Code: Select all
FUNCTION GetDLLStr(dwInput AS DWORD) AS WSTRING

    LOCAL varnamePtr AS WSTRINGZ PTR
    LOCAL varname AS WSTRING

    varnamePtr = dwInput
    varname = @varnamePtr

    FUNCTION = varname

END FUNCTION


non-unicode version

Code: Select all
FUNCTION GetDLLStr(dwInput AS DWORD) AS STRING

    LOCAL varnamePtr AS STRINGZ PTR
    LOCAL varname AS STRING

    varnamePtr = dwInput
    varname = @varnamePtr

    FUNCTION = varname

END FUNCTION



3. Usage
Code: Select all
local test as String
local dwTest as dword

dwTest = hola()

test = GetDwordStr(dwTest)



Hope it helps


Best regards
J├╝rgen

Re: Triangulating between NeoBook, PowerBasic and Visual Bas

PostPosted: Sat Mar 30, 2013 3:56 am
by HPW
Doesn't the PB-samples from the neosoft SDK not show the complete interfacing?

Re: Triangulating between NeoBook, PowerBasic and Visual Bas

PostPosted: Sat Mar 30, 2013 10:23 am
by David de Argentina
Thanks Dave, Jurgen & Hans-Peter,

I found some help on the PowerBasic forum, that answered me Visual Basic returns strings as unicode.

PowerBasic ( i use version 8 ) has a ACODE$() function to convert unicode strings to ansi strings, the correct way is:

( into the PowerBasic Function)

Code: Select all
MSGBOX ACODE$(hola())


And works like a charm.

Now, i'm trying to do more complex function: pass a string to the VisualBasic function.

The DLL VisualBasic Function is something like this:

Code: Select all
Function hola(a as string) As String
hola = "hello " + a
End Function


The PowerBasic function is something like this:

Code: Select all
DECLARE Function hola LIB "TestDLL.dll" ALIAS "hola" (byval a as string) as string

FUNCTION PBMAIN()
LOCAL  stxt AS STRING
stxt = UCODE$("David")  ' Convert the ansi string to unicode
MSGBOX ACODE$(hola(stxt))
END FUNCTION


When runs the PowerBasic Program, i receive a GPF error.

How i should send the string ? As a pointer variable and the len of the string ?

Any ideas ?

Hans-Peter: The NeoBook SDK samples sets the way to interface PowerBasic with Neobook. I'm trying to use PowerBasic to connect with a Visual Basic DLL, in order to use PowerBasic as a bridge between NeoBook and VisualBasic. Remember VisualBasic is not a compatible language for NeoBook... directly.

Thanks in advance again,
David de Argentina

Re: Triangulating between NeoBook, PowerBasic and Visual Bas

PostPosted: Mon Apr 01, 2013 12:34 pm
by pfisterhamj
Hello,

VB expects the String as BSTR see: http://msdn.microsoft.com/en-us/library/aa263531%28v=vs.60%29.aspx. This is a string with a header and a null terminated string.

Try a LPSTR. Best represented by ASCIIZ PTR.

Try this (not sure it works):
Code: Select all
DECLARE Function hola LIB "TestDLL.dll" ALIAS "hola" (byval a as asciiz ptr) as string




Best regards

Re: Triangulating between NeoBook, PowerBasic and Visual Bas

PostPosted: Wed Apr 03, 2013 12:40 pm
by David de Argentina
Thanks pfisterhamj,

If i define both (VB & PB) functions parameters as Variant, process works fine.

Thanks again,

David de Argentina