|
Would this be safe? (the following code is implemented in a DLL, used by a single EXE and a bunch of COM DLLs)
CComAutoCriticalSection cs;
DWORD dwOwnerThreadId;
ISomeInterface* pObject = 0;
IStream* pObjMarshalled = 0;
HRESULT RegisterGlobalObject(ISomeInterface* pObj)
{
if(!cs.Lock())
return E_FAIL;
if(pObject != 0) {
cs.Unlock();
return E_UNEXPECTED;
}
HRESULT hr = CoMarshalInterThreadInterfaceInStream(
__uuidof(ISomeInterface),
pObj,
&pObjMarshalled
);
if(FAILED(hr)) {
cs.Unlock();
return hr;
}
pObject = pObj;
dwOwnerThreadId = GetCurrentThreadId();
cs.Unlock();
return S_OK;
}
HRESULT GetGlobalObject(ISomeInterface** ppObj)
{
if(!ppObj)
return E_POINTER;
if(!pObject)
return E_FAIL;
if(!cs.Lock())
return E_FAIL;
if(GetCurrentThreadId() == dwOwnerThreadId) {
*ppObj = pObject;
(*ppObject)->AddRef();
cs.Unlock();
return S_OK;
}
*ppObj = 0;
LARGE_INTEGER seek;
seek.QuadPart = 0;
HRESULT hr = pObjMarshalled->Seek(seek, STREAM_SEEK_SET, NULL);
if(FAILED(hr) {
cs.Unlock();
return hr;
}
hr = CoUnmarshalInterface(
pObjMarshalled,
__uuidof(ISomeInterface),
(void**)ppObj
);
cs.Unlock();
return hr;
}
I'm marshalling the interface pointer upon registration using the inter thread marshalling function, because I know that this function will not be called from any other process (it can't be). I also assume that CoUnmarshalInterface() will work for interfaces marshalled with CoMarshalInterThreadInterfaceInStream() .
I have yet to try this out (it's way past bedtime ). But if you read this and spot any inherent danger with this code, please let me know.
--
Sancte Míchael Archángele, defénde nos in proélio contra nequítiam et
insídias diáboli esto præsídium. Imperet illi Deus, súpplices deprecámur:
tuque, princeps milítiæ cæléstis, Sátanam aliósque spíritus malígnos, qui
ad perditiónem animárum pervagántur in mundo, divína virtúte,
In inférnum detrude. Amen.
|
|
|
|
|
Once the marshalled interface has been "picked up" from the stream and used, it seems that it's been used up already. I receive RPC_E_DISCONNECTED on method access.
I decided to make a singleton COM object which stores the ISomeInterface pointer instead. Then COM will handle everything automatically.
--
Sancte Míchael Archángele, defénde nos in proélio contra nequítiam et
insídias diáboli esto præsídium. Imperet illi Deus, súpplices deprecámur:
tuque, princeps milítiæ cæléstis, Sátanam aliósque spíritus malígnos, qui
ad perditiónem animárum pervagántur in mundo, divína virtúte,
In inférnum detrude. Amen.
|
|
|
|
|
You might have look to the IGlobalInterfaceTable . This allows multiple unmarshalling of once marshalled interface - if it helps you somehow.
|
|
|
|
|
Hello there,
Does anyone know how I can search for all registered COM objects that expose some specific (defined by me) interface?
|
|
|
|
|
hi frnd
One can search a component installed on a particular machine based on the CATID i.e category ID in which it falls.
there are two interfaces
ICatInformation using methods of which you can enumerate all the component of a CATID.
and ICatRegister interface which provides methods for registering and unregistering component category information in the Registry.
have look on these interfaces in your MSDN , u might find your solution.
Abhishek Srivastava
Software Engg (VC++)
India ,Noida
Mobile no 9891492921
|
|
|
|
|
HI!
I need Yahoo messenger login interface urgently. I want to access yahoo messenger window from my application bypassing the login screen for a particular user. any links or suggestions is most welcome.
|
|
|
|
|
Hi, I need to access COM objects during runtime or dynamically using VC++6. Can somebody please help me in this? Is there a way I can call the COM objects during runtime by entering the GUID or something like that? I am a beginner in COM..
Thx!!
|
|
|
|
|
Is this the function you're looking for?
<code>
CoCreateInstance(REFCLSID rclsid,
LPUNKNOWN pUnkOuter,
DWORD dwClsContext,
REFIID riid,
LPVOID * ppv);
</code>
I hope this helps you.
-John
|
|
|
|
|
I forgot to mention you might want to call CoIntialize(NULL) to initialize the COM runtime before making a call to CoCreateInstance(). Once you're through using your COM objects be sure and call CoUnitialize().
|
|
|
|
|
Hi there,
One can access COM objects at run time , but the interface supported by this COM object should
support IDispatch interface.
CLSID objClsid;
// initialize your obj CLSID in this variable
using CoCreateInstance() get the IDispatch pointer.
IDispatch *dispPtr;
CoCreateInstance(objClsid, NULL, CLSCTX_ALL, IID_IDispatch , (void **) &dispPtr);
if your object support IDispatch interface , it will return its instance , else it will return NULL.
now using this dispPtr and IDispatch
int isInfoAvailable;
dispPtr->GetTypeInfoCount(&isInfoAvailable);
if isInfoAvailable = 0 , that means this object does not provide run time type information of interfaces it supports.
if isInfoAvailable = 1 , that mean now you can query for ITypeInfo interface pointer for getting information about the interface this object supports.
now using GetTypeInfo() method you can further query for ITypeInfo interface , using which you can browse all the interface and methods of these interface supported by your COM object.
and then using Invoke and GetIDsOfName methods of IDispatch you can also execute your method at run time.
Regards
Abhishek Srivastava
Software Engg (VC++)
India ,Noida
Mobile no 9891492921
|
|
|
|
|
|
Hello,
I want to learn COM+. I am an intermediate level programmer and am currently learning C#. Can anyone suggest a good book to purchase to learn COM+?
Thanx for the help.
-Flack
|
|
|
|
|
I want to extract Thumbnails Asynchronously...
I use IExtractImage::GetLocation with the flag IEIFLAG_ASYNC .
I get back an E_PENDING which as documented is the sign that things can go on Asynchronously...
I get the object's IRunnableTask (simple QueryInterface )...
And then nothing happens.
IRunnableTask::IsRunning() always returns 0 (which is IRTIR_TASK_NOT_RUNNING ).
IRunnableTask::Run() returns E_NOTIMPL (some documentation said there's no need to call it manually, but anyhows).
So, Can someone tell me what's going wrong here ?
thanks
|
|
|
|
|
Hello Tech people,
Can any one tell me how to create the COM+ components using C#.NET. I wanted to learn about the interface design and deploy the components using C#.NET.
Please let me know, if any one find any kind of material like Gopalan Suresh Raj's website, ie.,
http://gsraj.tripod.com/dotnet/complus/complus.net_accountmanager.html
As a matter of fact, this page it self has some errors. I tried to mail the author from his mail id, but there is no response...
If you come across any of such kind, pl send me the link at my mail id.
You can reach me at SIMIBOLD@YAHOO.COM or SIMIBOLD@HOTMAIL.COM
Thanks,
Simi Agarwal
|
|
|
|
|
I want to develop an word add-in to catch the mouse event of the Word
and determin if the mouse is over some sepecified word or chart,
if true,process it by my own code and the word it's self will not receive the mouse event.
if false,trans the mouse event to the Word
How can I do?
I found all of the Word VBA,and it does not provide the mouse event.
|
|
|
|
|
Hi all,
I m working on designing a Automation Testing tool. I am using MS Active Accessibility for it. I have written some code, with which I can work with windows objects (like search window). I can get and set the text properties, click buttons. But I tried to do the same thing with a C# winForm, but it din't worked.
I am sure that the program is not getting access to objects on the winForm. But I cannot understand why it is working with standays windows objects and not winForms.
any help will be greatly appreciated.
|
|
|
|
|
Hi guys,
I have a question about COM. Do someone know how to use COM to create functions for Excel directly, that is to say without encapsulating in vba. I explain what I want to say!! I have coded an ActiveX dll with a COM object inside. I have added methods to my COM object and then I have registered the dll. When I open Excel I create a new module in vba and I can access my methods and create functions calling the methods. But I have some stability problems with MAJ+F9. So I want to create a COM object so that when I open my Excel I can access directly my C++ functions.
P.S.: I code with Borland C++ Builder 5.0 and C++ BuilderX.
|
|
|
|
|
Hi everybody
I have a COM object that has 1 method and it is dual interface written with VC++ 6.0. Is there a way to access it from a C program?
Thank you for your time
Spiros Prantalos
Miami the place to be!!
|
|
|
|
|
I assume you have the IDL file which defines your interface? Or even better, the header file produced by midl.exe? If you don't have the header file, just run midl.exe on the idl file and it'll produce it for you.
Anyway, this midl generated header file contains macros which will ease your burden on calling the COM object in C. (Just look at it and you'll figure it out)
--
Sancte Míchael Archángele, defénde nos in proélio contra nequítiam et
insídias diáboli esto præsídium. Imperet illi Deus, súpplices deprecámur:
tuque, princeps milítiæ cæléstis, Sátanam aliósque spíritus malígnos, qui
ad perditiónem animárum pervagántur in mundo, divína virtúte,
In inférnum detrude. Amen.
|
|
|
|
|
Hi, I'm new to COM and .NET, and this is a fairly advanced question. So please be kind
I have an application written in VB6 that does some database stuff. There isn't time, yet, to rewrite it all in .NET. So we are hoping to rewrite the UI in .net and use the data manipulation core via COM interop. We have been trying to use the EXE file as the COM server, rather than expose a DLL. VS.NET 2003 has imported the exe file happily and we can call some simple functions fine.
However, the COM server uses ADODB and, in particular, it is necessary to read from ADO recorsdets created in the COM code and display them in a .NET datagrid. I understand the thing to do is use the OleDbDataAdapter. When I try this, I get a runtime error:
Except: Object is not an ADODB.Recordset or an ADODB.Record.
Parameter name: adodb
Specified cast is not valid.
at System.Data.OleDb.OleDbDataAdapter.FillFromADODB(Object data, Object adodb, String srcTable, Boolean multipleResults)
at System.Data.OleDb.OleDbDataAdapter.Fill(DataSet dataSet, Object ADODBRecordSet, String srcTable)
at MyApp.Main.SetDataFolder(String DocFolder, String withFilter) in Main.vb:line 1303
I don't understand why!
I have tried using both the ActiveX and the PIA ADODB references, and have tried using the various ADODB types for recordset (there are 3 - Recordset, RecordsetClass and _Recordset); nothing helps. The only thing that did help was creating the RS within .NET land, which worked fine but doesn't help us.
The relevant code is:
Dim FolderRecordSet As ADODB.Recordset
...
FolderRecordSet = EFClient.GTCodingUpdate.FolderRS
Dim ds As DataSet = New DataSet
Try
DocumentDataAdapter.Fill(ds, FolderRecordSet, "Documents")
DataGrid.SetDataBinding(ds, "Documents")
Catch e As OleDb.OleDbException
MsgBox("OleDb: " & e.Message & vbCrLf & e.InnerException.Message & vbCrLf & e.StackTrace)
Catch e As Exception
MsgBox("Except: " & e.Message & vbCrLf & e.InnerException.Message & vbCrLf & e.StackTrace)
End Try
|
|
|
|
|
guys..
any body done menu merging for an inplace active control?
|
|
|
|
|
hi there..
Thanks for the time firstly..
I wanted to know how can u add a shared menu to your active x control..also do we need to attach a verb to be able to use Shared Menus?
kind regards
safee
|
|
|
|
|
Hi,
I hosted a .Net control in an ActiveX control, and the accelerators and the tabbing are not working anymore. Any ideas how to fix this?
Thanks
|
|
|
|
|
Hi,
I´m catching Outlook Events by using the connectin points of the DispInterface.
It all works great, but when there is only on item, for example the last contact, in the folder contact, the event handler doesen´t fire.
What´s the problem and is there any solution known ?
My second question: The event handler does only catch Events for the TopLevel Folders such as Inbox ...
When the user created a subfolder under the inbox the event handler
does not fire.
Can someone pleas help me ?
Thanks a lot, Chris
|
|
|
|
|
I'm working on a project that implements Store Events for Microsoft Exchange server. The result is a DLL project with ATL and MFC support made in
Visual C++ .NET 2003.
Because the Microsoft Exchange events doesn’t have support for managed code the application code is unmanaged . This application for listening the events must be registered in Component Services according to MSDN examples.
I registered the dll manually in Component Services , I tested it and it works, but I want to make a setup for this application and here I have two problems:
The first problem is that I didn’t succeed to add the COM application in component services automatic from setup without doing this manually.
The second problem is that using MsiOpenPackage I
must give the absolute path where the msi file is, and I want to set a relative path or if I am using MsiOpenProduct in an application that is added at Custom Action Editor ->install is returning following error: ERROR_UNKNOWN_PRODUCT.
Alin Ilie
Software Developer
BluePhoenix Solutions
|
|
|
|
|