It is currently Mon Aug 20, 2018 8:36 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Some help with a dylib, please
PostPosted: Tue Jun 12, 2018 12:38 pm 
Offline
User
User

Joined: Sun Jun 10, 2018 12:54 pm
Posts: 30
I have been successful in creating a dylib which takes input parameters and exports numeric data (all types well).

However, I am having great difficulties in exporting (Returning from procedure) a string.

A code snippet is as follows:
Code:
Global ReturnString.s

ProcedureDLL.s GetString() ;Create unicode executable gives only first character
 
   ReturnString = "More then H"
   ProcedureReturn ReturnString

EndProcedure

This compiles correctly into a dylib.

The declaration in my source code (Xojo) is:
Code:
Declare Function GetString Lib libname As CString


The returned value that I get from the procedure is just the first character - "M".

Can anybody help me?


Top
 Profile  
Reply with quote  
 Post subject: Re: Some help with a dylib, please
PostPosted: Tue Jun 12, 2018 1:30 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 1326
Location: Germany
Purebasic v5.6x is Unicode
Code:
Threaded ReturnString.s

ProcedureDLL.i GetString()
 
   ReturnString = "More then H"
   ProcedureReturn @ReturnString

EndProcedure


I don´t know this right "WString as Result
Quote:
Declare Function GetString Lib libname As WString

_________________
My Projects OOP-BaseClass / OOP-BaseClassDispatch / Event-Designer /
PB v3.30 / v5.60 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: Some help with a dylib, please
PostPosted: Wed Jun 13, 2018 12:52 am 
Offline
User
User

Joined: Sun Jun 10, 2018 12:54 pm
Posts: 30
Thank you, I will try that.


Top
 Profile  
Reply with quote  
 Post subject: Re: Some help with a dylib, please
PostPosted: Wed Jun 13, 2018 9:22 am 
Offline
User
User

Joined: Sun Jun 10, 2018 12:54 pm
Posts: 30
The code that you posted works inasmuch as I now get a string returned from my dylib.

Unfortunately, this string is a 4 byte string rather than a two byte string so I get every other byte as a zero. This, of course, is not readable when displayed as the string

"More then H"

is returned as

"M*o*r*e* *t*h*e*n* *H*" (asterisks are Chr(0)).

This is because MacOS sees a String as 4 bytes. I tried using CString in my declare but this did not work, only String works (as you suggested).

Any further advice?


Top
 Profile  
Reply with quote  
 Post subject: Re: Some help with a dylib, please
PostPosted: Wed Jun 13, 2018 9:31 am 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 1326
Location: Germany
I think go back to CString...

Edit
Code:
;-TOP
CompilerIf #PB_Compiler_Version < 550
  Procedure Ascii(string.s)
    Protected *result
    *result = AllocateMemory(Len(String) + 1)
    If *result
      PokeS(*result, String, -1, #PB_Ascii)
    EndIf
    ProcedureReturn *result
  EndProcedure
 
  Procedure UTF8(string.s)
    Protected *result
    *result = AllocateMemory(StringByteLength(String, #PB_UTF8) + 1)
    If *result
      PokeS(*result, String, -1, #PB_UTF8)
    EndIf
    ProcedureReturn *result
  EndProcedure
CompilerEndIf

Threaded *ReturnString

ProcedureDLL.i GetString()
  If *ReturnString
    FreeMemory(*ReturnString)
  EndIf
  *ReturnString = Ascii("Hello World")
  ProcedureReturn *ReturnString
EndProcedure

_________________
My Projects OOP-BaseClass / OOP-BaseClassDispatch / Event-Designer /
PB v3.30 / v5.60 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: Some help with a dylib, please
PostPosted: Wed Jun 13, 2018 3:17 pm 
Offline
User
User

Joined: Sun Jun 10, 2018 12:54 pm
Posts: 30
Absolutely perfect.

Thank you so much, I have been agonising over this for four whole days.

You are a star.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: IceSoft and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye