Hosting the CLR

G

Guest

I'm writing a program to Host the CLR. As part of this I would like to run my managed code in an AppDomain other than the DefaultDomain. My understanding is that I can do after loading and starting the CLR by using CorBindToRuntimeEx to obtain a pointer to ICorRuntimeHost. With this interface pointer I would next call the method CreateDomainSetup. From this method I get back a pointer to an IAppDomainSetup interface. Now, with this interface pointer can set the Application Base to a directory of my choice. Well when I try to set this property I get the following error

Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention

The code I'm using is as follows

HRESULT hr

hr = CoInitialize(NULL)

LPWSTR pszVer = NULL
LPWSTR pszFlavor = L"wks"
ICorRuntimeHost *pHost = NULL

hr = CorBindToRuntimeEx(pszVer,
pszFlavor,
STARTUP_LOADER_OPTIMIZATION_SINGLE_DOMAIN | STARTUP_CONCURRENT_GC,
CLSID_CorRuntimeHost,
IID_ICorRuntimeHost,
(void **)&pHost)
pHost->Start()

// Get the IAppdomainSetu
IAppDomainSetup *pAppDomainSetupPunk = NULL
hr = pHost->CreateDomainSetup((IUnknown **)&pAppDomainSetupPunk)

// Set the AppBAse pro
wchar_t wszAppBase[] = L"c:\\AppDomainBase\0"
BSTR bstrAppBase = SysAllocString(wszAppBase)
hr = pAppDomainSetupPunk->put_ApplicationBase(bstrAppBase)

Program halts on the line above

Has anyone done this? What am I missing?

Thanks
Bob.
 
G

Gary Chang

Hi,

Thanks for using Microsoft MSDN Managed Newsgroup.

Currently I am looking for somebody who could help you on it. We will reply
here with more information as soon as possible.
If you have any more concerns on it, please feel free to post here.


Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
 
G

Guest

Gary
I got the answer from the same question I posted at dotnet.framework.clr from Jan Kotas (MSFT). The problem was the way I did the cast of &punkAppDomainSetup in the CreateDomainSetup method call. The corrected code is below. Thanks for looking into this for me

Corrected code snippet

IUnknown *punkAppDomainSetup = NULL
hr = pHost->CreateDomainSetup(&punkAppDomainSetup)

IAppDomainSetup *pAppDomainSetup = NULL
hr = punkAppDomainSetup->QueryInterface(__uuidof(IAppDomainSetup)
(void**)&pAppDomainSetup)

Thanks
Bob Elwar


----- Gary Chang wrote: ----

Hi

Thanks for using Microsoft MSDN Managed Newsgroup.

Currently I am looking for somebody who could help you on it. We will reply
here with more information as soon as possible.
If you have any more concerns on it, please feel free to post here


Best regards

Gary Chan
Microsoft Online Partner Suppor

Get Secure! - www.microsoft.com/securit
This posting is provided "AS IS" with no warranties, and confers no rights
-------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top