|
hi
I am a beginner to ATL .I made a Active control with ATL.
I can call the control's property pages in 'Active control test container' and VC++ ,but cant do that in VB(the context menu dont contain the 'Property' item).How will i do to perform that?
|
|
|
|
|
I have a COM dll with connction point interfaces. I require to sink the events in the Document class of an MFC SDI appilcation.I change the following in the document
in DeskDoc.h the following changes were made
class CDeskDoc : public COleDocument, public IDispEventImpl<
0,
CDeskDoc,
&DIID__IToolsEvents,
&LIBID_STOOLSLib,
1,
0>
{
public:
CDeskDoc();
HRESULT PassArg(BSTR * pArg);
BEGIN_SINK_MAP(CDeskDoc)
SINK_ENTRY_EX(0, DIID__IToolsEvents, 1, PassArg)
END_SINK_MAP()
}
The DeskDoc.cpp had the following added
HRESULT CDeskDoc::PassArg(BSTR * pArg)
{
BSTR chk;
chk = L"Test";
pArg = &chk;
return S_OK;
}
The following code in the MainFrame invokes the event
void CMainFrame::OnEventTest()
{
CoInitialize(NULL);
//ISDConnectionPoint *pSDConnectionPoint = NULL;
IUnknown *pSDConnectionPoint = NULL;
ITool *pTool = NULL;
HRESULT hr = CoCreateInstance(CLSID_Tool,NULL,CLSCTX_ALL,IID_IUnknown,(void**)&pSDConnectionPoint);
IConnectionPointContainer* pConnectionPointContainer;
hr = pSDConnectionPoint->QueryInterface(IID_IConnectionPointContainer, (void**)&pConnectionPointContainer);
if(SUCCEEDED(hr))
{
IConnectionPoint* pConnectionPoint;
hr = pConnectionPointContainer->FindConnectionPoint(DIID__IToolsEvents, &pConnectionPoint);
// CEventHandler* pSinkEvents = new CEventHandler();
//Get the document pointer
CDeskDoc *pDoc = (CDeskDoc*)GetActiveDocument();
GUID iid ;
BOOL bRet = pDoc->GetDispatchIID(&iid);
LPUNKNOWN lpUnknown = (LPUNKNOWN)pDoc->GetInterface(&IID_IUnknown);
DWORD dwCookie;
pConnectionPoint->Advise( lpUnknown, &dwCookie);
hr = pSDConnectionPoint->QueryInterface(IID_ISharpTool, (void**)&pTool);
pTool->Check(); //This invokes the event PassArg()
pConnectionPoint->Unadvise(dwCookie);
pConnectionPoint->Release();
pConnectionPointContainer->Release();
}
CoUninitialize();
}
This piece of code does not work.
However if i create a separate class derived from IDispEventImpl then there is no problem with the code.However i would like to sink the events in the MFC Document class it self.
Your early reply will be appreciated.
Thanks in advance.
Jafer
Jafer
|
|
|
|
|
Hello -
We have a C/C++ app witten with plain win APIs (no MFC). A nice enhancement to the project would involve the use of an ActiveX control by Infragistics. Question: Can an ActiveX control be used and accessed from plain C/C++ in an existing program that doesn't use MFC? If so, where could we find some "how to" information and possibly sample code?
Thanks,
Mike
|
|
|
|
|
where could we find some "how to" information and possibly sample code?
Everywhere, there are samples all over this site, and others, that use COM without MFC. ActiveX, or COM, is not dependent on MFC. Here is a hint, Coinitialize()
|
|
|
|
|
Mark,
Thank you for your reply. I spent some time on this great site but have to admit that I unfortunately didn't encounter the many samples you mention. Please help me in my obviously blind and confused search .
I understand the usage of CoCreateInstance() and CoInitialize(). I am puzzled however for example by how events are passed from the ActiveX control back to the C code.
Thanks in advance for the hand holding.
Mike
|
|
|
|
|
The book ATL internals had some actual samples of using something along this line using ATL. I know ATL is still a library but it is independant of MFC and is much smaller.
Sam C
----
Systems Manager
Hospitality Marketing Associates
|
|
|
|
|
|
I totally agree, I have that book as well Those are the only two books I use as an ATL reference suite.
Sam C
----
Systems Manager
Hospitality Marketing Associates
|
|
|
|
|
|
I am VC Developer and I am working on a COM wrapper for a DLL that we have.... I need to be able to pass DWORD (unsigned long) and WORD (unsigned short) values into this COM DLL.
THe Problem is that the DLL has to be able to be used from VB...When I compile my COM DLL and try and use the functions in VB it reports that VB does not support the automation type...
Any help you could give me would be greatly appreciated..
Joe Wiemann
Software Engineer
Daktronics Inc.
|
|
|
|
|
Can't you use the Variant type?
"Want to know what makes me mad? Everything!" The Ranting Swede.
|
|
|
|
|
|
I agree completely, I never use them, but then I don't do COM. I just thought that the entire purpose of the variant type was for compatibility between the C world and the VB world.
"Want to know what makes me mad? Everything!" The Ranting Swede.
|
|
|
|
|
There are no unsigned types in VB. Can you convert them to their signed counterparts before you pass them?
I vote pro drink
|
|
|
|
|
How to find the users that logged on one domain?
Which funntion or api to use?
sandos
|
|
|
|
|
Cannot add files to project.
It raise an exception and close.
|
|
|
|
|
Using CoCreateInstance(...) will create an instance, but what I need is to link to an already existing IE window. Is this possible? How can I do this?
Thx!
|
|
|
|
|
I have to read and write on the contents tab(which appears when u rigth click on any word file and select the properties).i am able to read and write rest all the tabs like (General,Summary,Statstic and custom) but not on contents. I am using IPropertySetStorage. the code i am using is given below please suggest some solution.........its urgent
the code i am using is described below
#define UNICODE
#define _UNICODE
#define WIN32_LEAN_AND_MEAN
#define UNICODE
#define _UNICODE
#include
#include
#include
#include
// Implicitly link ole32.dll
#pragma comment( lib, "ole32.lib" )
#include
// From uuidgen.exe:
//b725f130-47ef-101a-a5f1-02608c9eebac
//79c1e210-9ad8-11d5-ae31-000102572d6d
/*const FMTID fmtid = { /* d170df2e-1117-11d2-aa01-00805ffe11b8
0xd170df2e,
0x1117,
0x11d2,
{0xaa, 0x01, 0x00, 0x80, 0x5f, 0xfe, 0x11, 0xb8}
};*/
const FMTID fmtid = { /* d170df2e-1117-11d2-aa01-00805ffe11b8 */
0xb725f130,
0x47ef,
0x101a,
{0xa5, 0xf1, 0x02, 0x60, 0x8c, 0x9e, 0xeb, 0xac}
};
EXTERN_C void wmain()
{
HRESULT hr = S_OK;
IPropertySetStorage *pPropSetStg=NULL,*pPropSetStg1=NULL;
IPropertyStorage *pPropStg = NULL,*pPropStg1 = NULL;
WCHAR *pwszError = L"";
LPSTORAGE pFileStorage = NULL;
PROPVARIANT propvarWrite, propvarWrite1;
PROPSPEC propspec;
try
{
// Create a file and a property set within it.
hr = StgCreateDocfile( L"d:\\temp\\WriteRead.doc",
STGM_CREATE|STGM_SHARE_EXCLUSIVE|STGM_READWRITE,
0,
&pFileStorage);
if( FAILED(hr) ) return ;//throw L"Failed StgCreateStorageEx";
/*//#CHNG rajeev
LPSTORAGE pStorage;
hr = pFileStorage->CreateStorage( L"\005MyStorage",
STGM_CREATE|STGM_SHARE_EXCLUSIVE|STGM_READWRITE,
0,
0,
&pStorage);
LPSTREAM pStream1;
hr = pFileStorage->CreateStream( L"\005MyStream",
STGM_CREATE|STGM_SHARE_EXCLUSIVE|STGM_READWRITE,
0,
0,
&pStream1);
if ( FAILED(hr)) return;
CComBSTR ab("\005abcd");
unsigned long count;
pStream1->Write(ab,ab.Length(),&count);
*/
//
//#CHNG rajeev*/
//FMTID_DocSummaryInformation //for the summary coc
//FMTID_UserDefinedProperties
pFileStorage->QueryInterface(IID_IPropertySetStorage,(void **) &pPropSetStg1);
hr = pPropSetStg1->Create( FMTID_SummaryInformation, NULL, PROPSETFLAG_DEFAULT ,
STGM_CREATE|STGM_READWRITE|STGM_SHARE_EXCLUSIVE,
&pPropStg1 );
propspec.ulKind = PRSPEC_PROPID;
propspec.propid = 0x000000002;
PropVariantInit( &propvarWrite1 );
propvarWrite.vt = VT_LPWSTR;
propvarWrite.pwszVal = L"abc";
hr = pPropStg1->WriteMultiple( 1, &propspec, &propvarWrite, 0x00000000D);
if( FAILED(hr) ) throw L"Failed IPropertyStorage::WriteMultiple";
//////////code added by pankaj/////////////////
pFileStorage->QueryInterface(IID_IPropertySetStorage,(void **) &pPropSetStg);
hr = pPropSetStg->Create( FMTID_DocSummaryInformation, NULL, PROPSETFLAG_DEFAULT ,
STGM_CREATE|STGM_READWRITE|STGM_SHARE_EXCLUSIVE,
&pPropStg );
if( FAILED(hr) ) throw L"Failed IPropertySetStorage::Create";
// Write a Unicode string property to the property set
// propspec.ulKind = PRSPEC_LPWSTR;
// propspec.lpwstr = L"Property Name";
propspec.ulKind = PRSPEC_PROPID;
propspec.propid = 0x00000000C;
///
PropVariantInit( &propvarWrite1 );
propvarWrite1.vt = VT_LPWSTR;
propvarWrite1.pwszVal = L"Tittle";
propvarWrite.vt = VT_VARIANT | VT_VECTOR;
propvarWrite.capropvar.cElems = 1;
propvarWrite.capropvar.pElems = &propvarWrite1;
hr = pPropStg->WriteMultiple( 1, &propspec, &propvarWrite, 0x00000000D);
if( FAILED(hr) ) throw L"Failed IPropertyStorage::WriteMultiple";
LPSTR abc="Tittle";
//propspec.lpwstr = L"Contents";
propspec.propid = 0x00000000D;
propvarWrite.vt = VT_VECTOR | (VT_LPWSTR);
propvarWrite.calpstr.cElems = 1;
propvarWrite.calpstr.pElems = &abc;
hr = pPropStg->WriteMultiple( 1, &propspec, &propvarWrite, 0x000000002);
if( FAILED(hr) ) throw L"Failed IPropertyStorage::WriteMultiple";
/*propspec.propid = 0x00000000D;
propvarWrite.vt = VT_STORAGE;
propvarWrite.pStorage = pStorage;
hr = pPropStg->WriteMultiple( 1, &propspec, &propvarWrite, 0x000000002);
if( FAILED(hr) ) throw L"Failed IPropertyStorage::WriteMultiple";*/
propspec.ulKind = PRSPEC_PROPID;
propspec.propid = 0x000000003;
PropVariantInit( &propvarWrite );
propvarWrite.vt = VT_LPWSTR;
propvarWrite.pwszVal = L"RajeevSoft Inc. Punjab";
hr = pPropStg->WriteMultiple( 1, &propspec, &propvarWrite, 0x000000004);
if( FAILED(hr) ) throw L"Failed IPropertyStorage::WriteMultiple";
propspec.ulKind = PRSPEC_PROPID;
propspec.propid = 0x00000000A;
PropVariantInit( &propvarWrite );
propvarWrite.vt = VT_I4;
propvarWrite.iVal = 1234;
hr = pPropStg->WriteMultiple( 1, &propspec, &propvarWrite, 0x000000005);
if( FAILED(hr) ) throw L"Failed IPropertyStorage::WriteMultiple";
PROPID propidDictionary=PID_DICTIONARY;
WCHAR *pwszFriendlyName = L"Write/Read Properties Sample Property Set";
hr = pPropStg->WritePropertyNames( 1, &propidDictionary, &pwszFriendlyName );
if( FAILED(hr) ) throw L"Failed IPropertyStorage::WritePropertyNames";
pPropStg->Release(); pPropStg = NULL;
pPropSetStg->Release(); pPropSetStg = NULL;
pPropStg1->Release(); pPropStg1 = NULL;
pPropSetStg1->Release(); pPropSetStg1 = NULL;
pFileStorage->Release();pFileStorage = NULL;
// pStream1->Release();
}
catch( const WCHAR *pwszError )
{
wprintf( L"Error: %s (hr=%08x)\n", pwszError, hr );
}
if( pPropStg ) pPropStg->Release();
if( pPropSetStg ) pPropSetStg->Release();
if( pPropStg1 ) pPropStg1->Release();
if( pPropSetStg1 ) pPropSetStg1->Release();
}
Pankaj Mongia
|
|
|
|
|
I installed .Net,and I found the component writed with VB was correct while debug step by step,then I make the dll.But it does not work correct.(In one method of this component ,I called one function of another dll just for unzip files.)
If this is caused by .net?
sandos
|
|
|
|
|
Dear all,
Pls look at this problem.
HRESULT has many pre-defined values, each associated with an error-message,
which can be extracted using _com_error class like this :
HRESULT hr = some-method();
if(FAILED(hr)
{
_com_error ce(hr);
cout << ce.ErrorMessage();
}
Similar way how I can define a new value of HRESULT type, and map it to
app-specific error messages, which I can extract using above method.
Any timely help is apperiaciated.
|
|
|
|
|
you need to support ISupportErrorInfo in your com object (usually selected through the wizard when creating the COM project)
then call Error from your Method.
return Error(_bstr_t("Bespoke Error").copy(), IID_IObj);
This will give you a bespoke error description.
It has been suggested that you should not generate your own HRESULT, even though you can do it as M$ may use the value you generated in the future.
|
|
|
|
|
Hi,
I am embedding MSWord In my application, using OLE automation.
But when I goto save i get the saveas method is not available as the
document is been editted in another application.
Code As Follows, from the CanCloseFrame
CEmbedWordCntrItem* ViewObj;
ViewObj = ((CEmbedWordView*)pFrame->GetActiveView())
- >m_pSelection;
LPDISPATCH lpDispatch = (ViewObj->GetIDispatch());
_Document doc;
doc.AttachDispatch(lpDispatch);
COleVariant covFalse((short)FALSE);
COleVariant vtOptional((long)DISP_E_PARAMNOTFOUND,VT_ERROR);
doc.SaveAs(COleVariant("C:\\DataDoc.doc",VT_BSTR), vtOptional.........)
Cheers
Richard
|
|
|
|
|
I'm trying to create a COM obj. that has events. Is that possible? and if so, how? (you can be pretty general, i'll be able to figure most of it out)
~
SHABBA!!
|
|
|
|
|
Yeah Master, you must implement IConnectionPoints.
|
|
|
|
|
Hi,
I've got an active x control packaged up and signed in a .cab file
the only problem left is marking it safe for scripting and inialising. I have some code that has come with the internet SDK files called CATHELP.h ,.CPP and how to call them in the DLLRegisterServer function, but they don't have any effect!
I can use the regediter and manually set the implemented catigories, and it works fine then , but this isn't a good way to go.
Does anyone have any experience with the CATHELP.h,.CPP files or anyother way to mark a control as safe?
thanks.
|
|
|
|
|