|
If CBase implements IBase (which includes the IUnknown methods) then you second example is fine: the IUnknown and IBase method implementations are inherited from CBase and the implementation of the extra methods introduced by IDerived1 are implemented by CDerived1 .
A more typical solution is that CBase just implements IBase not including the IUnknown methods and CDerived1 would implements IUnknown and the extra methods introduced by IDerived1 . This would also look something like your second example.
Steve
|
|
|
|
|
Hi Steve, thanks for your reply.
IBase should never be instantiated, only the derived interfaces, so IBase shouldn't implement the IUnknown methods, right?
Is this good practice or should I use COM aggregation? I would like to avoid aggregation because it doesn't make sense to instanciate 2 objects and then delegating IUnknown.
So this would be the prefered way?
class CBase : public IBase<br />
{<br />
BaseFunc ();<br />
};<br />
<br />
<br />
class CDerived : public CBase, public IDerived<br />
{<br />
AddRef ();<br />
Release ();<br />
...<br />
<br />
DerivedFunc ();<br />
};
|
|
|
|
|
If you're talking about COM aggregation then you must be aware that you can only use it on COM objects which support it - I don't think it will help you here unless you’ve already got an existing COM object which you wish to use in building another COM object which exposes some or all or its functionality.
I see no reason for the CBase class at all unless you plan on reusing the IBase implementation in many objects.
Typically the most derived class implements the IUnknown methods although other scenarios are possible.
I'd use ATL.
Steve
|
|
|
|
|
All,
I am working on ATL COM DLL and I am writing a DLL which exposes few interfaces to the application. These interfces can be called either from the VBScript or C++ routine. Any rules which i need to follow especially for having a parameter[[IN], [OUT]. As every one knows that VBScript has data type limitations and we can't pass all the parameters as like in normal. For example the IN and OUT parameter will be used to send and receive values from the interfce and should always be having a VARIANT* data type.
For example:
1. STDMETHODIMP CXX::FUNC_XX( BYTE bnl,BYTE bCurrCl,VARIANT* vSData,BOOL boFlag, SHORT *pRetVal)
2. STDMETHODIMP CXXX::FUNC1_XXX(VARIANT* vReconfig,SHORT *pRetVal)
Please let me know if any one is having suggestions or sample ATL COM DLL which can be called from VBScript.
Thanks,
AKS
|
|
|
|
|
To call a COM interface from VBScript you need a dual interface with IDispatch.
|
|
|
|
|
Hi,
Thanks for answer. But i am mainly interested in knowing what are all the basic rules (such as supported data type of parameters and etc) which i need to follow when i want to write a com dll which can be used from the VBScript especially.
Thanks,
Siva
|
|
|
|
|
Whenever possible I use setters for strings (BSTRs) rather than getters, but sometimes this is not possible.
The advantage of a setter is that I only have to guarantee the lifetime of the string during the call of a method, and since the calls are synchronous the string can be on the stack, on the heap or in the resources and the other component doesn't have to care about it.
But how about getters, GetName for example. Should the caller pass a buffer? Should the callee make a copy of the string and offer a method to free the string? Or should the caller assume that the string will not be deleted during the execution of its own method and just not save the pointer for later use?
I would like to use a consistent way that works across different languages.
|
|
|
|
|
You should create the string with SysAllocString . The caller should free the string when it's finished with it using SysFreeString .
|
|
|
|
|
I guess you are right and that is the only way it should been done. I've just seen to many other ways how strings are handled.
Often C++ memory management is beeing used which is really bad because it assumes that the caller uses the same memory management as the callee.
During marshalling the .NET runtime calls SysFreeString for returned BSTRs, so anything else than SysAllocString doesn't seem to work.
|
|
|
|
|
The defined way of manipulating BSTRs is to use the SysXxxString methods. Anything else is just plain wrong and needs to be fixed.
OK, if you're copying a BSTR parameter into a member variable, you can use any allocator you like for your member variable.
If you have an in/out BSTR parameter, I don't think you're allowed to alter that string. Instead you should use SysAllocString to create a new one and SysFreeString the one you were passed.
|
|
|
|
|
I want to write a program in Visual C++ to transfer data between a computers and microcontroller via 10/100 Ethernet RJ-45.
What i need (libraries, or is there any help in MSDN.)
What i figured out is that i need "winsock" for programming.(TCP client and TCP Server)
Where should I start.
thanks
|
|
|
|
|
This message board is really for discussion of the Component Object Model (COM) and programming server components and client applications. You'll probably get better results on the Visual C++ forum[^].
|
|
|
|
|
I would like to use namespaces in the IDL file, instead of MyInterface I would like to use MyNamespace::MyInterface.
For example MSXML uses different namespaces.
|
|
|
|
|
IDL does not support namespaces, which are a C++ thing. IDL is designed to be language neutral. When you #import a type library, the namespace is generated by the C++ tool doing the import, not the type library.
Steve S
Developer for hire
|
|
|
|
|
Steve S wrote: When you #import a type library, the namespace is generated by the C++ tool doing the import, not the type library.
But how does the C++ tool (MSVC) knows which namespace to use if I #import "MSXML*.dll"? That info must be in the dll?
|
|
|
|
|
Because it uses the library name, which is in the IDL as
library MSXML2
{
// TLib : // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
importlib("STDOLE2.TLB");
....
Steve S
Developer for hire
|
|
|
|
|
Hi,
I'm a beginner in COM, and have a question in my program need your help~
I use either _beginthreadex or CreateThread to create a thread in my COM dll's DLLMain function's
case DLL_PROCESS_ATTACH:
the thread will run a while loop to excute ReadDirectoryChanges for real time monitor directory,
but very wired, the whole COM dll will hang by that thread, other function in the dll can't work, because
whole dll is hang in there when excute ReadDirectoryChanges.
when I take off ReadDirectoryChanges from Com dll, use a individual simple project create a thread
run ReadDirectoryChanges is OK, but when COM dll combine with create thread run ReadDirectoryChanges,
the COM dll will hang there, so it maybe the COM thread setting problem? or any other issue?
Please help me~ Thanks~
|
|
|
|
|
You can create a thread in DllMain, but you can't wait on it. It will immediately cause the OS to try to re-enter DllMain to give the DLL_THREAD_ATTACH notification, but the new thread will wait there because it needs to acquire the Loader Lock. Your original thread will already have the Loader Lock, and will not release it until it returns from DllMain. If the first thread now tries to wait for some other event to occur that's signalled by the second thread, you have a deadlock.
Basically, don't do any work at all in DllMain. Instead, do lazy initialisation, when actually needed. In a COM object you might do this in the object's constructor, or otherwise in response to CoCreateInstance. For example, ATL offers the FinalConstruct method to allow you to do extra initialisation after the constructor has run but before CoCreateInstance returns.
Finally recall that interface pointers are apartment-relative. If calling back into a client from a worker thread, you need to make sure the call is marshalled correctly. See the Global Interface Table for an idea of how to do this.
|
|
|
|
|
|
BY THE NAME OF ALLAH ,
i am asking for any new Idea for my graduation project , iam in computer science dep. i want in any field so plz any One know
tell me . i will be thankful .
thnkx , amal emam
|
|
|
|
|
I am having some difficulty in my C++ app with memory management. Currently the client app sets up a struct **pPointer that is passed to the COM+ method on the server. The server then reads a database and creates a record set. This record set is processed and the server then CoTaskMemAlloc’s space for each of the processed records. The array of pointers is then passed back to the client.
The pointers all seem to be marshaled fine. The data is processed, and then I CoTaskMemFree the pointers, and release the Access Object to decrement the object reference count. Even though the object seems to have no more references to it (ie the object is no longer spinning in Component Services), the server (dllhost.exe) is still holding on to the memory that was allocated on the server. After about 30 minutes the memory is eventually free’d. However the memory use is very large and multiple clients are utilizing the system. It does not take long to run out of resources and the server crashes with a ‘COM Surrogate error’ . My guess is that when the server runs out of memory, it errors and returns a NULL pointer. As Windows is trying to marshal the null pointer, the error situation occurs (but this is just a guess, it could be a bad uninitialized pointer).
I need to figure out how to free the memory on the COM server after I am done with it, so that it can be released. Any help would be greatly appreciated.
Client Side Code Snippit:
<br />
hr = CoCreateInstance( CLSID_ValuesAccessObject,<br />
0,<br />
CLSCTX_ALL,<br />
IID_IValuesAccessObject,<br />
(void**)&m_pidsrtval );<br />
<br />
...<other processing>...<br />
<br />
hr = m_pidsrtval->GetAllValues( GetDbConnectionString(),<br />
&nValues,<br />
&pspdcrtbv );<br />
<br />
<br />
...<other processing>...<br />
<br />
for( int i=0; i<nValues; i++ )<br />
{<br />
SPDCRTBV *paspdcrtbv = &((*ppsptbvValues)[i]);<br />
<br />
CoTaskMemFree(paspdcrtbv->pdvQualifiers);<br />
paspdcrtbv->pdvQualifiers = NULL;<br />
<br />
CoTaskMemFree(paspdcrtbv->pdvFacts);<br />
paspdcrtbv->pdvFacts = NULL;<br />
<br />
}<br />
<br />
CoTaskMemFree(pspdcrtbv);<br />
m_pidsrtval->Release(); <br />
Chris
|
|
|
|
|
hi everyone,
i created a activex control(.ocx),and placed the same in the form for testing,after placing not able to move(drag) the control to other places in the form
pls let me know whats missing on my control,
thanks n advance
rahul
rahul
|
|
|
|
|
Hi,
I have to build a layer of serviced components over a DAL (data access layer). Now this DAL was written using interop in VC++.
I built my component using a snk - which worked fine till i added the code to access DAL. Now it gives me an error sayin that assemly cannot be created as DAL does not have a strong name.
How do I get rid of this problem? How can i reuse the existing component without having to rewrite it in .net environment?
I recently read an article sayin that i would have to generate a strong key for the interop dll using tlbimp... but i somehow am not able to figure the parameters out ... has anybody done this?
Any help will be appreciated!
|
|
|
|
|
You only have to generate a strong name for interop if you plan to put the class library assembly into the GAC. This is recommended if you're going to share the component between applications, for example have multiple applications install the same component, but isn't actually required. The regasm utility can be made to register a class library DLL in any location using the /codebase switch; the Visual Studio deployment project's Register property, if set to 'vsdraCOM', will set the Codebase registry value appropriately if you're not installing the assembly to the GAC.
If you do install the same assembly from two different locations, then uninstall one of them, the registration will be broken for the other one. That's why the GAC is recommended.
If you do want to use the GAC, all assemblies that this one depends on will need to be signed and installed to the GAC as well. You can sign the DAL using the C++ linker's /KEYFILE option; you must specify this option in the 'Additional Options' field in the Linker options.
|
|
|
|
|
Hi,
How to register XPCOM component using XPInstall?
Thank you.
Ayesha
|
|
|
|