Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 22nd, 2003, 09:44 AM
Registered User
 
Join Date: Sep 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Call VB6 or VC++ classes from C# - Reflection?

Hi,

  Someone told me that it's possible to call methods of classes made with VB6 or VC++ from C# using reflection...

  After made some investigation it seems that it's really true, I really can make a call to a "old" method using a "new" language :)

  So after gathering all the evidences I tried to build a pratical example.

  When I try to make the call to the method an exception is thrown:

Unhandled Exception: System.Security.SecurityException: Request for the permission of type System.Security.Permissions.SecurityPermission, mscorlib, Version=1.0
.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.
   at COMReflectionExample.Client.Main(String[] args)

The state of the failed permission was:
<IPermission class="System.Security.Permissions.SecurityPermiss ion, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode"/>


Here's the code:
It calls a method WhoAmI, that exists in the class ClassY made in ProjectX (made w/ VB6)

Code:
      Type T = Type.GetTypeFromProgID("ProjectX.ClassY");
      object o = Activator.CreateInstance(T);

      object returnValue;
      object [] arguments = new object[1];
      arguments[0] = "Bob";
 
      returnValue = T.InvokeMember("WhoAmI",
                                   BindingFlags.InvokeMethod,
                                   null,
                                   o,
                                   arguments);
      Console.WriteLine(returnValue);

      Console.ReadLine();
Thank You for the help,

Luís Pinho






Similar Threads
Thread Thread Starter Forum Replies Last Post
How can we call VC++ dll in C# windows application bhavna C# 2 March 4th, 2007 01:45 AM
How to call a COM DLL from VC++, subhash_w Visual C++ 0 July 15th, 2005 11:33 PM
Using reflection to get derived classes jaucourt VB.NET 2002/2003 Basics 0 May 10th, 2004 09:14 AM
Talking classes in VB6 James Diamond Pro VB 6 23 March 3rd, 2004 05:53 AM
Classes in VB6 - Urgent help required please James Diamond Pro VB 6 0 February 10th, 2004 11:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.