|
Two questions:
One, can interface methods have default parameters? i.e.
HRESULT MyMethod ([in] int size = 0) Two, can a class that implements an interface have a constructor with paramaters?
Thanks!
- Aaron
|
|
|
|
|
monrobot13 wrote:
Two questions:
One, can interface methods have default parameters? i.e.
HRESULT MyMethod ([in] int size = 0)
Yes. Have a look at the MIDL keywords 'optional' and defaultvalue' in MSDN.
Two, can a class that implements an interface have a constructor with paramaters?
Regarding the C++ synthax and if you mean whether it will compile or not, the answer is yes.
I don't see the use of it though. When the ClassFactory creates the object the default constructor will get called. It should be possible to modify the ClassFactory to call a constructor with parameters, but I don't know how much work that would be. I have a feeling that it would be much work for nothing since the same constructor will be called every time the object is created. Even if you take the long way of reading the registry by yourself to get the CLSID, calling CoGetClassObject and creating the object through the IClassFactory::CreateInstance method, there is no way you can pass parameters that can determine which constructor to call from the ClassFactory. Not through the COM-interfaces anyway. Technically you could have information elsewhere, e.g. in the registry, but I consider that an unstable solution and NOT recommendable.
Consider who is responsible for that kind of information; if it's you, you can reproduce that information in your default constructor and if your user is responsible you have no control of the information and that would require a lot of error checking and fault tolerant code. And if it doesn't work, you would still be the one the user blames.
--
Roger
|
|
|
|
|
Thanks for the informative reply.
- Aaron
|
|
|
|
|
hi
One - Yes, An interface method can have parameters with default values provided the parameter shud be optional too. The parameter settings while creating the function defenition in IDL is as fllows:
[in] short i, [in] short j, [in, out, optional, defaultvalue(117)] short* k, [out, retval] short* l
and the c++ function signature will be:
STDMETHODIMP MyClass::Test(short i, short j, short *k, short *l)
Two - A class that implimets an interface can have constructor with parameters. But no way to use that. If you use CoCreateInstance to create the client then we can't use the c++ class name directly and so cunstructor parameter also. Only way where we can use the c++ class name to create the com class is CComObject<MyClass>. But even this CComObject does not accept constructor initializers.
rgds...mil10
|
|
|
|
|
Thanks much, the information is much appreciated.
- Aaron
|
|
|
|
|
Hi,
I'm really new to DCOM but my boss wants me to get into it. so here's my question:
I currently have a SDI MFC application which is a media player with DirectX, but that's beside the point. The thing is my boss wants me to implement the current application with some diagnostics software which has to call my application and pass along some values. The idea is to use DCOM as the interface between both applications but I'm kind of at a loss what I need to do now though. I've been reading some DCOM tutorials and I kind of understand how it works but I haven't been able to really find what I need to do to convert my current application to a component which understands messages it's sent. I'd be very greatful if anyone could help me or point me to some text on the internet which could help me.
-Paul
|
|
|
|
|
hi,
this is my observation , correct me if i am wrong .
I was defining a UDT which consist of a
[uuid(D8B3861A-74C6-11d2-0000-00C04FB17CDB)]
struct _BSSID_INFO
{
BSTR name;
short grade;
//classification type;
VARIANT_BOOL graduate;
};
in the IDL file.
Now when i was compiling with Default Visual Studio IDE Compiler it gave the
following errors :-
error MIDL2072 : inapplicable attribute : [uuid] [ Struct '_BSSID_INFO' ]
error MIDL2072 : inapplicable attribute : [uuid] [ Struct '_BSSID_INFO' (
Parameter 'bssid_info' ) ]
warning MIDL2039 : interface does not conform to [oleautomation] attribute :
[ Parameter 'bssid_info' of Procedure 'get_BSSID_INFO' ( Interface
'ICWiFiMgr' ) ]
but when i compiled with new vesrion of compiler and replaced it with new
MIDL.exe in the bin dir of VS6 it compiled correctly.
Any Inputs
--
Tarun..
Knowledge Seeker............
**********************************************************************
Tarundeep Singh Kalra
(tarundeep1976_nospam_at_yahoo_dot_nospam_dot_com)
tarun_at_tarunsadhana_dot_com
visit:www.tarunsadhana.com
*************************************************************************
Blue Pill or Red Pill........??
|
|
|
|
|
dear,
i use .net framework v1.0.3705. win 2000 sp 4. i try to registry my dll with regasm or regsvcs. but, i have an error.
"Strong name validation failed for assembly
'C:\WINNT\Microsoft.NET\Framework\v1.0.3705\RegAsm', The file may have been
tampared with or it was partially signed but not fully signed with the correct private key."
event if, i just run regasm or regsvcs from .net command prompt, i have a same error.
please help me sir/madam...i really appreciate for your help.
best regards
|
|
|
|
|
hi,
I already saw this behavior when you referenced the System.EnterpriseServices without a strongname, the behavior of project act strangely, in design time the COM run smoothly but if you want to register your object into component services the problem occurs. The RegAsm utility show an error saying about strongname. The just add strongname to your project will solve your problem.
mark
|
|
|
|
|
I am trying to implement a simple COM Application using Custome Interface and trying to get its object through CoCreateInstace(....). But it can get pointer to IUnknown interface but not the pointer to the COM Object. \
But the above scenerio works well in case of COM DLL Application.
Kindly help me in this regard.
|
|
|
|
|
Have you built and registered your proxy/stub library?
If you're using an Automation-compliant interface (only using types defined for the VARIANT type) and the Automation marshaller, this step is not necessary as long as you have registered your type library.
When you make an out-of-process call, COM has to translate the call arguments from the source process to the destination process - this is called marshalling. This isn't necessary in-process as long as the components are loaded into the same apartment (if they load into different apartments or contexts, COM needs to marshal between them). The proxy/stub DLL contains two parts, a proxy and a stub. The proxy is loaded into the client's address space and impersonates the server for the client. The stub loads into the server's address space and impersonates the client for the server.
The Automation marshaller simplifies things a bit; it's able to generate a proxy and a stub from the type library.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
First off I'm new to COM programming so maybe this question is foolish.
In the class I'm writing I need some strings so I'm using the CComBSTR class (I'm using ATL) for my strings. If I need to convert that item to a regular char can I use the OLE2A (and it's realated macros) to do this? I'm doing OLE2CA(bsString.Copy()) to convert it. Will this work?
Also are BSTR 's the best types to use for function paramters when implementing the functions of the interface?
Thanks!
- Aaron
|
|
|
|
|
Yes, be sure and use the USES_CONVERSION macro before using any of the ATL conversion macros.
monrobot13 wrote:
Also are BSTR's the best types to use for function paramters when implementing the functions of the interface?
Yes
|
|
|
|
|
Thanks very much.
- Aaron
|
|
|
|
|
I don't think you should use the Copy() function as this will allocate a new BSTR. CComBSTR has a BSTR operator, so OLE2CA(bsString) should be sufficient.
Shaun
|
|
|
|
|
Alright, thanks for the tip.
- Aaron
|
|
|
|
|
I have a need to change a COM+ Applications Identity and password thru script or other compiled code( Preferably not C++). I have found some documentation but nothing ever address this. Your help is greatly appreciated
Thanks
|
|
|
|
|
You need to use the COM+ Admin objects to do this, you get the application, then set the User and Password properties, followed by a save changes. I've done this using VBS and also C++, which was somewhat 'contorted', but well worth the effort, as I ended up with some admin utilities for saving/restoring application configuration.
Steve S
|
|
|
|
|
Thanks Steve. I got This far but it does not work. I found this code on MSDN
All works except for the comp object it stays set to nothing and it does not look like the comps.SaveChanges() would save anything
Dim cat As New COMAdmin.COMAdminCatalog()<br />
Dim apps As COMAdmin.COMAdminCatalogCollection<br />
apps = cat.GetCollection("Applications")<br />
apps.Populate()<br />
<br />
Dim comps As COMAdmin.COMAdminCatalogCollection<br />
Dim comp As COMAdmin.COMAdminCatalogObject<br />
<br />
comps = apps.GetCollection("Components", AppID)<br />
comps.Populate()<br />
<br />
comp.Value("Description") = "This is my Jofreder description"<br />
comps.SaveChanges()
|
|
|
|
|
You seem to be missing several steps there, namely extracting an AppID to get the components from, etc. However, you're on the right lines. Right now I'm in the middle of restoring one on my machines, and when that's done, I'll post some example VBS code that does what you want, along with an explanation - assuming my ISP doesn't screw up, of course, and my restore works*!!
Steve S
*It's a test, OK, no real machines are being harmed, and it's restoring onto a scratch disk, just to prove it can. I'm not paranoid - they are out to get me...
|
|
|
|
|
I got it working Steve. Thanks For the Help.
|
|
|
|
|
Help? Me? Nah, you're confusing me with someone else...
Steve S
|
|
|
|
|
Dear friends,
I'm learnning COM now.But there are too much things for me to learn,so I
feel tired.Can you give me some advice(such as books,links and others)?Thank you!
Jim
|
|
|
|
|
Hello Jim2004King,
For real practical help, search for the unbeatable "The Essence Of COM" by David Platt (Publishers : Prentice Hall).
This book is filled with practical source codes (from simple beginners' level to advanced).
Best Of Luck,
Bio.
|
|
|
|
|
Thank u for help.
Jim
|
|
|
|