|
In short, you don't. COM is designed to be langauge neutral, as such it only knows about COM objects, not C++ objects. Can you give more details? If so I may be able to be more helpful!
Steve
|
|
|
|
|
thanks for the response steve..
I can give u the exact situation..
Say i have a class clsA
class clsA
{
public:
clsB obj1; //class B obj
clsC obj2; //class C obj
char name[10];
void show();
}
Now if i create an object of clsA say obj3, is it possible to pass
obj3 to the COM client. Please let me know if there is a way to do this
even if its twisted...
ann
|
|
|
|
|
It's possible, but the solutions are definately "twisted", I would suggest they are worse then the problem. You could do this:
class clsA
{
public:
clsB obj1;
clsC obj2;
char name[10];
void show();
};
HRESULT DirtyHack_PassInCPPObject([in]INT_PTR pObj);
STDMETHODIMP CYouCOMObject::DirtyHack_PassInCPPObject(INT_PTR pObj)
{
clsA* pA = reinterpret_cast<clsA*>(pObj);
return S_OK;
}
clsA a;
spObj->DirtyHack_PassInCPPObject(reinterpret_cast<INT_PTR>(&a));
As you've probably guessed, I do not approve of this - But you wanted twisted. None of your coworkers will thank you for putting this in production code - If I were a manager I'd fire someone for doing so. COM objects written in any language can be called from any other language, this is one of the reasons for using COM. Breaking the rules like this destroys all this.
Steve
|
|
|
|
|
You are right steve... its real twisted...
but u think such a situation never comes..? like the need to pass a collection
of values which are dependent on each other..? If such a situation comes, wat is the
perfect way to do it..?
thanks,
ann
|
|
|
|
|
Model the data as a COM object. Once that's done you can consume the data from any COM compatible langauge. e.g. C/C++, JavaScript, VB, any of the dotNET langauges, etc......
Steve
|
|
|
|
|
sorry to bug u again steve...But can u explain a bit more on modelling the data a COM object
using the example i gave before as i am pretty new to COM..
Ann
|
|
|
|
|
It would help if I knew how the COM server was implemented. Does it use ATL, MFC, etc....
Steve
|
|
|
|
|
yup... currently it is done using ATL...
Ann
|
|
|
|
|
annjose24 wrote: Now if i create an object of clsA say obj3, is it possible to passobj3 to the COM client.
The "clean" way to do that is implementing COM objects to expose the funcionality of clsA, clsB and clsC. So you will have IClsA implemented by clsA, IClsB implemented by clsB, and so on...
Then, instead of passing the object, you can pass the interface via COM. In your current COM object you need a method like:
(I suppose that you have a pointer to an object of type ClsA in your COM object called m_pClsa)
HRESULT CYourCOMObject::GetObjectClsA ( IClsA ** ppObjClsA)
{
HRESULT hr = m_pClsa->QueryInterface(IID_IClsa, (void**)ppObjClsA);
if (SUCCEEDED(hr))
return S_OK
*ppObjClsa = NULL;
return S_FALSE;
}
The same methods for ClsB and ClsC should be in ClsA.
Do you get the idea more or less?
Regards.
|
|
|
|
|
As Stephen said, you can't, but you have the alternative of modeling the objects you want to pass with COM interfaces, as you can pass via COM that interfaces. I'm not sure if I was clear... This alternative is much more tedious but is better than nothing.
Regards.
|
|
|
|
|
Can u explain a bit more on what you meant by modelling the
objects.
Thanks,
ann
|
|
|
|
|
I'm having difficulty intializing a variable of type ENTRYLIST and I think I'm just missing something simple. I need to call IMAPIFolder::CopyMessage and the first variable is to be an LPENTRYLIST. So my code has
ENTRYLIST elMessage[] = {1, &messageEID};
m_Folder->CopyMessage(&elMessage, ...
The compiler is not liking my initialization where the variable messageEID is of type ENTRYID and is the entry ID of a message within an Exchange folder. The error from the compiler makes sense, but I'm still unsure what needs to be change.
error C2440: 'initializing' : cannot convert from 'ENTRYID *' to 'struct _SBinary *'
What type of cast or type conversion do I need to do? Thanks.
Chris Meech
I am Canadian. [heard in a local bar]
When I want privacy, I'll close the bathroom door. [Stan Shannon]
Nice sig! [Tim Deveaux on Matt Newman's sig with a quote from me]
|
|
|
|
|
This code is passing all compiler rules okay and I believe it is the correct way to set it up
SBinary sbMessage[] = {1, pMessageEID->abFlags};
ENTRYLIST elMessages[] = {1, sbMessage};
HRESULT hr = m_pFolder->CopyMessages(elMessages, N... However the call to CopyMessage is returning an error which indicates that I do not have permissions to create a message in the folder I'm trying to copy to. I suspect at the moment that my initialisation of elMessages[] is incorrect, but I don't know what else I can use to identify the message that I want to have copied.
I'm still searching but if anyone can shed some more light on extended MAPI, that whould help me out. Thanks.
Chris Meech
I am Canadian. [heard in a local bar]
When I want privacy, I'll close the bathroom door. [Stan Shannon]
Nice sig! [Tim Deveaux on Matt Newman's sig with a quote from me]
|
|
|
|
|
Hello All,
i have an com dll which implemts the IShellPropSheet Interface.
Now i will call the function AddPages from an application.
The Property Page from the comm dll should be showing in the application on an Tab Control.
All i must do is to call the function
AddPages(LPFNADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam).
I don't understand the LPFNADDPROPSHEETPAGE parameter. I think it is an callback function, but how must i implement it in my application?
Thanks for you help.
If something is unclear, because my english is bad, please let me know.
|
|
|
|
|
hi,
i want to send my custom error message to vb (or asp) from my c++ com object. i wrote a simple dll with one method
// C++ code
STDMETHODIMP _Test::TestErr ( ){
//AFX...
AfxThrowOleDispatchException( 1001 , "error occured" ); //just wrote this but tried many other methods
return S_OK;
}
'' VB code
Public Sub Test()
Dim obj as object
set obj = CreateObject("TestObj.Test")
on error goto ErrOccured
obj.TestErr
set obj = nothing
exit sub
ErrOccured:
MsgBox err.Description
set obj = nothing
End Sub
i want to see "error occured" message and also get 1001 as error number from vb exe.
i have tried many things but couldnot solve it.
Help needed!!!
thanx.
NOTE: com dll registrations WORKS, if i do not throw exception then no problem but i want to throw some error message to vb...
|
|
|
|
|
Does your object implement the ISupportErrorInfo interface?
|
|
|
|
|
gizzo,
yes and i solved the problem .
thanks.
|
|
|
|
|
hi,
i'm trying to write a shell extension for printers in c#. i use the IContextMenu and IShellExtInit interfaces to insert the menu item in the context menu - it works fine. my problem is to find out to which printer the context menu belongs.
example:
i have three printers installed on my system.
1. name: hp 5p port: lpt1
2. name: hp 1160 port: usb001
3. name: local hostprinter port: lpt1
when i click on the 'hp 1160' printer and then on my context menu item the port of 'local hostprinter' has change to 'usb001'. to do this so i need to know the name of the printer... how can i do it?
thx
eisbär
|
|
|
|
|
hi,
here is the IShellExtInit.Initialize to get the printername:
int IShellExtInit.Initialize(
IntPtr pidlFolder,
IntPtr lpdobj,
uint hKeyProgID)
{
try
{
uint CFSTR_PRINTERGROUP;
CFSTR_PRINTERGROUP =
DllImports.RegisterClipboardFormat("PrinterFriendlyName");
m_dataObject = null;
if (lpdobj != (IntPtr)0)
{
m_dataObject = (IDataObject)Marshal.GetObjectForIUnknown(lpdobj);
FORMATETC fmt = new FORMATETC();
fmt.cfFormat = CFSTR_PRINTERGROUP; fmt.ptd = 0;
fmt.dwAspect = DVASPECT.DVASPECT_CONTENT;
fmt.lindex = -1;
fmt.tymed = TYMED.TYMED_HGLOBAL;
STGMEDIUM medium = new STGMEDIUM();
m_dataObject.GetData(ref fmt, ref medium);
m_hDrop = medium.hGlobal;
uint nselected = DllImports.DragQueryFile(m_hDrop,
0xffffffff,
null,
0);
if (nselected == 1)
{
StringBuilder sb = new StringBuilder(1024);
DllImports.DragQueryFile(m_hDrop, 0, sb, sb.Capacity + 1);
string objectname = sb.ToString();
}
}
}
catch (Exception e)
{
sting err = e.ToString();
}
return 0;
}
eisbär
|
|
|
|
|
Hi
I have a ICopyHook extension DLL. But this DLL is coming to effect only when i restart my explorer i.e, by lkilling the explorer.exe. If i register the DLL, i will have to kill the explorer.exe to make it work. Is there any way by which i can make the DLL work wihtout restarting the explorer.
|
|
|
|
|
Hi,
I made a COM-client in C++ which uses the import directive and
_COM_SMARTPTR_TYPEDEF(Iclogmanager, __uuidof(Iclogmanager));
to access the methods of the COM-Server via a smart pointer.
Iclogmanager is a dispinterface and the COM-Object which implements it is a Visual-Fox-Pro COM-Server. Its image is in an exe-file and it runs as a separate process on an other machine.
I was surprised to see, that the client crashed, after I released a new version of the server, although I did not even add additional methods. It was just a line of additional code I added within a method.
To be exact, it crashed at
HRESULT _hr = raw_doQuery(tcFilterMethode, toCollParameters, &_result);
After recompilation it worked fine again.
This is absolutely not consistent with my idea of COM.
Any idea?
Thanks an best regards
Werner
|
|
|
|
|
what is an interface ?
difference between interface and a abstract class >
Vikas Amin
Embin Technology
Bombay
|
|
|
|
|
Essentially an interface is an abstract base class, but their are limitations of what is allowed to ensure compatible vtable layout between different compilers:
- No virtual destructors (as different compilers implement it differently).
- Only single inheritance (as different compilers implement multiple inheritance differently).
Probably other stuff I forgot.
Steve
|
|
|
|
|
A interface is an abstract class in c++.it's methods are not defined.A interface shows some aspects of a com component (coclass) like we have "human" component then IHand and IMouth could be it's interfaces.
danishjibbran
|
|
|
|
|
hi guys;
the IMediaSeeking @ Duration didn't work, any thougth about that?
the code would be:
#pragma once
using namespace System;
using namespace System::Runtime::InteropServices;
namespace QuartzTypeLib
{
[StructLayout(LayoutKind::Sequential), ComVisible(false)]
public ref class DsOptInt64
{
public:
DsOptInt64( long Value )
{
this->Value = Value;
}
long Value;
};
[Flags, ComVisible(false)]
public enum class SeekingCapabilities // AM_SEEKING_SeekingCapabilities AM_SEEKING_SEEKING_CAPABILITIES
{
CanSeekAbsolute = 0x001,
CanSeekForwards = 0x002,
CanSeekBackwards = 0x004,
CanGetCurrentPos = 0x008,
CanGetStopPos = 0x010,
CanGetDuration = 0x020,
CanPlayBackwards = 0x040,
CanDoSegments = 0x080,
Source = 0x100 // Doesn't pass thru used to count segment ends
};
[Flags, ComVisible(false)]
public enum class SeekingFlags // AM_SEEKING_SeekingFlags AM_SEEKING_SEEKING_FLAGS
{
NoPositioning = 0x00, // No change
AbsolutePositioning = 0x01, // Position is supplied and is absolute
RelativePositioning = 0x02, // Position is supplied and is relative
IncrementalPositioning = 0x03, // (Stop) position relative to current, useful for seeking when paused (use +1)
PositioningBitsMask = 0x03, // Useful mask
SeekToKeyFrame = 0x04, // Just seek to key frame (performance gain)
ReturnTime = 0x08, // Plug the media time equivalents back into the supplied LONGLONGs
Segment = 0x10, // At end just do EC_ENDOFSEGMENT, don't do EndOfStream
NoFlush = 0x20 // Don't flush
};
[ComVisible(true), ComImport,
Guid("36b73880-c2c8-11cf-8b46-00805f6cef60"),
InterfaceType( ComInterfaceType::InterfaceIsIUnknown )]
public interface class IMediaSeeking
{
[PreserveSig]
int GetCapabilities(SeekingCapabilities &pCapabilities );
[PreserveSig]
int CheckCapabilities( [In, Out] SeekingCapabilities &pCapabilities );
[PreserveSig]
int IsFormatSupported( [In] Guid& pFormat );
[PreserveSig]
int QueryPreferredFormat( [Out] Guid& pFormat );
[PreserveSig]
int GetTimeFormat( [Out] Guid& pFormat );
[PreserveSig]
int IsUsingTimeFormat( [In] Guid& pFormat );
[PreserveSig]
int SetTimeFormat( [In] Guid& pFormat );
[PreserveSig]
int GetDuration( long& pDuration );
[PreserveSig]
int GetStopPosition( long& pStop );
[PreserveSig]
int GetCurrentPosition( long &pCurrent );
[PreserveSig]
int ConvertTimeFormat( long& pTarget, [In] Guid& pTargetFormat,
long& Source, [In] Guid& pSourceFormat );
[PreserveSig]
int SetPositions(
[In, Out, MarshalAs(UnmanagedType::LPStruct)] DsOptInt64^ pCurrent,
SeekingFlags dwCurrentFlags,
[In, Out, MarshalAs(UnmanagedType::LPStruct)] DsOptInt64^ pStop,
SeekingFlags dwStopFlags );
[PreserveSig]
int GetPositions( long &pCurrent, long &pStop );
[PreserveSig]
int GetAvailable( long &pEarliest, long &pLatest );
[PreserveSig]
int SetRate( double dRate );
[PreserveSig]
int GetRate( double& pdRate );
[PreserveSig]
int GetPreroll( long &pllPreroll );
};
}
thanks
|
|
|
|
|