|
The Visual C++ forum is the place for C++ related stuff.
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
hmm...
All the C++ boffins will tell you to use the reference version because it's "safer", and that's their justification for just about everything to do with the language Just remember that you can't reassign references and you can with pointers - this might nudge you towards the pointer version.
Unless you have a fairly strange function, there is no performance gain from using one in particular. If you want to emulate the powers-that-be and go in the direction the C++ standards commitee have not-so-subtlely been trying to push us in, use the reference version. Be aware of the possiblity of unseen anonymous objects being created when you pass by reference (if you do indeed have to create a temporary const object) - obviously this isn't possible with pointers and prevents this bit of bloat.
I go with references cos company's love to see them in your code. To be honest there's not much to gain from it, but try and stick to one in style. It also stops you having to stick &'s everywhere
|
|
|
|
|
[ATL, VC++ 6.0 SP6]
Hello to all. I am working on an ATL COM project that needs to interface with a 3rd party application. This application uses IDispatch interfaces with CP-based event interfaces that go along with them (shudder ).
I have the following problem. I have an object that uses two interfaces, and implements two more as well as the connection-point-based event interface. Problem is, I now need to add another event interface sink to the object. After adding it, I am unable to call DispEventAdvise because the compiler cannot resolve the ambiguity between Event interface and the other.
I have tried various means of qualifying the function call, including using the expanded form of one version of the IDispEventImpl -derived class, but I cannot get any of them to work. If anyone has any idea how to resolve this, I would love to hear about it.
The def of the object's class is as follows (some identifiers renamed):
class ATL_NO_VTABLE CxxxxMWare : <br />
public CComObjectRootEx< CComSingleThreadModel>,<br />
public CComCoClass< CxxxxMWare, &CLSID_xxxxMWare>,<br />
public IDispEventImpl< 1, CxxxxMWare, &DIID_EAxxxxxxxx, &LIBID_xxxxLib, 1, 0 >,<br />
public IDispatchImpl<IxxxxMWare, &IID_IxxxxMWare, &LIBID_xxxxMIDDLEWARELib>,<br />
public IDispatchImpl<IxxxxMiddleWare, &IID_IxxxxMiddleWare, &LIBID_xxxxSERVERLib>,<br />
public IDispatchImpl<IMxxxxxxxxAPICB, &IID_IxxxxxxxxAPICB, &LIBID_xxxxSERVERLib><br />
BEGIN_SINK_MAP(CxxxxMWare)<br />
SINK_ENTRY_EX(1, DIID_EAxxxxxxxx, 0x01, BxxxxSxxxx)<br />
SINK_ENTRY_EX(1, DIID_EAxxxxxxxx, 0x02, AxxxxSxxxx)<br />
SINK_ENTRY_EX(1, DIID_EAxxxxxxxx, 0x03, WxxxxCxxxx)<br />
SINK_ENTRY_EX(1, DIID_EAxxxxxxxx, 0x04, Dxxxx)<br />
SINK_ENTRY_EX(1, DIID_EAxxxxxxxx, 0x05, AxxxxCxxxx)<br />
SINK_ENTRY_EX(1, DIID_EAxxxxxxxx, 0x06, OxxxxAxxxx)<br />
SINK_ENTRY_EX(1, DIID_EAxxxxxxxx, 0x07, Mxxxx)<br />
SINK_ENTRY_EX(1, DIID_EAxxxxxxxx, 0x08, Cxxxx)<br />
SINK_ENTRY_EX(1, DIID_EAxxxxxxxx, 0x09, Dxxxx)<br />
<br />
END_SINK_MAP()<br />
The class/object, as written, works correctly. I need to receive events from the DIID_ECxxxxCxxxx interface, and when the commented lines are uncommented, calls to DispEventAdvise from within the class' code become ambigious - the compiler cannot resolve between they two IDispEventImpl classes.
Any thoughts? I would perfer not to have to create a separate class for this Event interface, but that is what I will do if I cannot resolve this within the next day or so...
AdvaThanksnce!
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
Have you tried qualifying the DispEventAdvise call with the name of the base class whose events you're trying to advise - like this:
IDispEventImpl< 1, CxxxxMWare, &DIID_EAxxxxxxxx, &LIBID_xxxxLib, 1, 0 >::DispEventAdvise(blah blah blah);
I put a typedef in my class declarations to give the base class a nice name. For example:
typedef IDispEventImpl<1, xxxxBrowserView, &DIID_HTMLElementEvents2, &LIBID_MSHTML, 4, 0> HTMLElementEventsSink;
allows me to write
HTMLElementEventsSink::DispEventAdvise(blah blah blah);
Stuart Dootson
'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'
|
|
|
|
|
[EDIT] Gah! Never mind... I had a little brain cramp; it is working correcly now. Thanks again for helping me find the problem! [/EDIT] Yes... "I have tried various means of qualifying the function call, including using the expanded form of one version of the IDispEventImpl-derived class, but I cannot get any of them to work."
At least I thought I did... Now it works? I must have been copying over the template dec incorrectly...!
Well, now that code works, but other stuff is failing to compile:
...\atl\include\atlcom.h(3698) : error C2243: 'static_cast' : conversion from
'class ATL::IDispEventSimpleImpl<1,class CxxxxMWare,&struct _GUID const DIID_EAxxxxxxxx> *const ' to
'class CxxxxMWare *' exists, but is inaccessible Oh, well... I will just put the second event handler into its own little class and use it. Thanks for the post, anyway.
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
Whoops - should have read your message properly
However - that error message looks like you're calling DispEventAdvise from a const method.
Stuart Dootson
'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'
|
|
|
|
|
Nah; I changed the template decl to a typedef for clarity/readability but forgot to specify it as public when I used it in the class decl.
Besides, without your post I would never have gone bac and tried again.
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
I have successfully created an addin for Word using the article provided by Amit Dey on Outlook 2000. There is one problem that i am facing.
How do I make my addin work with multiple instances of Word?? Currently the addin only works with one instance of Word.
Any help would be greatly appreciated.
|
|
|
|
|
hi!
I want to increase or decrease the width of my activex control written in
VC7.1 using ATL. I have done following in the InitNew method but no effect.
SIZEL sz = {129,211};
AtlPixelToHiMetric(&sz,&m_sizeExtent);
m_sizeNatural = m_sizeExtent;
Any ideas?
what if i dont want user to increase the height and width of my control?
Thanks in advance.
Ahmad Jalil Qarshi
|
|
|
|
|
I think that may be i have posted this question to a wrong forum. If someone knows the right place to post this question. Please help me.
Thanks.
Ahmad Jalil Qarshi
|
|
|
|
|
Hi,
does someone have a stdafx.h file for an MFC project with WTL support? I have followed the information in the articles here and elsewhere in the web I can find, but am having problems including atlctrlx.h, atlctrlw.h - there seems to be some confusion on the part of the compile with common names such as CClientDC, CWindowDC, even though I am using #define _WTL_NO_AUTOMATIC_NAMESPACE
as suggested.
|
|
|
|
|
|
Thanks Mike. I understand this.
I will make changes in the WTL source files for my projects correct?
|
|
|
|
|
|
to conditional Compilation in the .idl file, if yes how ?, I am facing tough time doing this!
Thanks
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
You can use any C++ preprocessor directives.
With best wishes,
Vita
|
|
|
|
|
Vi2 wrote:
You can use any C++ preprocessor directives.
Hi Mr. Vita,
Thanks For Reply, actually condtional compilation cannot be possible without preprocessor, actually i fail to explain my problem. when ever I use preprocessor to hide a Interface and corresponding .h and .cpp file , it's still compile that .cpp files and give me compiler errror. though i resolve that error by removing corresonding file from the project.
Is there any way to stop compilation of particular cpp file through Visual Studio 6.0!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
ThatsAlok wrote:
Is there any way to stop compilation of particular cpp file through Visual Studio 6.0!
You can use the different Active Configuration (Build -> Configurations...) to make the different targets. As well as we use the Debug and Release configurations.
With best wishes,
Vita
|
|
|
|
|
Hi
I have a graph control built using ATL3.0 and used this control in VC++ client application.This control is working fine in my windows XP sys,but siezed to work properly on win 98.The problems are
1) we are displaying 5 grid lines along both X and Y axes.but on win 98 only 2 grids are being displayed along Y axis.
2) when I try to load a saved file(graph) on win 98 the graph is exceeding the plot area.
Every thing seems to be working fine on win XP.Has there any thing to do with ATL.dll. Infact we have used the correct ANSI version of ATL.dll for both 98 and XP..
Can any one plzzzzzzz help me??????
ThnX in Advance.
Naveen.V
|
|
|
|
|
I am complete newbie in this field. I need to install DLL in MTS via VC++ 6.0 program. Any help is appreciable.
Thanks in advance.
|
|
|
|
|
Any idea how to embed an exectuable inside another executable, and then from with in your program, call the embeded exectuable with out creating another process or wrting the embed exectuable to disk?
I have a C++ program (straight C++, not managed). It has some logic and then depending on a number of conditions, ShellExecute()s another exectble file (client.exe), which happens to be a .net file. Is there anyway that I can add this client.exe file as a resource of my C++ program, and then call the beginning of the code from within the C++ program, so I wouldn't have to extract the resource or create a new process
Please help
Thanks,
Jason A. Donenfeld
PS: This is what I have now:
<br />
#define WIN32_LEAN_AND_MEAN<br />
#include<br />
#include<br />
#include<br />
<br />
#define INSTANCEMESSAGE "ShowZIM"<br />
#define WINDOW_TITLE "ZX2C4InstantMessenger"<br />
#define MUTEX_STRING "Local\\ZX2C4IM"<br />
#define FILE "client.exe"<br />
<br />
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)<br />
{<br />
if(_tcscmp(lpCmdLine,"clone"))<br />
{<br />
CreateMutex(NULL,TRUE,MUTEX_STRING);<br />
if(GetLastError()==ERROR_ALREADY_EXISTS)<br />
{<br />
SendMessage(FindWindow(NULL, WINDOW_TITLE), RegisterWindowMessage(INSTANCEMESSAGE), NULL, NULL);<br />
return 0;<br />
}<br />
}<br />
ShellExecute(NULL,NULL,FILE,lpCmdLine,NULL,SW_SHOW);<br />
return 0;<br />
}<br />
|
|
|
|
|
I programmed my Function like one in the book from Duffie: Financial Instrument Pricing using c++
. The Problem is That the output is a row vektor.
Does anyone have an Idea How to make the Output a Column Range and not a row Vektor under Excel ?
Here s the code:
STDMETHODIMP CMyExcelFunctions::MyArrayFunction(VARIANT* range1, VARIANT* range2, VARIANT* result)
{
// Convert input to vector
Vector<double> v1=COMUtils::ExcelRangeToVector(range1);
Vector<double> v2=COMUtils::ExcelRangeToVector(range2);
// Determine the minimum size of both input arrays
size_t size;
if (v1.Size()<v2.size()) size="v1.Size();
size=v2.Size();
//" add="" both="" arrays="" (v1+v2="" does="" not="" take="" different="" vector="" sizes="" in="" account)
vector<double=""> vr(size);
for (int i=vr.MinIndex(); i<=vr.MaxIndex(); i++)
{
vr=v1+v2;
}
// Put result in safe array
CComSafeArray<double> res;
res.Create(size);
LONG j;
for (i=vr.MinIndex(), j=0; i<=vr.MaxIndex(); i++, j++)
{
res.SetAt(j, vr);
}
// Put safe array in variant
CComVariant v(res);
// Put resulting variant in result
v.Detach(result);
return S_OK;
}
Vector<double> COMUtils::ExcelRangeToVector(VARIANT* range)
{
// Check if a range object was passed
if (range->vt!=VT_DISPATCH)
{
// No range passed so just return the double value in a vector
Vector<double> v(1);
v[v.MinIndex()]=range->dblVal;
return v;
}
// Retrieve the Excel range object from the variant and convert it to a Vector<double>
Excel::RangePtr pRange=range->pdispVal;
return COMUtils::ExcelRangeToVector(pRange);
}
// Convert an Excel range to our vector template class
Vector<double> COMUtils::ExcelRangeToVector(Excel::RangePtr pRange)
{
// Get the number of rows and columns in the range
int columns=pRange->Columns->Count;
int rows=pRange->Rows->Count;
// Create the vector with the correct size
Vector<double> v(columns*rows);
// Iterate the rows and columns
int index=v.MinIndex();
for (int r=1; r<=rows; r++)
{
for (int c=1; c<=columns; c++)
{
// Add each element in the range to our vector
v[index++]=(((Excel::RangePtr)pRange->Item[r][c])->Value).dblVal;
}
}
// Return the vector
return v;
}
Thanks
|
|
|
|
|
Hi,
I was wondering if anyone had implemented a WTL application as a static library. I've tried this with a simple dialogue and can't get it working.
In the function AtlModuleAddCreateWndData, the line
::EnterCriticalSection(&pM->m_csWindowCreate);
produces an assertion (where pM is of the type _ATL_MODULE*).
It appears that the module has not been created and so I was wondering how I would go about doing this.
Thanks in advance.
Marcpolo
|
|
|
|
|
in my SDI app a call to UpdateAllViews from a user thread fails .
I was wondering if this is disallowed .
UpdateAllViews call from within the main thread works fine .
Is there a workaround for this ?
|
|
|
|
|
In general, passing MFC objects between threads will not work because MFC keeps thread-specific data structures. Use a custom window message instead - the worker thread can post this message to the main thread, which would then call UpdateAllViews() .
--Mike--
Visual C++ MVP
LINKS~! Ericahist | 1ClickPicGrabber | CP SearchBar v2.0.2 | C++ Forum FAQ
Strange things are afoot at the U+004B U+20DD
|
|
|
|
|