Source language: Translate to:

Triangulating between NeoBook, PowerBasic and Visual Basic

Questions about NeoBook PlugIns

Moderator: Neosoft Support

Triangulating between NeoBook, PowerBasic and Visual Basic

Postby David de Argentina » Wed Mar 27, 2013 2:18 pm

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
User avatar
David de Argentina
 
Posts: 1560
Joined: Mon Apr 04, 2005 4:13 pm
Location: Buenos Aires, Argentina

Re: Triangulating between NeoBook, PowerBasic and Visual Bas

Postby Neosoft Support » Thu Mar 28, 2013 3:30 pm

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.
NeoSoft Support
Neosoft Support
NeoSoft Team
 
Posts: 5603
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA

Re: Triangulating between NeoBook, PowerBasic and Visual Bas

Postby pfisterhamj » Sat Mar 30, 2013 2:33 am

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
pfisterhamj
 
Posts: 39
Joined: Sun Sep 06, 2009 2:56 am

Re: Triangulating between NeoBook, PowerBasic and Visual Bas

Postby HPW » Sat Mar 30, 2013 3:56 am

Doesn't the PB-samples from the neosoft SDK not show the complete interfacing?
Hans-Peter
User avatar
HPW
 
Posts: 2520
Joined: Fri Apr 01, 2005 11:24 pm
Location: Germany

Re: Triangulating between NeoBook, PowerBasic and Visual Bas

Postby David de Argentina » Sat Mar 30, 2013 10:23 am

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
User avatar
David de Argentina
 
Posts: 1560
Joined: Mon Apr 04, 2005 4:13 pm
Location: Buenos Aires, Argentina

Re: Triangulating between NeoBook, PowerBasic and Visual Bas

Postby pfisterhamj » Mon Apr 01, 2013 12:34 pm

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
pfisterhamj
 
Posts: 39
Joined: Sun Sep 06, 2009 2:56 am

Re: Triangulating between NeoBook, PowerBasic and Visual Bas

Postby David de Argentina » Wed Apr 03, 2013 12:40 pm

Thanks pfisterhamj,

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

Thanks again,

David de Argentina
User avatar
David de Argentina
 
Posts: 1560
Joined: Mon Apr 04, 2005 4:13 pm
Location: Buenos Aires, Argentina


Return to PlugIn Discussions

Who is online

Users browsing this forum: No registered users and 1 guest

cron