Click here to Skip to main content
15,868,340 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
Here is the code I'm trying to run:
HRESULT hr = S_OK;
ICLRMetaHost    *m_pMetaHost = NULL;
ICLRRuntimeInfo *m_pRuntimeInfo = NULL;
ICorRuntimeHost  *m_pHost = NULL;
       
//CorBindToRuntimeEx is deprecated, try this code instead
hr = CLRCreateInstance(CLSID_CLRMetaHost, IID_ICLRMetaHost, (LPVOID*) &m_pMetaHost);
if (hr != S_OK) 
	return hr;
hr = m_pMetaHost->GetRuntime (DOTNETVERSION, IID_ICLRRuntimeInfo, (LPVOID*) &m_pRuntimeInfo);
if (hr != S_OK)
	return hr;
hr = m_pRuntimeInfo->GetInterface(CLSID_CLRRuntimeHost, IID_ICLRRuntimeHost, (LPVOID*) &m_pHost );
       if (FAILED(hr)) return hr;
        
//Start the CLR
hr = m_pHost->Start();

The program crashed upon trying to execute m_pHost->Start().

In the output window, I'm getting first-chance exceptions and an access violation:
First-chance exception at 0x7c812afb in sidebar.exe: 0x04242420: 0x4242420.
'sidebar.exe': Loaded 'C:\WINDOWS\assembly\NativeImages_v4.0.30319_32\mscorlib\246f1a5abb686b9dcdf22d3505b08cea\mscorlib.ni.dll'
'sidebar.exe': Loaded 'C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Culture.dll'
'sidebar.exe': Loaded 'C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\nlssorting.dll'
First-chance exception at 0x79168cef in sidebar.exe: 0xC0000005: Access violation reading location 0xc6c5fb37.
The thread 'Win32 Thread' (0x930) has exited with code -2146233082 (0x80131506).
The thread 'Win32 Thread' (0x67c) has exited with code -2146233082 (0x80131506).
The thread 'Win32 Thread' (0xdfc) has exited with code -2146233082 (0x80131506).
The program '[0x508] sidebar.exe: Native' has exited with code -2146233082 (0x80131506).

Any ideas would be appreciated.


Regards,
Mike
Posted
Updated 6-Jul-11 9:13am
v4

OK, I think I found the problem:
ICorRuntimeHost  *m_pHost = NULL;

should be changed to
ICLRRuntimeHost  *m_pHost = NULL;
 
Share this answer
 
There is a radically different alternative to this approach. This is directly exposing a .NET methods to the unmanaged. Many would tell you it is impossible, but this is not true. This is impossible for C#, C#/CLI and VB.NET, but possible and standardized in IL. You don't need to know IL in fact, there is a solution automatically adding unmanaged export to your compiled assembly. I know it from some CodeProject articles referenced below.

Please see my past solution for more information: How can I use a dll created in Visual Basic 2008 in Visual Basic 6.0[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900