PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 6 7 [8] 9 10

Author Topic: CWindow Release Candidate 31  (Read 2172 times)

José Roca

  • Moderator
  • Master FireFly Member
  • *****
  • Posts: 2732
    • José Roca Software
Re: CWindow Release Candidate 31
« Reply #105 on: September 08, 2017, 07:26:11 PM »

I have changed the code to not use SetLastError, because it can't be trusted. You can call a function or method that succeeds, but GetLastError can return an unmeaningful error.

Code: [Select]
'#CONSOLE ON
#define UNICODE
#INCLUDE ONCE "windows.bi"
#INCLUDE ONCE "Afx/CCLRHost.inc"
USING Afx

' // Create an instance of the CCLRHost class
DIM pCLRHost AS CCLRHost
print pCLRHost.GetLastResult

' // Create a custom domain
DIM pDomain AS Afx__AppDomain PTR = pCLRHost.CreateDomain("MyDomain")
print HEX(pCLRHost.GetLastResult, 8)
IF pDomain THEN pCLRHost.UnloadDomain(pDomain)


PRINT
PRINT "Press any key..."
SLEEP

José Roca

  • Moderator
  • Master FireFly Member
  • *****
  • Posts: 2732
    • José Roca Software
Re: CWindow Release Candidate 31
« Reply #106 on: September 08, 2017, 07:47:43 PM »

I even have tried using a VTable instead of abstract methods with the same result.

Paul Squires

  • Administrator
  • Master FireFly Member
  • *****
  • Posts: 8090
  • Windows 10
    • PlanetSquires Software
Re: CWindow Release Candidate 31
« Reply #107 on: September 08, 2017, 10:39:49 PM »

I wonder if it could be the string that is being passed to CreateDomain. Is CreateDomain expecting a .dot net string class rather than a UTF-16 string of characters? The documentation seems to say that it is a UTF-16 string of characters.
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

José Roca

  • Moderator
  • Master FireFly Member
  • *****
  • Posts: 2732
    • José Roca Software
Re: CWindow Release Candidate 31
« Reply #108 on: September 08, 2017, 11:03:46 PM »

Code: [Select]
HRESULT CreateDomain ( 
    [in] LPWSTR    pwzFriendlyName, 
    [in] IUnknown* pIdentityArray, 
    [out] void   **pAppDomain 
); 

It is a LPWSTR, i.e. a pointer to a WSTR (null terminated unicode string). The ICorRuntimeHost interface is a low-level COM interface, not a .NET class. With PowerBasic, it works using a WSTRINGZ. I have tried everything and I always get the same error.
« Last Edit: September 08, 2017, 11:08:43 PM by José Roca »
Logged

Paul Squires

  • Administrator
  • Master FireFly Member
  • *****
  • Posts: 8090
  • Windows 10
    • PlanetSquires Software
Re: CWindow Release Candidate 31
« Reply #109 on: September 08, 2017, 11:19:51 PM »

You are passing NULL to pIdentityArray but in the PowerBasic it seems you are passing an actual value. The docs say that NULL is valid but maybe it is worth a look.
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

José Roca

  • Moderator
  • Master FireFly Member
  • *****
  • Posts: 2732
    • José Roca Software
Re: CWindow Release Candidate 31
« Reply #110 on: September 08, 2017, 11:35:57 PM »

With PowerBASIC the parameter is optional and a NULL is also being passed. The returned message does not make sense to me. It is not even listed in the list of possible errors in the MSDN documentation for the CreateDomain method.

José Roca

  • Moderator
  • Master FireFly Member
  • *****
  • Posts: 2732
    • José Roca Software
Re: CWindow Release Candidate 31
« Reply #111 on: September 08, 2017, 11:53:12 PM »

And CreateDomainEx also fails with the same error. These are the only two that have an string parameter in this interface, so it is my main suspect.

José Roca

  • Moderator
  • Master FireFly Member
  • *****
  • Posts: 2732
    • José Roca Software
Re: CWindow Release Candidate 31
« Reply #112 on: September 09, 2017, 12:18:46 AM »

I also have tried

Code: [Select]
   DIM ppEvidence AS IUnknown PTR
   m_pCorRuntimeHost->CreateEvidence(@ppEvidence)
   DIM hr AS HRESULT = m_pCorRuntimeHost->CreateDomain(@wszFriendlyName, ppEvidence, cast(ANY PTR, @pUnk))

and also fails.

Looks like the string parameter is the problem, but I have also tried passing a BSTR and even a CWSTR and a ZSTRING and it fails. I don't understand why.

Paul Squires

  • Administrator
  • Master FireFly Member
  • *****
  • Posts: 8090
  • Windows 10
    • PlanetSquires Software
Re: CWindow Release Candidate 31
« Reply #113 on: September 11, 2017, 09:56:45 AM »

Have you been able to figure out the string problem? Problems like this must drive you crazy! :)  :)  :)
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

José Roca

  • Moderator
  • Master FireFly Member
  • *****
  • Posts: 2732
    • José Roca Software
Re: CWindow Release Candidate 31
« Reply #114 on: September 11, 2017, 10:19:59 AM »

No. I have tried everything and always get the same error. Yet similar code works with PowerBasic. Everything else works, so we can use it using the default domain. Custom domains aren't indispensable, just convenient for some tasks.

Some time ago I had a problem to add OpenGL support to the graphic control. Some months later, I tried again and it worked. I can't tell you where was the problem, because I had discarded the code and started from scratch.

Meanwhile, I have been working writing wrapper functions to support Complex numbers. Instead of a class, this time I have used plain functions and use the Afx namespace to avoid conflicts.

Code: [Select]
#include once "AfxComplex.inc"

DIM cpx1 AS _complex = (3, 4)
DIM cpx2 AS _complex = (5, 6)
cpx1 = cpx1 + cpx2
print Afx.Cstr(cpx1)

There are a lot of math functions, most of which I have already checked that return the right results. The most complex functions are an adaptation of the ones from the GSL - GNU Scientific Library, which unfortunately is LGPL.

« Last Edit: September 11, 2017, 12:54:24 PM by José Roca »
Logged

Johan Klassen

  • FireFly3 Registered User
  • Little Newbie FireFly
  • *
  • Posts: 19
  • FF3 User
Re: CWindow Release Candidate 31
« Reply #115 on: September 12, 2017, 10:03:55 AM »

hello José Roca
just in case you need to have a look at complex functions implementation there's this library http://www.wolfgang-ehrhardt.de/misc_en.html#damath
Quote
License

(C) Copyright 2002-2017 Wolfgang Ehrhardt

Copying Conditions

This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.

Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.

2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.

3. This notice may not be removed or altered from any source distribution.
Logged

José Roca

  • Moderator
  • Master FireFly Member
  • *****
  • Posts: 2732
    • José Roca Software
Re: CWindow Release Candidate 31
« Reply #116 on: September 12, 2017, 03:34:09 PM »

Thanks for the link. I already have implemented a big amount of functions and, more important, I have checked that all of them work correctly. Don't know if I will add more. Math is not my forte.
« Last Edit: September 12, 2017, 05:51:48 PM by José Roca »
Logged

José Roca

  • Moderator
  • Master FireFly Member
  • *****
  • Posts: 2732
    • José Roca Software
Re: CWindow Release Candidate 31
« Reply #117 on: September 14, 2017, 11:58:24 PM »

I'm replacing the GSL functions with translations of the .NET System.Numerics/System/Numerics/Complex.cs class (source code: https://github.com/Microsoft/referencesource/blob/master/System.Numerics/System/Numerics/Complex.cs ) and apparently the code for the Asin and Acos methods is reversed! I have checked results with GSL and from MATLAB examples, and Asin returns the expected results for Acos, and viceversa.

The reason of the replacement is because this .NET class as a MIT license, whereas GSL as a GPL license.

José Roca

  • Moderator
  • Master FireFly Member
  • *****
  • Posts: 2732
    • José Roca Software
Re: CWindow Release Candidate 31
« Reply #118 on: September 15, 2017, 01:42:41 AM »

And also differs in the sign of the imaginary part, + instead of - (according the other sources). Looks like they have got everything reversed. Anybody has the means to ascertain which source is right?

Code: [Select]
' ========================================================================================
' * Returns the complex arcsine of a complex number.
' The branch cuts are on the real axis, less than -1 and greater than 1.
' Example:
'   DIM z AS _complex = (1, 1)
'   z = AfxCArcSin(z)
'   PRINT AfxCStr(z)
' Output: 0.6662394324925152 +1.061275061905036 * i
' ========================================================================================
' ========================================================================================
' - NET 4.7 code:
' public static Complex Acos(Complex value) /* Arccos */
' { return (-ImaginaryOne) * Log(value + ImaginaryOne*Sqrt(One - (value * value))); }
' Note: Apparently, .NET has got the code for the Asin and Acos function revesed!
' It also returns -1.061275061905036 * i instead of +1.061275061905036 * i in the above example.
' ========================================================================================
PRIVATE FUNCTION AfxCArcSin (BYREF value AS _complex) AS _complex
   DIM ImaginaryOne AS _complex = TYPE<_complex>(0.0, 1.0)
   DIM One AS _complex = TYPE<_complex>(1.0, 0.0)
'   RETURN (-ImaginaryOne) * AfxCLog(value + ImaginaryOne * AfxCSqr(One - (value * value)))
   DIM z AS _complex = AfxCLog(value + ImaginaryOne * AfxCSqr(One - (value * value)))
   RETURN TYPE<_complex>(z.y, z.x)
END FUNCTION
' ========================================================================================

Code: [Select]
' ========================================================================================
' * Returns the complex arccosine of a complex number.
' The branch cuts are on the real axis, less than -1 and greater than 1.
' Example:
'   DIM z AS _complex = (1, 1)
'   z = AfxCArcCos(z)
'   print AfxCStr(z)
' Output: 0.9045568943023814 -1.061275061905036 * i
' ========================================================================================
' ========================================================================================
' - NET 4.7 code:
' public static Complex Asin(Complex value) /* Arcsin */
' { return (-ImaginaryOne) * Log(ImaginaryOne * value + Sqrt(One - value * value)); }
' Note: Apparently, .NET has got the code for the Asin and Acos function revesed!
' It also returns +1.061275061905036 * i instead of -1.061275061905036 * i in the above example.
' ========================================================================================
PRIVATE FUNCTION AfxCArcCos (BYREF value AS _complex) AS _complex
   DIM ImaginaryOne AS _complex = TYPE<_complex>(0.0, 1.0)
   DIM One AS _complex = TYPE<_complex>(1.0, 0.0)
'   RETURN (-ImaginaryOne) * AfxCLog(ImaginaryOne * value + AfxCSqr(One - value * value))
   DIM z AS _complex = AfxCLog(ImaginaryOne * value + AfxCSqr(One - value * value))
   RETURN TYPE<_complex>(z.y, z.x)
END FUNCTION
' ========================================================================================

José Roca

  • Moderator
  • Master FireFly Member
  • *****
  • Posts: 2732
    • José Roca Software
Re: CWindow Release Candidate 31
« Reply #119 on: September 15, 2017, 02:09:58 AM »

Another problem with the sign in the arctangent function.

Code: [Select]
' ========================================================================================
' * This function returns the complex arctangent of a complex number.
' The branch cuts are on the imaginary axis, below -i and above i.
' Example:
'   DIM z AS _complex = (1, 1)
'   z = AfxCArcTan(z)
'   PRINT AfxCStr(z)
' Output: 1.017221967897851 +0.4023594781085251 * i
' ========================================================================================
' ========================================================================================
' - NET 4.7 code:
' public static Complex Atan(Complex value) /* Arctan */
' {
'    Complex Two = new Complex(2.0, 0.0);
'    return (ImaginaryOne / Two) * (Log(One - ImaginaryOne * value) - Log(One + ImaginaryOne * value));
' }
' Note: It returns -0.4023594781085251 * i instead of +0.4023594781085251 * i, so I have
' needed to use a workaround.
' ========================================================================================
' ========================================================================================
PRIVATE FUNCTION AfxCArcTan (BYREF value AS _complex) AS _complex
   DIM ImaginaryOne AS _complex = TYPE<_complex>(0.0, 1.0)
   DIM One AS _complex = TYPE<_complex>(1.0, 0.0)
   DIM Two AS _complex = TYPE<_complex>(2.0, 0.0)
'   RETURN (ImaginaryOne / Two) * (AfxCLog(One - ImaginaryOne * value) - AfxCLog(One + ImaginaryOne * value))
   DIM z AS _complex = AfxCLog(One - ImaginaryOne * value) - AfxCLog(One + ImaginaryOne * value)
   z /= 2 : DIM temp AS DOUBLE = z.x : z.x = z.y : z.y = temp
   RETURN z
END FUNCTION
' ========================================================================================
Pages: 1 ... 6 7 [8] 9 10