Search:
Namespaces
Discussions
.NET v1.1
Feedback
Problem calling c# com from c++ client?
Messages
Related Types
This message was discovered on
microsoft.public.dotnet.framework.interop
.
Post a new message to this list...
BlackHawk
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?
Reply to this message...
Volker Hilsheimer
"BlackHawk" <
Click here to reveal e-mail address
> wrote in message
news:
Click here to reveal e-mail address
...
[Original message clipped]
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
Reply to this message...
BlackHawk
9/7/2004 5:54:30 PM
Volker Hilsheimer <
Click here to reveal e-mail address
> wrote in message
<
Click here to reveal e-mail address
>
> "BlackHawk" <
Click here to reveal e-mail address
> wrote in message
> news:
Click here to reveal e-mail address
...
> > 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
Reply to this message...
Volker Hilsheimer
"BlackHawk" <
Click here to reveal e-mail address
> wrote in message
news:
Click here to reveal e-mail address
...
[Original message clipped]
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
Reply to this message...
BlackHawk
9/8/2004 5:39:19 PM
Volker Hilsheimer <
Click here to reveal e-mail address
> wrote in message
<
Click here to reveal e-mail address
>
> "BlackHawk" <
Click here to reveal e-mail address
> wrote in message
> news:
Click here to reveal e-mail address
...
> > 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.
Reply to this message...
BlackHawk
9/7/2004 5:54:30 PM
Volker Hilsheimer <
Click here to reveal e-mail address
> wrote in message
<
Click here to reveal e-mail address
>
> "BlackHawk" <
Click here to reveal e-mail address
> wrote in message
> news:
Click here to reveal e-mail address
...
> > 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.
Reply to this message...
System.Collections.ArrayList
System.Collections.ICollection
System.Runtime.InteropServices.ClassInterfaceType
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com