How to return string from callfunction?

Just starting out? Need help? Post your questions and find answers here.
Bonne_den_kule
Addict
Addict
Posts: 841
Joined: Mon Jun 07, 2004 7:10 pm

How to return string from callfunction?

Post by Bonne_den_kule »

How do i return a string from a dll function?
Callfunction can't return a string.
Proteus
Enthusiast
Enthusiast
Posts: 113
Joined: Wed Sep 17, 2003 8:04 pm
Location: The Netherlands

Post 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.
P4 2.4GHz, 256 MB, WinXP Pro, onboard video&audio.
The Programmer's Drinking Song:
"99 little bugs in the code,
99 little bugs.
Fix one bug, recompile
100 little bugs in the code."
fweil
Enthusiast
Enthusiast
Posts: 725
Joined: Thu Apr 22, 2004 5:56 pm
Location: France
Contact:

Post 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
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

..

Post 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
Proteus
Enthusiast
Enthusiast
Posts: 113
Joined: Wed Sep 17, 2003 8:04 pm
Location: The Netherlands

Post 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
P4 2.4GHz, 256 MB, WinXP Pro, onboard video&audio.
The Programmer's Drinking Song:
"99 little bugs in the code,
99 little bugs.
Fix one bug, recompile
100 little bugs in the code."
Bonne_den_kule
Addict
Addict
Posts: 841
Joined: Mon Jun 07, 2004 7:10 pm

Post by Bonne_den_kule »

I need to get a string from a 3rd party library, not from a library that I have made myself
Froggerprogger
Enthusiast
Enthusiast
Posts: 423
Joined: Fri Apr 25, 2003 5:22 pm
Contact:

Post 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]
%1>>1+1*1/1-1!1|1&1<<$1=1
Post Reply