|
It's been a while since I've done ATL, but it's coming back now I was wrong about the .c file not being needed - that's a *different* .c file!
The .c file defines the CLSID and IID for the ATL object and interfaces. You can compile the .c file and incorporate the .obj file into a .lib file - that's what Microsoft do in the Windows SDK (look for uuid.lib) - or just #include the .c file into your client. I usually use the second approach, so if I have generated interface files called a_i.c and a_i.h , I'd use something like the code below in the .cpp file containing my main or WinMain :
#include "a_i.h"
#define INITGUID
#include "a_i.c"
The #define INITGUID causes the code in the .c file to define variables that contain the IID and CLSID.
HTH!!!
|
|
|
|
|
Thanks Stuart,
I am confused about your two solutions.
1. The first solution is to include _i.c file into the COM consumer project, I agree and understand. Is it what you mean?
2. The second solution is to use uuid.lib?? Could this lib file contains all customer defined CLSID/IID, since this lib file is shipped before you write any customized code? I doubt it will have the same effect as solution 1.
regards,
George
|
|
|
|
|
George_George wrote: 1. The first solution is to include _i.c file into the COM consumer project, I agree and understand. Is it what you mean?
Yes
George_George wrote: 2. The second solution is to use uuid.lib?? Could this lib file contains all customer defined CLSID/IID, since this lib file is shipped before you write any customized code? I doubt it will have the same effect as solution 1.
No - I used uuid.lib as an example of how CLSID and IIDs can be packaged - in fact, how Microsoft package up CLSIDs and IIDs for COM objects defined within Windows.
I meant that you could compile your _i.c file and put the .obj file into a .lib file, then get consumers to link against the .lib file you've produced. This way of doing things could be easier if you have several COM components to distribute.
|
|
|
|
|
Thanks Stuart,
Good idea -- "compile your _i.c file and put the .obj file into a .lib file"! You mean a static lib file, and not import lib file, correct?
regards,
George
|
|
|
|
|
George_George wrote: You mean a static lib file, and not import lib file, correct?
Yep, that's right. Create a static library project in VS and add the _i.c file as a source.
|
|
|
|
|
Thanks Stuart,
I like your alternative solution.
regards,
George
|
|
|
|
|
Hi,
I have a activeX ATL control embeded in an html page. The page also defines some javascript which I'd like to call from my ActiveX object. From reading several articles I realize I could to use connectionpoints to accomplish this. However, I'm stuck with a compile error:
error C2787: '_IWebPluginControlEvents' : no GUID has been associated with this object.
Is there some step i'm missing here? Any help is greatly apperciated!
I have defined a connectionpoint within my IDL file as follows:
In "WebPlugin.idl"
[
uuid(FD84D4F2-4D92-48DE-9A16-0D2F1A43DD6D),
helpstring("_IWebPluginControlEvents")
]
dispinterface _IWebPluginControlEvents
{
properties:
methods:
[id(1), helpstring("method Finished")] HRESULT Finished();
};
coclass WebPluginControl
{
[default] interface IWebPluginControl;
[default, source] dispinterface _IWebPluginControlEvents;
};
I have implemented IProvideClassInfo2Imp and added the COM_ENTRIES as follows:
WebPluginControl.h
class ATL_NO_VTABLE CWebPluginControl :
public CComObjectRootEx<ccomsinglethreadmodel>,
public IDispatchImpl,
public IPersistStreamInitImpl<cwebplugincontrol>,
public IOleControlImpl<cwebplugincontrol>,
public IOleObjectImpl<cwebplugincontrol>,
public IOleInPlaceActiveObjectImpl<cwebplugincontrol>,
public IViewObjectExImpl<cwebplugincontrol>,
public IOleInPlaceObjectWindowlessImpl<cwebplugincontrol>,
public ISupportErrorInfo,
public IPersistStorageImpl<cwebplugincontrol>,
public ISpecifyPropertyPagesImpl<cwebplugincontrol>,
public IQuickActivateImpl<cwebplugincontrol>,
public IDataObjectImpl<cwebplugincontrol>,
public IProvideClassInfo2Impl<&CLSID_WebPluginControl, &__uuidof(_IWebPluginControlEvents), &LIBID_WebPluginLib>,
public IObjectSafetyImpl<cwebplugincontrol,>,
public IConnectionPointContainerImpl<cwebplugincontrol>,
public IConnectionPointImpl<cwebplugincontrol,&__uuidof(_iwebplugincontrolevents)>,
public IPropertyNotifySinkCP<cwebplugincontrol>,
public IPersistPropertyBagImpl<cwebplugincontrol>,
public CComCoClass<cwebplugincontrol,>,
public CComControl <cwebplugincontrol>,
public CProxy_IWebPluginControlEvents<cwebplugincontrol>
BEGIN_COM_MAP(CWebPluginControl)
COM_INTERFACE_ENTRY(IWebPluginControl)
COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY(IViewObjectEx)
COM_INTERFACE_ENTRY(IViewObject2)
COM_INTERFACE_ENTRY(IViewObject)
COM_INTERFACE_ENTRY(IOleInPlaceObjectWindowless)
COM_INTERFACE_ENTRY(IOleInPlaceObject)
COM_INTERFACE_ENTRY2(IOleWindow, IOleInPlaceObjectWindowless)
COM_INTERFACE_ENTRY(IOleInPlaceActiveObject)
COM_INTERFACE_ENTRY(IOleControl)
COM_INTERFACE_ENTRY(IOleObject)
COM_INTERFACE_ENTRY(IPersistStreamInit)
COM_INTERFACE_ENTRY2(IPersist, IPersistStreamInit)
COM_INTERFACE_ENTRY_IMPL(IConnectionPointContainer)
COM_INTERFACE_ENTRY(ISupportErrorInfo)
COM_INTERFACE_ENTRY(ISpecifyPropertyPages)
COM_INTERFACE_ENTRY(IQuickActivate)
COM_INTERFACE_ENTRY(IPersistStorage)
COM_INTERFACE_ENTRY(IDataObject)
COM_INTERFACE_ENTRY(IProvideClassInfo)
COM_INTERFACE_ENTRY(IProvideClassInfo2)
COM_INTERFACE_ENTRY(IPersistPropertyBag)
COM_INTERFACE_ENTRY_IID(IID_IObjectSafety, IObjectSafety)
COM_INTERFACE_ENTRY(IConnectionPointContainer)
END_COM_MAP()
BEGIN_CONNECTION_POINT_MAP(CWebPluginControl)
CONNECTION_POINT_ENTRY(__uuidof(_IWebPluginControlEvents))
CONNECTION_POINT_ENTRY(IID_IPropertyNotifySink)
END_CONNECTION_POINT_MAP()
</cwebplugincontrol></cwebplugincontrol></cwebplugincontrol></cwebplugincontrol></cwebplugincontrol></cwebplugincontrol></cwebplugincontrol></cwebplugincontrol></cwebplugincontrol></cwebplugincontrol></cwebplugincontrol></cwebplugincontrol></cwebplugincontrol></cwebplugincontrol></cwebplugincontrol></ccomsinglethreadmodel>
The proxy class (auto-generated) looks like:
#pragma once
template<class t="">
class CProxy_IWebPluginControlEvents :
public IConnectionPointImpl<t,>
{
public:
HRESULT Fire_Finished()
{
HRESULT hr = S_OK;
T * pThis = static_cast<t>(this);
int cConnections = m_vec.GetSize();
for (int iConnection = 0; iConnection < cConnections; iConnection++)
{
pThis->Lock();
CComPtr<iunknown> punkConnection = m_vec.GetAt(iConnection);
pThis->Unlock();
IDispatch * pConnection = static_cast<idispatch>(punkConnection.p);
if (pConnection)
{
CComVariant varResult;
DISPPARAMS params = { NULL, NULL, 0, 0 };
hr = pConnection->Invoke(1, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, ¶ms, &varResult, NULL, NULL);
}
}
return hr;
}
};
</idispatch></iunknown></t></class>
I am using Visual Studio 2003 under windows XP SP2
MIDL compiler version 6.00.0361
Every ATL.dll on my system is versioned > 3 (not sure how to check the exect one visual studio is using)
|
|
|
|
|
Ok I've figured it out, I was placing code in the wrong spot inside my idl file. Specifically, the following needed to be inside the "library" tag.
[
uuid(FD84D4F2-4D92-48DE-9A16-0D2F1A43DD6D),
helpstring("_IWebPluginControlEvents")
]
dispinterface _IWebPluginControlEvents
{
properties:
methods:
[id(1), helpstring("method Finished")] HRESULT Finished();
};
|
|
|
|
|
I need a sample application for connecting to sql server database in ATL.
Thanks..
|
|
|
|
|
|
How can create I an ActiveX which can still active after close IExplorer?
|
|
|
|
|
I wrote a plugin for IE with ATL. Now my requirement is to pop up a modeless dialog in IE so that it can display some information extracted from the page of my IE explored.
When I use DoModal(), it works fine
But I need to show it modeless, so when I use (SW_SHOWNORMAL), my plug in crashed. it says error in atlwin.h 2815 line
Anyone can tell me why and do me a favor? Below is my code:
CMainDialog d;
HWND hIE;
HRESULT hr = m_pBrowser->get_HWND((long*)&hIE);
d.Create(hIE);
d.ShowWindow(SW_SHOWNORMAL);
//error code in atlwin.h
virtual ~CWindowImplRoot()
{
#ifdef _DEBUG
if(m_hWnd != NULL) // should be cleared in WindowProc
{
ATLTRACE(atlTraceWindowing, 0, _T("ERROR - Object deleted before window was destroyed\n"));
ATLASSERT(FALSE);
}
#endif //_DEBUG
}
|
|
|
|
|
Hi everyone,
Look at follow code:
UINT uFormat = DT_WORDBREAK|DT_EXTERNALLEADING;
CRect rect(10,30,200,60);
::DrawText(dc,"hi harry, how are you! there are no persons in the school fdsfdsfsd fsdfdsf",-1,rect,uFormat);
Run this code in the OnPaint(), the result is that there is no compelete string show in the region(CRect rect(10,30,200,60));
I want to add "..." into the end string display. If someone can help me, please tell me how.
Thanks.
|
|
|
|
|
Add DT_END_ELLIPSIS to your uFormat.
- S
50 cups of coffee and you know it's on!
A post a day, keeps the white coats away!
|
|
|
|
|
Hi Steve,
It's only one line for this case, I want to show string like this:
many of them virtual, to convert an object to and from other types. This conversion is mainly used by the property browser to convert...
Can you help me how show string in mutlti lines with '...'.
Thanks
|
|
|
|
|
Yeah, I don't think end ellipsis works with multiline. You might try DT_WORD_ELLIPSIS.
I saw some post about adjusting the height of the rect to make it an integral of the font size, but that seems like a pain.
- S
50 cups of coffee and you know it's on!
A post a day, keeps the white coats away!
|
|
|
|
|
DT_WORD_ELLIPSIS also is fit in this case.
|
|
|
|
|
I wanna implement a toolbar for Windows using WTL classes like CToolBarCtrl. For the toolbar to work I saw in numerous examples that you have to create a reflection window, that is essentially a hidden parent for the toolbar so you can fetch the commands send by the toolbar.
I wonder if you could implement a reflective toolbar using the CWindowWithReflectorImpl?
I never got it to work though. The created window did not repaint itself and the toolbar was not visible. Anyone here knows how to use CWindowWithReflectorImpl?
Thanks in advance!
Happy coding,
Philipp Kursawe
|
|
|
|
|
Some coding standards at my end says that, Do not use smart types in a container?
Does anyone know reason for this?
|
|
|
|
|
Any extra things that one has to consider while using this?
|
|
|
|
|
When copying container auto_ptr will incur problems.
No problem with shared_ptr .
I'm using shared_ptr in a vector now.
system
|
|
|
|
|
Thanks for the answer.
but my other question is e.g.
what care needs to be taken if i use _bstr_t in a vector?
|
|
|
|
|
_bstr_t is like shared_ptr, it can be copied,
but there is a problem about the semantic:
For example,
1. let vecotr a contain some _bstr_t pointers,
2. copy a to b
3. get some pointer in b, and changed the object through the pointer, think what about a.
I think it is not the semantic of copy.
system
|
|
|
|
|
Here is my test code.
class fig_line
{
public:
fig_line(ADO::_ConnectionPtr connection, const std::wstring &source_query);
virtual ~fig_line(void);
fig_line(){}
private:
fig_line(const fig_line &a_fig_line){}
fig_line & operator=(const fig_line &a_fig_line){return *this;}
}
std::vecotr<fig_line> m_lines;
m_lines.resize(10);
</fig_line>
class fig_line
{
public:
fig_line(ADO::_ConnectionPtr connection, const std::wstring &source_query);
virtual ~fig_line(void);
fig_line(){}
fig_line(const fig_line &a_fig_line){}
fig_line & operator=(const fig_line &a_fig_line){return *this;}
}
std::vecotr<fig_line> m_lines;
m_lines.resize(10);
</fig_line>
class fig_line
{
public:
fig_line(ADO::_ConnectionPtr connection, const std::wstring &source_query);
virtual ~fig_line(void);
fig_line(){}
}
std::vecotr<fig_line> m_lines;
m_lines.resize(10);
</fig_line>
Why can't case 1 be compiled?
system
|
|
|
|
|
Your class must have a public or default copy constructor and assignment operator. std::vector requires an accessible copy constructor and assignment operator in order to do operations such as resizing.
In case #1, both are private; thus, case #1 does not compile. In case #2, both are public; thus, this case compiles. In case #3, the class uses the default copy constructor and assignment operator (which are too public); thus, it compiles likewise.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
modified on Tuesday, September 16, 2008 1:24 PM
|
|
|
|
|