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 / .NET Framework / Interop / September 2004

Tip: Looking for answers? Try searching our database.

Problem calling c# com from c++ client?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
BlackHawk - 07 Sep 2004 10:34 GMT
Hi,

I wrote a class library using c#, now I will use it in vc++6.

I have registered my c# program as com and imported the .tlb file in
vc6.

Now I have some problems in using it:

1. How can I response events wroten c# in vc6. The event has custom
parameters. For example:

 C# code:

  public delegate void MyCustomeEventHandler(object sender,
MyCustomEventArgs e);

  public class MyClass

  {

     public event MyCustomEventHandler MyEvent;

     public OnMyEvent(object sender, MyCustomEventArgs e);

  }  

  pubilc class MyCustomEventArgs

  {

     ErrorType errorType;   //  ErrorType is a enumeration.

     public ErrorType ErrorType

     {get {reuturn errorType;}set{errorType = value;}}

  }

  How can I use response the event in vc6 and process parameters. I
will access parameter's property "ErrorType".

2. How can I access Collection object in vc6 com?

  C# code:

   public class MyObject

   {

     MyClassCollection classColl;

     public MyClassCollection ClassCollection

     {get{return classColl;}set{classColl = value;}}

   }

   public class MyClassCollection : ICollection

   {

     ArrayList al;

     public MyClass this(int index);

     public void Add();

     public void Remove();

     public void RemoveAt();

     ..........

   }

   public class MyClass

   {

     public MyClass();

     public string Property1;

     public int Property2;

     ..........

   }

  In vc6 program class MyObject is only visible. How can I access
Property1 and Property2 in MyClass from MyObject class?
Volker Hilsheimer - 07 Sep 2004 10:54 GMT
> Hi,
>
[quoted text clipped - 88 lines]
>    In vc6 program class MyObject is only visible. How can I access
> Property1 and Property2 in MyClass from MyObject class?

Does the type library includes all classes? Check with OLE/COM viewer
(oleview).

From the C++ perspective it should be irrelevant that your COM object has
been developed with C#, as long as all classes that you can possibly write
with C# are supportable through COM. What counts is - what do the COM
interfaces look like. OLE/COM viewer will display the IDL for the type
library.

To handle the events you will probably have to implement an event sink as
for all COM objects, and advise your sink on the source interfaces called
by your COM object. Check that the COM object actually lists source
interfaces in the "coclass" declaration.

Volker
BlackHawk - 08 Sep 2004 02:13 GMT
9/7/2004 5:54:30 PM

Volker Hilsheimer <unwatched@gmx.net> wrote in message

<eGCaOCMlEHA.3896@TK2MSFTNGP15.phx.gbl>

> "BlackHawk" <eliubo@sohu.com> wrote in message

> news:eUPoW2LlEHA.1356@TK2MSFTNGP09.phx.gbl...

> > Hi,

> > I wrote a class library using c#, now I will use it in vc++6.

> > I have registered my c# program as com and imported the .tlb file in

> > vc6.

> > Now I have some problems in using it:

> > 1. How can I response events wroten c# in vc6. The event has custom

> > parameters. For example:

> >   C# code:

> >    public delegate void MyCustomeEventHandler(object sender,

> > MyCustomEventArgs e);

> >    public class MyClass

> >    {

> >       public event MyCustomEventHandler MyEvent;

> >       public OnMyEvent(object sender, MyCustomEventArgs e);

> >    }

> >    pubilc class MyCustomEventArgs

> >    {

> >       ErrorType errorType;   //  ErrorType is a enumeration.

> >       public ErrorType ErrorType

> >       {get {reuturn errorType;}set{errorType = value;}}

> >    }

> >    How can I use response the event in vc6 and process parameters.
I

> > will access parameter's property "ErrorType".

> > 2. How can I access Collection object in vc6 com?

> >    C# code:

> >     public class MyObject

> >     {

> >       MyClassCollection classColl;

> >       public MyClassCollection ClassCollection

> >       {get{return classColl;}set{classColl = value;}}

> >     }

> >     public class MyClassCollection : ICollection

> >     {

> >       ArrayList al;

> >       public MyClass this(int index);

> >       public void Add();

> >       public void Remove();

> >       public void RemoveAt();

> >       ..........

> >     }

> >     public class MyClass

> >     {

> >       public MyClass();

> >       public string Property1;

> >       public int Property2;

> >       ..........

> >     }

> >    In vc6 program class MyObject is only visible. How can I access

> > Property1 and Property2 in MyClass from MyObject class?

> Does the type library includes all classes? Check with OLE/COM viewer

> (oleview).

> From the C++ perspective it should be irrelevant that your COM object has

> been developed with C#, as long as all classes that you can possibly write

> with C# are supportable through COM. What counts is - what do the COM

> interfaces look like. OLE/COM viewer will display the IDL for the type

> library.

> To handle the events you will probably have to implement an event sink as

> for all COM objects, and advise your sink on the source interfaces called

> by your COM object. Check that the COM object actually lists source

> interfaces in the "coclass" declaration.

> Volker

Thanks your response.

The type library includes all classes and I have responsed event
successfully(used ATL), but I don't know how to access event's
parameters. This parameter is a class(MyCustomEventArgs) and has a
enumeration property(ErrorType). How can I access this enumeration
property?

The second problems same as the first. The class includes a
collection property not a enumeration. How can I access this
collection property and its element in collection?

Thanks
Volker Hilsheimer - 08 Sep 2004 10:39 GMT
> Thanks your response.
>
[quoted text clipped - 9 lines]
>
> Thanks

When you import the type library you should get the enum defined. If this
doesn't happen correctly then you will get compile errors... In C++, enums
are passed as integers, maybe this helps?

How to use the collection type depends on the API of the interface, i.e.
in

HRESULT _stdcall Images([out, retval] _IRImages** pRetVal);

what is _IRImages? What does the type library importer make out of it?

Volker
BlackHawk - 08 Sep 2004 11:26 GMT
9/8/2004 5:39:19 PM

Volker Hilsheimer <unwatched@gmx.net> wrote in message

<O9XPYeYlEHA.556@tk2msftngp13.phx.gbl>

> "BlackHawk" <eliubo@sohu.com> wrote in message

> news:uOR1QDUlEHA.1376@TK2MSFTNGP12.phx.gbl...

> > Thanks your response.

> > The type library includes all classes and I have responsed event

> > successfully(used ATL), but I don't know how to access event's

> > parameters. This parameter is a class(MyCustomEventArgs) and has a

> > enumeration property(ErrorType). How can I access this enumeration

> > property?

> > The second problems same as the first. The class includes a

> > collection property not a enumeration. How can I access this

> > collection property and its element in collection?

> > Thanks

> When you import the type library you should get the enum defined. If this

> doesn't happen correctly then you will get compile errors... In C++,
enums

> are passed as integers, maybe this helps?

> How to use the collection type depends on the API of the interface, i.e.

> in

> HRESULT _stdcall Images([out, retval] _IRImages** pRetVal);

> what is _IRImages? What does the type library importer make out of it?

> Volker

Hi,

Thanks for your help.

1. about enumeration:

Follow is my vc code.

void __stdcall CEventSink::OnDownload(VARIANT sender,
_TransferEventArgs* e)

{

DISPID dispid;

VARIANT vRet;

DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};

LPOLESTR lpStr[] = {L"TranferType"};  

// TransferType is a property in _TransferEventArgs class. It is a
enumeration.

// _TransferEventArgs is a interface in idl. Its class is
TransferEventArgs.

e->GetIDsOfNames(IID_NULL,lpStr,1,LOCALE_SYSTEM_DEFAULT,&dispid);

e->Invoke(dispid,IID_NULL,LOCALE_USER_DEFAULT,DISPATCH_PROPERTYGET,
&dispparamsNoArgs,&vRet,NULL,NULL);

if(vRet.iVal == 3) // It don't work now. How can I use vRet to
compare with enumeration.

{

 AfxMessageBox("hh",NULL,NULL);

}

}

relative IDL:

typedef [uuid(9DEDE979-708E-361A-B813-89674323B659), version(1.0),

custom({0F21F359-AB84-41E8-9A78-36D110E6D2F9}, "IRCommunication.
TransferType")

]

enum {

   TransferType_None = 0,

   TransferType_Read = 1,

   TransferType_Write = 2,

   TransferType_Download = 3,   // I want to use this enumeration.

   TransferType_Upload = 4

} TransferType;

[

 uuid(687D9CD8-F778-3067-BEDE-9EFE70E870F7),

 version(1.0),

 noncreatable,

   custom({0F21F359-AB84-41E8-9A78-36D110E6D2F9}, "IRCommunication.
TransferEventArgs")

]

coclass TransferEventArgs {

   [default] interface _TransferEventArgs;

   interface _Object;

};

[

 uuid(BA677050-17FB-3B60-9772-AA10B567E1AE),

 hidden,

 dual,

   custom({0F21F359-AB84-41E8-9A78-36D110E6D2F9}, "IRCommunication.
TransferEventArgs")

]

dispinterface _TransferEventArgs {

   properties:

   methods:

};

Since I create com in C# using "ClassInterfaceType.None" so we can't
see the method definition in _TransferEventArgs interface.
BlackHawk - 08 Sep 2004 02:33 GMT
9/7/2004 5:54:30 PM

Volker Hilsheimer <unwatched@gmx.net> wrote in message

<eGCaOCMlEHA.3896@TK2MSFTNGP15.phx.gbl>

> "BlackHawk" <eliubo@sohu.com> wrote in message

> news:eUPoW2LlEHA.1356@TK2MSFTNGP09.phx.gbl...

> > Hi,

> > I wrote a class library using c#, now I will use it in vc++6.

> > I have registered my c# program as com and imported the .tlb file in

> > vc6.

> > Now I have some problems in using it:

> > 1. How can I response events wroten c# in vc6. The event has custom

> > parameters. For example:

> >   C# code:

> >    public delegate void MyCustomeEventHandler(object sender,

> > MyCustomEventArgs e);

> >    public class MyClass

> >    {

> >       public event MyCustomEventHandler MyEvent;

> >       public OnMyEvent(object sender, MyCustomEventArgs e);

> >    }

> >    pubilc class MyCustomEventArgs

> >    {

> >       ErrorType errorType;   //  ErrorType is a enumeration.

> >       public ErrorType ErrorType

> >       {get {reuturn errorType;}set{errorType = value;}}

> >    }

> >    How can I use response the event in vc6 and process parameters.
I

> > will access parameter's property "ErrorType".

> > 2. How can I access Collection object in vc6 com?

> >    C# code:

> >     public class MyObject

> >     {

> >       MyClassCollection classColl;

> >       public MyClassCollection ClassCollection

> >       {get{return classColl;}set{classColl = value;}}

> >     }

> >     public class MyClassCollection : ICollection

> >     {

> >       ArrayList al;

> >       public MyClass this(int index);

> >       public void Add();

> >       public void Remove();

> >       public void RemoveAt();

> >       ..........

> >     }

> >     public class MyClass

> >     {

> >       public MyClass();

> >       public string Property1;

> >       public int Property2;

> >       ..........

> >     }

> >    In vc6 program class MyObject is only visible. How can I access

> > Property1 and Property2 in MyClass from MyObject class?

> Does the type library includes all classes? Check with OLE/COM viewer

> (oleview).

> From the C++ perspective it should be irrelevant that your COM object has

> been developed with C#, as long as all classes that you can possibly write

> with C# are supportable through COM. What counts is - what do the COM

> interfaces look like. OLE/COM viewer will display the IDL for the type

> library.

> To handle the events you will probably have to implement an event sink as

> for all COM objects, and advise your sink on the source interfaces called

> by your COM object. Check that the COM object actually lists source

> interfaces in the "coclass" declaration.

> Volker

This is my idl content:

This is enumeration definition in type library.

typedef [uuid(9DEDE979-708E-361A-B813-89674323B659), version(1.0),

custom({0F21F359-AB84-41E8-9A78-36D110E6D2F9}, "IRCommunication.
TransferType")

]

enum {

   TransferType_None = 0,

   TransferType_Read = 1,

   TransferType_Write = 2,

   TransferType_Download = 3,

   TransferType_Upload = 4

} TransferType;

This is collection property:

HRESULT _stdcall Images([out, retval] _IRImages** pRetVal);

"_IRImages" is a collection class in type library.

Rate this thread:







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.