Silverfrost Forums

Welcome to our forums

MBConvertMBToUnicode

1 Feb 2019 2:26 #23197

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

1 Feb 2019 9:30 #23198

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.

2 Feb 2019 12:44 #23199

Yes please! That would be fantastic...

2 Feb 2019 10:31 #23200

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.

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
4 Feb 2019 12:46 #23204

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!

20 Apr 2019 6:57 #23534

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?

8 May 2019 10:46 #23590

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.

!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
9 May 2019 9:27 #23591

Thank you Stam.

Please login to reply.