Host CLR

  • Thread starter Thread starter timor.super
  • Start date Start date
T

timor.super

Hi all,

I'm trying to use a .net api from unmanaged MFC code.


I'm trying to use ClrCreateManagedInstance api, but as shown above,
my
var pDisp equals null before the ClrCreateManagedInstance call.


Can you correct my code ? (Or any other way to do that ?)


#include "mscoree.h"
#pragma comment (lib, "mscoree.lib")


CComPtr<IDispatch> pDisp;
HRESULT hr = S_OK;
hr = ClrCreateManagedInstance(L"System.Windows.Forms.MessageBox,
System.Windows.Forms, Version=2.0.50727.42, Culture=neutral,
PublicKeyToken=b77a5c561934e089",IID_IDispatch, (void**)&pDisp);


Thansk in advance for your help,


Best,


S.
 
Hi all,

I'm trying to use a .net api from unmanaged MFC code.

I'm trying to use ClrCreateManagedInstance api, but as shown above,
my
var pDisp equals null before the ClrCreateManagedInstance call.

Can you correct my code ? (Or any other way to do that ?)

#include "mscoree.h"
#pragma comment (lib, "mscoree.lib")

CComPtr<IDispatch> pDisp;
HRESULT hr = S_OK;
hr = ClrCreateManagedInstance(L"System.Windows.Forms.MessageBox,
System.Windows.Forms, Version=2.0.50727.42, Culture=neutral,
PublicKeyToken=b77a5c561934e089",IID_IDispatch, (void**)&pDisp);

Thansk in advance for your help,

Best,

S.


Let me add some information, if i try with System.Random that is part
of mscorlib
this :
hr =
ClrCreateManagedInstance(L"System.Random,mscorlib,PublicKeyToken=b03f5f7f11d50a3a",
IID_IManagedObject, (void**)&pWrap);

is working :)


but if i try with my own assembly :
hr = ClrCreateManagedInstance(L"MyAssembly.Class1,MyAssembly",
IID_IDispatch, (void**)&pDisp);

i have the hresult : E_NOINTERFACE value

Nb : my assembly isn't strong signed

Thanks for your answer
 
Let me add some information, if i try with System.Random that is part
of mscorlib
this :
hr =
ClrCreateManagedInstance(L"System.Random,mscorlib,PublicKeyToken=b03f5f7f11d50a3a",
IID_IManagedObject, (void**)&pWrap);

is working :)


but if i try with my own assembly :
hr = ClrCreateManagedInstance(L"MyAssembly.Class1,MyAssembly",
IID_IDispatch, (void**)&pDisp);

What compiler version is your assembly built with? Did you call
CorBindToRuntimeEx? If not, the documentation indicates that the .NET 1.0
runtime gets loaded and you won't be able to load newer assemblies.
 
Let me add some information, if i try with System.Random that is part
of mscorlib
this :
hr =
ClrCreateManagedInstance(L"System.Random,mscorlib,PublicKeyToken=b03f5f7f11d50a3a",
IID_IManagedObject, (void**)&pWrap);

is working :)


but if i try with my own assembly :
hr = ClrCreateManagedInstance(L"MyAssembly.Class1,MyAssembly",
IID_IDispatch, (void**)&pDisp);

Maybe ClrCreateManagedInstance doesn't load the assembly for you. Try
loading System.Reflection.Assembly from mscorlib, and call Assembly.Load.
See http://msdn2.microsoft.com/en-us/library/y6k08yft(VS.80).aspx
i have the hresult : E_NOINTERFACE value

Have you set the COMVisibleAttribute on your class?
 
Hi all,

I'm trying to use a .net api from unmanaged MFC code.


I'm trying to use ClrCreateManagedInstance api, but as shown above,
my
var pDisp equals null before the ClrCreateManagedInstance call.


Can you correct my code ? (Or any other way to do that ?)


#include "mscoree.h"
#pragma comment (lib, "mscoree.lib")


CComPtr<IDispatch> pDisp;
HRESULT hr = S_OK;
hr = ClrCreateManagedInstance(L"System.Windows.Forms.MessageBox,
System.Windows.Forms, Version=2.0.50727.42, Culture=neutral,
PublicKeyToken=b77a5c561934e089",IID_IDispatch, (void**)&pDisp);


Thansk in advance for your help,


Best,


S.

You can't instantiate S.W.F.MessageBox, because it has a private constructor
:-)

Marcus
 
Back
Top