Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Closed Thread
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 22nd, 2003, 09:44 AM
Registered User
Points: 49, Level: 1
Points: 49, Level: 1 Points: 49, Level: 1 Points: 49, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2003
Location: Porto, , Portugal.
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

Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 07:33 AM.


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