View previous topic :: View next topic |
Author |
Message |
StamK
Joined: 12 Oct 2016 Posts: 159
|
Posted: Fri Feb 01, 2019 3:26 pm Post subject: MBConvertMBToUnicode |
|
|
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 |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7925 Location: Salford, UK
|
Posted: Fri Feb 01, 2019 10:30 pm Post subject: |
|
|
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 |
|
|
StamK
Joined: 12 Oct 2016 Posts: 159
|
Posted: Sat Feb 02, 2019 1:44 am Post subject: |
|
|
Yes please! That would be fantastic... |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7925 Location: Salford, UK
|
Posted: Sat Feb 02, 2019 11:31 am Post subject: |
|
|
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 |
|
|
John-Silver
Joined: 30 Jul 2013 Posts: 1520 Location: Aerospace Valley
|
Posted: Sat Feb 02, 2019 6:07 pm Post subject: |
|
|
this would be a more appropriate message for it to print ....
Quote: | еще раз товарищ Павел вытаскивает кролика из шляпы! |
_________________ ''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 ... " |
|
Back to top |
|
|
StamK
Joined: 12 Oct 2016 Posts: 159
|
Posted: Mon Feb 04, 2019 1:46 pm Post subject: |
|
|
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 |
|
|
Ryan
Joined: 25 Feb 2016 Posts: 110
|
Posted: Sat Apr 20, 2019 7:57 pm Post subject: |
|
|
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 |
|
|
StamK
Joined: 12 Oct 2016 Posts: 159
|
Posted: Wed May 08, 2019 11:46 pm Post subject: |
|
|
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 |
|
|
Ryan
Joined: 25 Feb 2016 Posts: 110
|
Posted: Thu May 09, 2019 10:27 am Post subject: |
|
|
Thank you Stam. |
|
Back to top |
|
|
|