DLL - Call results improvement?

Just starting out? Need help? Post your questions and find answers here.
User avatar
kpeters58
Enthusiast
Enthusiast
Posts: 341
Joined: Tue Nov 22, 2011 5:11 pm
Location: Kelowna, BC, Canada

DLL - Call results improvement?

Post by kpeters58 »

Hi all,

just built a DLL as per code below. When setting

Code: Select all

#BUILD_DLL = #False
and thus testing it, I get the DLL's Messagerequester displaying my message just fine. I do, however, get a '0' as Result of CallFunction, indicating a failure (as per PB Help) and the Debug window pops up.

Help file:
Return value

Returns the return-value of the called function or zero if the library does not contain a function with the given name.
So to me this looks like the called function returns '0' (as per help) - now we have a situation where we don't know if the called proc failed (in my case we see the requester, so we know it's ok - but in other cases we will be in the dark).

I could give it a dummy return value <> '0' so it becomes testable again - or Fred could resolve this ambiguity in code... or at least the help could be updated to point this potential pitfall out to unsuspecting users (like me today)...

Is this a valid assessment or am I missing something here?

Code: Select all

#BUILD_DLL = #False

CompilerIf #BUILD_DLL 

  ProcedureDLL DLLRequester(Msg$)
    MessageRequester("DLL Requester", Msg$)
  EndProcedure

CompilerElse
  EnableExplicit
  
  #LibHandle = 1
  Define Result
  
  If OpenLibrary(#LibHandle, "InstallHelper.dll") ;;; Or OpenLibrary(0, "InstallHelper.so")
    Result = CallFunction(#LibHandle, "DLLRequester", @"I've got to get a message to you ...")  
    If Result = 0
      Debug "Call function failed"
    EndIf
  Else
    Debug "Lib open failed"
  EndIf
    
CompilerEndIf
PB 5.73 on Windows 10 & OS X High Sierra
User avatar
mk-soft
Always Here
Always Here
Posts: 5409
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: DLL - Call results improvement?

Post by mk-soft »

Check with GetFunction(...) or the result of function have never #NULL
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
kpeters58
Enthusiast
Enthusiast
Posts: 341
Joined: Tue Nov 22, 2011 5:11 pm
Location: Kelowna, BC, Canada

Re: DLL - Call results improvement?

Post by kpeters58 »

mk-soft wrote:Check with GetFunction(...) or the result of function have never #NULL
True, that's a fourth option - albeit an extra function call.

I still feel that the help for CallProcedure/CallCProcedure should include a warning along the lines:

OLD
Return value
Returns the return-value of the called function or zero if the library does not contain a function with the given name.
NEW
Return value
Returns the return-value (which may be zero) of the called function or zero if the library does not contain a function with the given name.
Use GetFunction() to test for the existence of a DLL function.
PB 5.73 on Windows 10 & OS X High Sierra
User avatar
HeX0R
Addict
Addict
Posts: 992
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: DLL - Call results improvement?

Post by HeX0R »

CallFunction is outdated anyway, I didn't use that anymore since years.
Prototypes should be used, they are much more flexible and powerful.
Then you will see via GetFunction if a procedure exists or not.
Post Reply