|
What language are you coding in?
In VB, just make sure you set all of the objects you create to Nothing as soon as you're done with them:
Set MyLibraryInterface = Nothing<br />
Set MyBusinessObject = Nothing
In many situations, you don't really need to do this unless you're creating a lot of objects that don't fall out of scope right away
In C++, you just call ->Release() on your interface pointer.
MyComObject* pMyComObject = NULL;<br />
(send the pointer into your class factory CreateInstance call here)<br />
(do your business logic here)<br />
<br />
pMyComObject->Release();
Hope this helps.
|
|
|
|
|
I have implemented both applications using COM & DLL. But i don't find out any significance difference.So if anybody knows about it,then please reply me as soon as possible.
Regards,
Pankaj Sachdeva
|
|
|
|
|
[Why the laugh?]
A DLL is a set of code packaged into a library which can be used by your application, but is limited to working "in-process". That means it's loaded into your EXE, and has the same access to the memory allocated to the process as any of your other code. Similarly, it runs with the same privileges and user identify that your process does.
A COM component (or object, if you will) on the other hand, is a package of code which can be used by your (or any COM-aware) application, possibly even script hosts (VBScript, JScript) if the component implements the necessary supporting functionality. It provides mechanisms for working across process and machine boundaries, and allows (well, insists, sometimes) the configuration of security such that the component may execute under a different identity to the clients of the component. A COM object can implement or provide multiple interfaces, support aggregation, callbacks, and will implement lifetime management.
If your only exposure to COM is writing an ATL-based DLL, then it is not surprising that you haven't really appreciated the differences. Where I am (and where I was before) make heavy use of COM, COM+ and DCOM to implement a range of application servers (some of which are also services). None of them are 'network-aware', in the sense that there is no client code which deals directly with locating a component on a remote machine on the LAN and talking to it. COM/DCOM deals with all the plumbing issues, so you can concentrate on making the applications do what they are supposed to.
Many of these run 24/7, stopping only for software changes, and sometimes not always then!
Steve S
Developer for hire
|
|
|
|
|
pan_angel wrote: I have implemented both applications using COM & DLL
The above line doesn't match well with the below one.
pan_angel wrote: But i don't find out any significance difference
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Hi,
I'm using one COM component(exe), which implements the connection points also.
I have a client which implements Sink interface also. The event the server fires is a method with a single argument BSTR. When the server fires the event, client gets the notification, but the BSTR value is invalid(empty string).
The problem is also seen with ULONG parameter also. Please suggest a solution, and please
suggest is it a good idea to have parameters in the event notifications.
Also if two clients are connected to the server, only the client which caused the event to fire is getting the notification.
Thanks and regards,
Raja Pratap.
|
|
|
|
|
Could you post a bit of your code so we can see where the problem is?
---
Hakuna-Matata
It means no worries for the rest of your days...
It's our problem free, Philosophy
"I think my response was 'What idiot dreamed this up?'" -- Mary Ann Davidson, Oracle's chief security officer, in typical blunt manner, remembering her reaction to the company's scheme to brand its databases as "unbreakable."
|
|
|
|
|
The problem got soleved.
We have to make the server free threaded and make the class implementing the interface singleton and we need to in _tWinMain.. make sure that CoInitializeEx gets called.
Just trial and error caused a break through.
Thanks and regards,
Raja Pratap
|
|
|
|
|
Hi
I am trying to understand relation between queryinterface and cocretaeinstance. I read so many things still dont understand.
(For cocretaeinstance) In MSDN it says:
"This function creates on the local system a single uninitialized object of the class associated with a specified class identifier. "
I understand that
We use cocreateinstance to take instance for a class and we query for a supported interface with queryinterface.
But if we use COM for using Interface instead of class object.
So why do we take instance of a class? Isn't concept of COM using Interface instead of class object. So hiding implemantion details and avoiding name mangling etc... So why do we take a class object?
I dont understand here.
In what conditions do we need/use cocretaeinstance and queryinterface together? And in what conditions one of them is enough?
I hope i could explain the problem.
I am looking for your answers
Thanks.
|
|
|
|
|
I guess, one cannot take an instace of a COM class...As it is still abstract...
It is passed as a parameter to one of the CComObject<> varaiants to instantiate it..
If you want to access other interfaces supported by the coclass, then it can be done by queryinterface-ing the already obtained interface... instead of re-creating the Object instance...
Hope this helps,...
raja
|
|
|
|
|
CoCreateInstance will give you an instance of a class of object (defined by the CLSID), and allow you to reference it via an interface (defined by the IID).
You can then ask the object for a different interface via QueryInterface.
As an example, imagine an object which displays data onto a device context. This uses an 'IRender' interface, which allows you to specify stuff like where to render to, and stuff like a zoom ratio, etc. But the object also supports the IPersistFile interface, to allow the saving/loading of the object to/from file.
The only way to get to IPersistFile from IRender is via IUnknown's QueryInterface method.
If you only use simple objects, they may only implement one (custom) interface, although in practice IUnknown must always be supported as well.
Does that help?
Steve S
Developer for hire
|
|
|
|
|
|
Hello
How can i change the CLSID and progid for already existing projects.Should i generate this for each project using guidgen.exe?I want to be able to load the dlls from a different target path, as a seperate plugin.is it sufficient to change the clsid alone or should progid needs to be modified as well? What will be the efficient way to do this.
Thanks
|
|
|
|
|
Dear all,
I want to write a Visual C++ program which interacts with a COM dll provided by a company. I have registered the dll and generated the .tlb using regasm, and now I'm facing a big problem, which is probably due to some very basic/stupid error:
<br />
#import "D:\programs\Autodrop\AutodropAutomation.tlb" no_namespace<br />
<br />
int _tmain(int argc, _TCHAR* argv[])<br />
{<br />
HRESULT hr;<br />
<br />
hr = CoInitializeEx(NULL,COINIT_MULTITHREADED);<br />
<br />
if (SUCCEEDED(hr)) {<br />
CLSID CLSID_clsAutomation;<br />
hr = CLSIDFromProgID(L"AutodropAutomation", &CLSID_clsAutomation);<br />
<br />
LPOLESTR clsidStr;<br />
hr = StringFromCLSID(CLSID_clsAutomation, &clsidStr);<br />
<br />
clsAutomation *aac = NULL;<br />
<br />
hr = CoCreateInstance( CLSID_clsAutomation,<br />
NULL,<br />
CLSCTX_INPROC_SERVER,<br />
__uuidof(clsAutomation), <br />
(void**) &aac);<br />
<br />
if(SUCCEEDED(hr)) {<br />
cout << "The COM server has been successfully created!" << endl;<br />
long feedback = aac->Init("Test");<br />
} else {<br />
cout << "The COM server has not been created: ";<br />
}<br />
}<br />
<br />
return 0;<br />
}<br />
<br />
When trying to compile this code, I get the following error:
InkjetController.cpp<br />
.\InkjetController.cpp(67) : error C2027: use of undefined type 'clsAutomation'<br />
d:\documents\visual studio projects\inkjetcontroller\inkjetcontroller\debug\autodropautomation.tlh(23) : see declaration of 'clsAutomation'<br />
.\InkjetController.cpp(67) : error C2227: left of '->Init' must point to class/struct/union/generic type
Now, the point is that the method Init(String) DOES exist for clsAutomation:
Function Init(ByVal DatabasePath As String) As Long
Member of AutodropAutomation.clsAutomation
I saw many examples which access methods just by using this syntax, I do not understand what does not work. I tried a lot of work-arounds, but none of them worked up to now...
Thank you very much for your help,
Grégory
|
|
|
|
|
Hi
Am working on an application which is a plugin in a host application. To load an image the startup calls from the host are passed via an interface A and calls are passed to a package handles all the dll loading and initialising the application.Currently am loading the dlls from particular location , Location A.
The plugin A will be used as such and no more development will be done on that.
My goal is to load a second plugin from the host, which would be using the same code base, but development will be carried on moving forward.Essentially this has to load the same dlls but a different version and the code base is going to be updated.The dlls for the new plugin will be loaded from location B.
Experts in the group, what is the best approach to achieve this? As dlls are identified by GUID,so only one version of the dll can be registered at a time in the registry. Should i change the dll name and GUID for the entire application?IS this feasible?
Thanks a lot!
|
|
|
|
|
Hi all.
I'm having a really annoying issue generating a type library from a COM component written in .NET. Actually the class library was coded by another employee who has since left, so I am stuck trying to properly compile it.
Basically there is an interface IParameterData that has a number of properties all starting with I (upper case i) and ending in ID. However, when inspecting the generated type library the case has been changed on the first I (to lowercase) and the final D. This happens on 4 out of roughly 12 parameters.
The strange thing is that the type library is generated fine on one particular pc, but on 3 others I have tried it is incorrect.
Has anyone had similar issues with this? Is it because of old entries still in the registry? I have tried deleted old registry entires but to no avail.
Any help with this would be greatly appreciated
|
|
|
|
|
|
Hi,
I have to export data from a database to Excel via VB.NET 1.1. And I am having all kinds of issues.
I honestly do not know what to do, I have searched high and low. Is there another way of exporting data from the database to Excel via VB.NET. I have to do everything in VB.NET.
This is my error:
"ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user."
I read an article on the Internet and they said that I must add the following to the web.config file:
<identity impersonate="true" userName="youradminuser" password="youradminpassword" />
..but what username and password is this?
Regards
ma se
-- modified at 2:53 Friday 15th June, 2007
|
|
|
|
|
Dude, you are in the wrong forum.
Anyways, for a Windows application you can easily use the Excel interfaces provided by Microsoft to do the job.
---
Hakuna-Matata
It means no worries for the rest of your days...
It's our problem free, Philosophy
"I think my response was 'What idiot dreamed this up?'" -- Mary Ann Davidson, Oracle's chief security officer, in typical blunt manner, remembering her reaction to the company's scheme to brand its databases as "unbreakable."
|
|
|
|
|
Hi to All,
I created one ClassLibrary in .Net using VB.Net, which is configured for COM InterOP. In this Library, I created 3 classes and below they are.
(1) Document class: which is having 2 properties
(a) AddPage : function for adding a Page to the Document.
(b) DrawToFile : method which 'll draw the output to the specified file.
(2) Page class: Having a AddLabel function used for adding a Label to the Page.
(3) Label class: having 2 functions and 1 Event.
(a) Text function: which is used to Set or Get the Text of the Label.
(b) TextColor function , which is used to Set or Get the Text of the Label.
(c) TextColorChanged event
Now, In Vb 6, by referencing the TypeLibrary for the .Net ClassLibrary, I am able to code as I required. And the code , what I have written in Vb 6 is below.
Public WithEvents mylabel As ClassLibrary1.Label
Public doc As New Document
Private Sub Command1_Click()
Dim page As page
Set page = doc.AddPage
Set mylabel = page.AddLabel("ceTe Software,Mysore,India", 10, 10, 300, 20)
doc.DrawToFile ("c:\t.pdf")
End Sub
Private Sub Command2_Click()
mylabel_TextColorChanged (Text1.Text)
doc.DrawToFile ("c:\t.pdf")
End Sub
Private Sub mylabel_TextColorChanged(ByVal value As String)
mylabel.TextColor = value
End Sub
My need is to implement the same in Classic ASP.
Anyone, write the code in Classic ASP for me, as I donot know how to do this in Classic ASP.
Thanks in Advance,
Murty
|
|
|
|
|
I created a regular COM object with ATL, it worked fine by using the CoCreateInstance(), and then install the COM object to a COM+ application with Component Services administrative tool, when I try to call CoCreateInstance in my client code, I got "no such interface supported" error, the returned HRESULT is "Class not registered". class can be seen in OLE/COM Viewer, but it doesn't expose custom interfaces (only IUnknown, IClientSecurity, IMultiQI and IMarshal). But if I delete the object from COM+ application, and just register the component with regsvr32 command, my client works, again.
Anything I have missed when I installed the component into the COM+ application?
|
|
|
|
|
Hi,
I'm planning to implement a chat server + a chat client as a learning exercise for my ATL/COM/DCOM.
As part of that first I would implement a chat server which is a local server and a chat client. Please suggest if the following is possible, if true how.
Clients register their callbacks by using Advice() (Of course, I would do FindConnectionPoint(), before that ). My doubt is is there any way to send the notification from the server to all the clients? and also can the server select the client to which it has to send the notification.
For Example: User1, User2 are currently logged in. If user1 sends a message to User2 by using SendMsg(from, to, msg) of IChatServer, can the server alert client of User2.
Otherwise can server broadcast the event??
Thanks and regards,
Raja Pratap
|
|
|
|
|
Hi,
I desperately need some help on getting started on an browser helper object for Internet Explorer.
What I want is basically a very simple thing: two buttons in the link bar, of which one activates a predefined page (just regular link button functionality), while the other does the same, but adds the web page that is currently visible as attributes. To spice things up, they could be collected in a toolbar with a company logo, but that is extra.
I have made this in Delphi about a year ago, but I never got the button sizing working good (in fact the toolbar did WEIRD things to Internet Explorer layout when dragging and dropping this), so my problem is not that I do not know about IDispatch and IWebBrowser and stuff, but mainly how I can program the two link buttons.
I have the feeling that such a BHO has been made many times, but I wouldn't know where to start.
Any help would be greatly appreciated!
Thanks
Kees
Keesp
"You should have an open mind, but not so open that your brain falls out"
|
|
|
|
|
I try to use FileSystemObject in VC6 via "#import "scrrun.dll""
<br />
IFileSystemPtr spFso(__uuidof(FileSystemObject));<br />
ISupportErrorInfoPtr spSupportE = spFso;<br />
HRESULT hrRet = spFso->raw_MoveFolder(_bstr_t(pwszSrc), _bstr_t(pwszDst));<br />
For testing, I assigned pwszSrc and pwszDst with invalid paths.
I find that IFileSystem does not support ErrorInfo coz the interface pointer in spSupportE is NULL. The value of hrRet is 0x800a004c, which can not be processed by FormatMessage(). So after MoveFolder() fails, I can't get any error message.
However, I used VB to call the same function and got error message "Path not found". How does VB do that? How can I get the same message in VC?
|
|
|
|
|
Well, 800a004c is CTL_E_PATHNOTFOUND (olectl.h), so you probably need to point FormatMessage at the right DLL...
Steve S
Developer for hire
|
|
|
|
|
I think the common way of using FormatMessage is like this:
<br />
LPWSTR pwszMsg = NULL;<br />
<br />
FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL,hr, 0, (LPWSTR)&pwszMsg, 0, NULL);<br />
How can I know which DLL to point and generate correct message?
Thanks.
|
|
|
|
|