New Message on dotNET User Group Hyd

Article: Calling managed code(C#.NET) from unmanaged(VB) - Part II

Reply
  Reply to Sender   Recommend Message 1 in Discussion
From: johnsonsmithy2k2

.... Continues from Part I

They will discover the following:
// Generated .IDL file (by the OLE/COM Object Viewer)

//
// typelib filename: sample.tlb


[

uuid(AD7B6A7C-4F96-3710-B1AC-5170E611BA57),

version(1.0),

custom(90883F05-3D28-11D2-8F17-00A0C9A6186D, sample, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null)


]

library sample

{

// TLib : // TLib : Common Language Runtime Library : {BED7F4EA-1A96-11D2-8F08-00A0C9A6186D}

importlib("mscorlib.tlb");

// TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}

importlib("stdole2.tlb");


// Forward declare all types defined in this typelib

interface _T;


[

uuid(4996A037-02BD-3839-A363-A9A321885D2C),

version(1.0),

custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, T)

]

coclass T {

[default] interface _T;

interface _Object;

};


[

odl,

uuid(742F958A-4C27-399F-89DD-5368588B63B7),

hidden,

dual,

oleautomation,

custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, T)


]

interface _T : IDispatch {

};

};

What is wrong there? Our public string A method is nowhere to be seen, also familiar methods belonging to Object are hidden.

That means that VB code editor won't be able to help in a way which we would like to show as methods and properties of the class. So what could be done to improve that kind of situation? Help comes from attributes. Change your C# code to this:
using System;

using System.Runtime.InteropServices;


[ClassInterface(ClassInterfaceType.AutoDual)]

public class T

{

public string A(string s)

{

return s+" from C#";

}

}

Repeat steps to compile, get tlb and register library, copy sample.dll and str.tlb to corresponding directory and try early binding. Everything will work fine.

...to be continued in Part III

Notice: The information contained in this e-mail message and/or attachments to it may contain confidential or privileged information. If you are not the intended recipient, any dissemination, use, review, distribution, printing or copying of the information contained in this e-mail message and/or attachments to it are strictly prohibited. If you have received this communication in error, please notify us by reply e-mail or telephone and immediately and permanently delete the message and any attachments. Thank you

View other groups in this category.

Click here
Also on MSN:
Start Chatting | Listen to Music | House & Home | Try Online Dating | Daily Horoscopes

To stop getting this e-mail, or change how often it arrives, go to your E-mail Settings.

Need help? If you've forgotten your password, please go to Passport Member Services.
For other questions or feedback, go to our Contact Us page.

If you do not want to receive future e-mail from this MSN group, or if you received this message by mistake, please click the "Remove" link below. On the pre-addressed e-mail message that opens, simply click "Send". Your e-mail address will be deleted from this group's mailing list.
Remove my e-mail address from dotNET User Group Hyd.

Reply via email to