How do i return a string from a dll function?
Callfunction can't return a string.
How to return string from callfunction?
-
- Addict
- Posts: 841
- Joined: Mon Jun 07, 2004 7:10 pm
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.
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."
The Programmer's Drinking Song:
"99 little bugs in the code,
99 little bugs.
Fix one bug, recompile
100 little bugs in the code."
I guess this example may help :
Rgrds
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
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.
- NoahPhense
- Addict
- Posts: 1999
- Joined: Thu Oct 16, 2003 8:30 pm
- Location: North Florida
..
Yeah, like Proteus said.
DLL
***
EXE (you dont have to use callfunction fast - i just like it)
- np
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
EEK! Pointers!
Change
to
And you can use the string directly in PB. 
Change
Code: Select all
Procedure.l doesthiswork(name.s)
ProcedureReturn CallFunctionFast(ffName, name)
EndProcedure
Code: Select all
Procedure.s doesthiswork(name.s)
ProcedureReturn PeekS(CallFunctionFast(ffName, name))
EndProcedure

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."
The Programmer's Drinking Song:
"99 little bugs in the code,
99 little bugs.
Fix one bug, recompile
100 little bugs in the code."
-
- Addict
- Posts: 841
- Joined: Mon Jun 07, 2004 7:10 pm
-
- Enthusiast
- Posts: 423
- Joined: Fri Apr 25, 2003 5:22 pm
- Contact:
Perhaps the following would work (if the returnvalue is a pointer to a nullterminated string)
[edit]
Damn, I should read all the ohter posts before posting, sorry :roll:
... so Proteus way should do it.
[/edit]
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