Page 1 of 1

How to return string from callfunction?

Posted: Wed Jul 21, 2004 11:34 am
by Bonne_den_kule
How do i return a string from a dll function?
Callfunction can't return a string.

Posted: Wed Jul 21, 2004 11:50 am
by Proteus
You need to make the string variable in the DLL global.

If that doesn't work, and callfunction( returns a number, that number should be a pointer to the string.

Posted: Wed Jul 21, 2004 12:06 pm
by fweil
I guess this example may help :

Code: Select all

  If OpenWindow(0, 0, 0, 320, 240, 0, "") ; just for test purpose
  EndIf
  
  If OpenLibrary(0, "USER32.DLL")
      ClassName.s = Space(100)
      Debug CallFunction(0, "GetClassNameA", WindowID(), @ClassName, 100)
      Debug ClassName
      CloseLibrary(0)
  EndIf
End
Rgrds

..

Posted: Wed Jul 21, 2004 4:51 pm
by NoahPhense
Yeah, like Proteus said.

DLL

Code: Select all

Global Returnvalue$ 

ProcedureDLL proc1(Name$) 
  Returnvalue$ = "Hello "+Name$
  
  ProcedureReturn @ReturnValue$ 
EndProcedure
***

EXE (you dont have to use callfunction fast - i just like it)

Code: Select all

#dll = 1

Global ffName.l

res = OpenLibrary(#dll, "testdll.dll")

If res
  ffName.l = IsFunction(#dll, "proc1")
Else 
  MessageBox_(0, "Error", "could not locate dll", 0)
  End
EndIf 

Procedure.l doesthiswork(name.s)
  ProcedureReturn CallFunctionFast(ffName, name)
EndProcedure

MessageBox_(0, doesthiswork("World"), "...", 0)


  CloseLibrary(0) 
End
- np

Posted: Wed Jul 21, 2004 5:03 pm
by Proteus
EEK! Pointers!
Change

Code: Select all

Procedure.l doesthiswork(name.s) 
  ProcedureReturn CallFunctionFast(ffName, name) 
EndProcedure 
to

Code: Select all

Procedure.s doesthiswork(name.s) 
  ProcedureReturn PeekS(CallFunctionFast(ffName, name))
EndProcedure
And you can use the string directly in PB. :D

Posted: Wed Jul 21, 2004 9:06 pm
by Bonne_den_kule
I need to get a string from a 3rd party library, not from a library that I have made myself

Posted: Wed Jul 21, 2004 11:29 pm
by Froggerprogger
Perhaps the following would work (if the returnvalue is a pointer to a nullterminated string)

Code: Select all

result.s = PeekS(CallFunction(...))

[edit]
Damn, I should read all the ohter posts before posting, sorry :roll:
... so Proteus way should do it.
[/edit]