CWindow Release Candidate 31

Started by José Roca, August 06, 2017, 03:21:36 PM

Previous topic - Next topic

Paul Squires

Ahhhhh.... now I understand. You only need to pass that value and not a full path. Got it.
Seems like version 4.5 would be the version to support as it requires Vista and I assume it is installed on all machines. I wonder if that's true.

Paul Squires
PlanetSquires Software

José Roca

In the beginning (version 1 and 2) you had to install the Framework, but now it comes pre-installed. I could have added a method to support version 2, but why bother? We don't support Windows 2000 and XP.

José Roca

#92
I can't understand why calling the method below fails with an out of memory error in the call to m_pCorRuntimeHost->CreateDomain. The same code, but using the PowerBasic syntax, works with PowerBasic.


' ========================================================================================
' Creates an application domain.
' Note: Does not work. Returns error COR_E_OUTOFMEMORY (&h8007000E) in the call to CreateDomain.
' ========================================================================================
PRIVATE FUNCTION CCLRHost.CreateDomain (BYREF wszFriendlyName AS WSTRING) AS Afx__AppDomain PTR
   DIM pUnk AS Afx_IUnknown PTR, pDomain AS Afx__AppDomain PTR
   DIM hr AS HRESULT = m_pCorRuntimeHost->CreateDomain(@wszFriendlyName, NULL, cast(ANY PTR, @pUnk))
   IF hr <> S_OK THEN SetLastError(hr) : RETURN NULL
   DIM IID__AppDomain AS GUID = TYPE(&h05F696DC, &h2B29, &h3663, {&hAD, &h8B, &hC4, &h38, &h9C, &hF2, &hA7, &h13})
   pUnk->QueryInterface(@IID__AppDomain, @pDomain)
   pUnk->Release
   FUNCTION = pDomain
END FUNCTION
' ========================================================================================


Paul Squires

Maybe the call to m_pCorRuntimeHost->CreateDomain is calling the same instance function CCLRHost.CreateDomain over and over again until the recursion causes memory fail?
Paul Squires
PlanetSquires Software

José Roca

#94
No. it is called only once. You can't call CCLRHost.CreateDomain using the m_pCorRuntimeHost pointer. m_pCorRuntimeHost->CreateDomain calls the CreateDomain method of the ICorRuntimeHost interface.

Paul Squires

Can you post the current class code you have and the example you are working with? Maybe I can trace it with the debugger.
Paul Squires
PlanetSquires Software

José Roca

#96
The testing code is very simple:


'#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

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


PRINT
PRINT "Press any key..."
SLEEP


Attached is the current version of the hosting class.

José Roca

#97
With PowerBasic I use this code and works. The names and the syntax are a bit different, but as far as I know both do the same thing.


   ' =====================================================================================
   METHOD CreateDomain ( _                              ' VTable offset = 48
     BYREF pwzFriendlyName AS WSTRINGZ _                ' __in LPCWSTR pwzFriendlyName
   , BYVAL pIdentityArray AS IUnknown _                 ' __in IUnknown *pIdentityArray
   , BYREF pAppDomain AS IUnknown _                     ' __out IUnknown **pAppDomain
   ) AS LONG                                            ' HRESULT
   ' =====================================================================================



' =====================================================================================
' Creates an application domain.
' =====================================================================================
METHOD CreateDomain (OPTIONAL BYREF wszFriendlyName AS WSTRINGZ, BYVAL pIdentityArray AS IUnknown) AS SystemAppDomain
   LOCAL hr AS LONG
   LOCAL pUnk AS IUnknown
   LOCAL pDomain AS SystemAppDomain
   hr = m_pCorRuntimeHost.CreateDomain(wszFriendlyName, pIdentityArray, pUnk)
   IF hr THEN
      METHOD OBJRESULT = hr
   ELSE
      pDomain = pUnk
      pUnk = NOTHING
      METHOD = pDomain
   END IF
END METHOD
' =====================================================================================


Paul Squires

Putting GetLastError after;

DIM pCLRHost AS CCLRHost
GetLastError

Returns:
Error 127 ERROR_PROC_NOT_FOUND

Problem with the class constructor?
Paul Squires
PlanetSquires Software

José Roca

#99
No. This error must be set internally by NET in the call to CLRCreateInstance, but it is not meaningful since what it counts is the result code of the function. I will have to set the last error to 0 after calling it.

José Roca

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.


'#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

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

Paul Squires

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.
Paul Squires
PlanetSquires Software

José Roca

#103

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.

Paul Squires

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.
Paul Squires
PlanetSquires Software