Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / April 2007

Tip: Looking for answers? Try searching our database.

Host CLR

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
timor.super@gmail.com - 13 Apr 2007 14:08 GMT
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.
timor.super@gmail.com - 13 Apr 2007 16:26 GMT
On 13 avr, 15:08, timor.su...@gmail.com wrote:
> Hi all,
>
[quoted text clipped - 20 lines]
>
> 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
Ben Voigt - 13 Apr 2007 20:38 GMT
> On 13 avr, 15:08, timor.su...@gmail.com wrote:
>> Hi all,
[quoted text clipped - 34 lines]
> 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.

> i have the hresult : E_NOINTERFACE value
>
> Nb : my assembly isn't strong signed
>
> Thanks for your answer
Ben Voigt - 13 Apr 2007 20:41 GMT
> On 13 avr, 15:08, timor.su...@gmail.com wrote:
>> Hi all,
[quoted text clipped - 34 lines]
> 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?

> Nb : my assembly isn't strong signed
>
> Thanks for your answer
Marcus Heege - 16 Apr 2007 14:47 GMT
> Hi all,
>
[quoted text clipped - 20 lines]
>
> S.

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

Marcus

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.