forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

MBConvertMBToUnicode

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General
View previous topic :: View next topic  
Author Message
StamK



Joined: 12 Oct 2016
Posts: 110

PostPosted: Fri Feb 01, 2019 3:26 pm    Post subject: MBConvertMBToUnicode Reply with quote

Is there in silverfrost an intrinsic similar to MBConvertMBToUnicode (available in Intel Fortran)?

We need to pass a licence key as unicode to a C++ call which will then check if it is correct. The actual key is a string in Fortran but needs to be converted to unicode.

Thanks
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 6002
Location: Salford, UK

PostPosted: Fri Feb 01, 2019 10:30 pm    Post subject: Reply with quote

There is no FTN95 intrinsic as such but it should be possible to directly call the Microsoft API function MultiByteToWideChar. I can try to put together some illustrative code if you need it.
Back to top
View user's profile Send private message
StamK



Joined: 12 Oct 2016
Posts: 110

PostPosted: Sat Feb 02, 2019 1:44 am    Post subject: Reply with quote

Yes please! That would be fantastic...
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 6002
Location: Salford, UK

PostPosted: Sat Feb 02, 2019 11:31 am    Post subject: Reply with quote

Here is some sample code. The code page (CP_UTF8) and flag (MB_PRECOMPOSED) will depend on your context. The file was saved using Plato with "Advanced Save Options" as "UNICODE(UTF-8 without signature)".

The text says "Hello World" in Russian.

Code:
PROGRAM main
STDCALL MultiByteToWideChar 'MultiByteToWideChar'(VAL,VAL,STRING,VAL,REF,VAL):INTEGER*4
INTEGER count
INTEGER,PARAMETER::CP_UTF8=65001,MB_PRECOMPOSED=1,NCHARS=256
CHARACTER(NCHARS) str
INTEGER*2 wstr(NCHARS)
str = "Привет, мир"
!str = "Hello World"
count = MultiByteToWideChar(CP_UTF8,MB_PRECOMPOSED,str,LEN_TRIM(str),wstr,NCHARS)
DO i = 1,count
 WRITE(*, '(Z6)') wstr(i)
END DO
END PROGRAM main
Back to top
View user's profile Send private message
John-Silver



Joined: 30 Jul 2013
Posts: 1176
Location: Aerospace Valley

PostPosted: Sat Feb 02, 2019 6:07 pm    Post subject: Reply with quote

this would be a more appropriate message for it to print ....
Quote:
еще раз товарищ Павел вытаскивает кролика из шляпы! Smile

_________________
''Computers (HAL and MARVIN excepted) are incredibly rigid. They question nothing. Especially input data.Human beings are incredibly trusting of computers and don't check input data. Together cocking up even the simplest calculation ... Smile "
Back to top
View user's profile Send private message
StamK



Joined: 12 Oct 2016
Posts: 110

PostPosted: Mon Feb 04, 2019 1:46 pm    Post subject: Reply with quote

Many thanks for that Paul.

Unfortunately the third party C++ DLL doesn't seem to recognise the key passed this way. But I was able to pass it using a STRING keyword with STDCALL, so it wasn't necessary to use the conversion. In their help for Fortran they do say that is is necessary to convert first (for Intel Fortran), so I guess there is no need with Sivlerfrost!
Back to top
View user's profile Send private message
Ryan



Joined: 25 Feb 2016
Posts: 76

PostPosted: Sat Apr 20, 2019 7:57 pm    Post subject: Reply with quote

Stam, I'm working on some licencing code right now and wondered if you'd be able to share your API calls as a sample?

This would help tremendously if you can.

I'm guessing that this is for LimeLM?
Back to top
View user's profile Send private message
StamK



Joined: 12 Oct 2016
Posts: 110

PostPosted: Wed May 08, 2019 11:46 pm    Post subject: Reply with quote

For some reason I don't get notifications when somebody replies to my thread.

Anyway this was for LIBXL, below is an example (could be useful perhaps). Libxl module is provided by LIBXL themselves.


Code:
 
!ftn95$free
  subroutine xlBookSetKeyPrivateString(handle,name,key)
  stdcall xlBookSetKeyPrivateString  'xlBookSetKeyA'(val, string, string)
  ! ---!DEC$ATTRIBUTES REFERENCE :: name 
  ! ---!DEC$ATTRIBUTES REFERENCE :: key           
  integer*4 handle
  character*(*) :: name
  character*(*) :: key
  end subroutine
 
 
program main
  use libxl

  integer*4 handle
  character(len=20) filename, filename_out
 


  handle = xlCreateXMLBook()
  print*,"handle=",handle
 
  call  xlBookSetKeyPrivateString(handle,"username", &
    "secretkey")
 
  filename="example.xlsx"
  iret=xlBookLoad(handle,trim(filename)//CHAR(0))
  print*,"iret=",iret         
   
                                               
  filename_out = "exampleout.xlsx"
  iret = xlBookSave(handle,filename_out)
  print*,"iret xlBookSave=",iret
 
  call xlBookRelease(handle)
end program
Back to top
View user's profile Send private message
Ryan



Joined: 25 Feb 2016
Posts: 76

PostPosted: Thu May 09, 2019 10:27 am    Post subject: Reply with quote

Thank you Stam.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group