|
remove the template <> - I'm not 100% sure about the syntax.
You might want to read up on "template specialization" - the idea is to provide a special implementation of the std::greater for your CSort class.
we are here to help each other get through this thing, whatever it is Vonnegut jr. boost your code || Fold With Us! || sighist | doxygen
|
|
|
|
|
I think I got it now. Thank you!
|
|
|
|
|
a little precision :
classes (and structures, it is quite the same except on the member rights) are not designed to represent actions, but object you want to act on. you should better make a class with you data members (that represent the datas you operate on), and encapsulate your functions as members into the same class.
this is how OO was designed for...
TOXCCT >>> GEII power
|
|
|
|
|
You mean the lessThan class?
That's what's called a "functor" - it's instances act like a function, but have a few advantages (they can keep per-instance state, and using them as template parameter is much easier).
There is nothing in OO that prohibits an object class to represent an operation.
we are here to help each other get through this thing, whatever it is Vonnegut jr. boost your code || Fold With Us! || sighist | doxygen
|
|
|
|
|
peterchen wrote:
There is nothing in OO that prohibits an object class to represent an operation.
i know, but i find that representation is quite strange... anyway, anyone can code as it like...
TOXCCT >>> GEII power
|
|
|
|
|
Well the point of my reply was: this is a standard technique, they are essential to most if not all template libraries. And trust me, it's one of the less awkward things in the STL.
And if I am your project lead, you cannot code as you like
we are here to help each other get through this thing, whatever it is Vonnegut jr. boost your code || Fold With Us! || sighist | doxygen
|
|
|
|
|
toxcct wrote:
classes (and structures, it is quite the same except on the member rights) are not designed to represent actions
Sorry, but this is not correct. Take a look at the Stroustrup book[^], Chapter 25 "Roles of Classes", and you will find a sub-chapter 25.5 "Actions" that describes function objects.
toxcct wrote:
this is how OO was designed for...
Maybe, but C++ is not (just) an OO language.
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
|
|
|
|
|
Hi!
I'm making a shell extension, adding stuff to the context menu in Windows Explorer. I can find plenty of tutorials, but everyone uses ATL3 or VC++. I've already made a shell extension using the old stuff, now I want to try using the latest.
The stuff that's generated from the VS.NET 2003 ATL wizard is completely different from what I've seen. After being adviced not to use attributes (couldn't get it to work anyway) I've been trying to get the COM_MAP stuff to work, but I've not been succesfull. It generated over 10 files, but here's the main file (I think) and what I've got so far:
#include "stdafx.h"
#include "resource.h"
#include "This2That.h"
#include <ShlObj.h>
class CThis2ThatModule :
public CAtlDllModuleT< CThis2ThatModule >,
public IShellExtInit
{
public :
DECLARE_LIBID(LIBID_This2ThatLib)
DECLARE_REGISTRY_APPID_RESOURCEID(IDR_THIS2THAT, "{58F42B54-8108-44DF-8CBC-BE62D021D4D8}")
BEGIN_COM_MAP(CThis2ThatModule)
COM_INTERFACE_ENTRY(IShellExtInit)
COM_INTERFACE_ENTRY_IID(IID_IShellExtInit, CThis2ThatModule)
END_COM_MAP( )
STDMETHOD(Initialize)( LPCITEMIDLIST, IDataObject*, HKEY );
};
STDMETHODIMP CThis2ThatModule::Initialize( LPCITEMIDLIST pidlFolder, IDataObject *pdtobj, HKEY hkeyProgID ) { return E_NOTIMPL; }
CThis2ThatModule _AtlModule;
extern "C" BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
hInstance;
return _AtlModule.DllMain(dwReason, lpReserved);
}
STDAPI DllCanUnloadNow(void)
{
return _AtlModule.DllCanUnloadNow();
}
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
{
return _AtlModule.DllGetClassObject(rclsid, riid, ppv);
}
STDAPI DllRegisterServer(void)
{
HRESULT hr = _AtlModule.DllRegisterServer();
return hr;
}
STDAPI DllUnregisterServer(void)
{
HRESULT hr = _AtlModule.DllUnregisterServer();
return hr;
}
That gives me two errors:
error C3861: 'InternalQueryInterface': identifier not found, even with argument-dependent lookup
error C2259: 'CThis2ThatModule' : cannot instantiate abstract class
I've tried adding stuff from my old ATL3 project, but no luck so far... My guess is that the MAP isn't working, i.e. I'm doing something wrong...
Adding DECLARE_PROTECT_FINAL_CONSTRUCT() gave me even more errors.
I would really appreciate any help I can get! Thank you...
[ ThumbView: Adds thumbnail support for DDS, PCX, TGA and 16 other imagetypes for Windows XP Explorer. | Homepage | Thread ]
|
|
|
|
|
You're adding stuff in the wrong class. You're changing the module class, which is just the global _Module object (or whatever ATL7 calls it). You need to add a new ATL object and modify that; aside from the wizard looking different, it's pretty much the same as ATL3.1.
--Mike--
LINKS~! Ericahist | 1ClickPicGrabber | CP SearchBar v2.0.2 | C++ Forum FAQ | You Are Dumb
|
|
|
|
|
Hehe I was just about to delete my post, I noticed that too. I checked out your article code and saw that there WAS two classes. I've compiled now and it worked. So I tried to do the same thing with Attributes, and it compiles too. Now the real job begins hehe...
Thank you for replying. And thank you for all the very helpful articles here at CodeProject!
|
|
|
|
|
Hello all,
I'm writing a IE toolbar/toolband and I need to update some html elements before saving them to a file.
So far so good, everything works as expected, but I have 1 problem.
I capture the IHTMLDocument2 and loop through the IHTMLElementCollection to change the 'src' of all 'img' elements. The logic works fine, but the screen (Internet Explorer) is updated with the new source code, so all img elements in the html page are invalid (which is normal, I changed them to an invalid location to test things).
Is there any way I can prevent this update from happening?
I'm thinking of taking a copy of the IHTMLDocument2, but have no idea how to accomplish this.
Obviously setting pTempCopyDoc=pCurrentIEDoc is not working
I fail to find a real copy statement.
Anyone knows
a) how to prevent the update in IE from happening
or
b) take a copy of an IHTMLDocument2.
By the way, the strange thing is that although the screen is updated with the invalid img's, the code behind the screen is not (if I do show source or do file/save as), the img's are still the old values.
Thanks in advance
Wim
|
|
|
|
|
I am learning Program COM by ATL,I build a inpro-server dll and add a com object ComputerInfo,I only add a method to IComputerInfo and not to any thing just as bellow:
interface IComputerInfo : IDispatch
{
[id(1), helpstring("method Test")] HRESULT GetCPU(char* bufName,const int* size);
};
STDMETHODIMP CComputerInfo::GetCPU(char* bufName,const int* size)
{
// TODO: Add your implementation code here
return S_OK;
}
Compiler shows:
ATLFirst.cpp
error C2259: 'CComObject<class ccomputerinfo="">' : cannot instantiate abstract class due to following members:
atlcom.h(1823) : while compiling class-template member function 'long __stdcall ATL::CComCreator<class atl::ccomobject<class="" ccomputerinfo=""> >::CreateInstance(void *,const struct _GUID &,void ** )'
f:\microsoft visual studio\vc98\atl\include\atlcom.h(1827) : warning C4259: 'long __stdcall IComputerInfo::GetCPU(unsigned char *,const int *)' : pure virtual function was not defined
if I have change the metho to GetCPU(unsigned char* bufName,const int* size)
all right,it works well,why???
|
|
|
|
|
I think this is a problem (bug?) in the IDL compiler, that generated the unsigned char* signature instead the char*
Anyway, if you want to be able to call your component from e.g. Visual Basic or something, it's better to use BSTR type for strings. This is basically counted unicode string (Basic STRing). Then you can cope with that using helper classes CComBSTR from ATL or _bstr_t from comdef.h
Hope this helps
|
|
|
|
|
thanks a lot.and I also have a question.
unsigned char buf[]="hello";//OK
strcpy(buf,"hello");//Error:because buf is not char*
and if I forced buf to char* and use MessageBox to show it,I found many rubbish code.I don't know the advantage of the unsigned char*,could you tell me?
|
|
|
|
|
unsigned char is in equal to BYTE type from windows header. Difference between these is stated in the name of the type - both are 1 byte of size, but char is signed and unsigned char is... unsigned (unless you switch the C++ compiler to treat char as unsigned).
because in C++ the type checking is quite strict, you cannot implicitly convert unsigned to signed and vice versa. You have to state explicitly, that you really want to do it. (e.g. by casting)
Just an advice - don't use the strcpy and similar functions. Find and stick to some string wrapper - be it std::string from stl libraries or CString from MFC/ATL. This would save you lot of troubles when looking for bugs inside string manipulation (forgotten ending \0, buffer overruns or whatever)
|
|
|
|
|
Hi all,
I'm facing a big problem with strings in ATL component.
it need to append to same string in a function.
that CComBSTR object is passed to a function by reference which appends some data to it.
but in appending steps at certain stages it show increase in memory usages.
Is this memory leak.
how to work around this problem.
thanks,
Prasad
|
|
|
|
|
Can you specify how you determined memory usage has increased ?
Also check whether this link has something to say.INFO :q139071
There is no spoon.
mail
|
|
|
|
|
in my component there is memory leak.
when i was debugging application, i found in task manager that append statement of CComBSTR causes some increase in memory usage
|
|
|
|
|
I'm sure someone else will point this out...
An increase in memory usage is not necessarily an indication that the program leaks memory. CComBSTR may use temporary heap space while it does the append operation. This may cause a change in the memory size of your app. When the memory is freed (via delete or free) this is not necessarily reflected immediately by the memory being marked as free from the OS point of view.
If you do repeated appends (say, 1000 in a loop), and it still increases, that may be a better indication.
Steve S
Developer for hire
|
|
|
|
|
Hi everyone.
Recently I've began to study WTL programming and I 've got a question. Please explain me how can I create a colour bitmap from array of bits? Not colour bitmap I create like this:
HBITMAP btmp;
LPBITMAPINFO pbi;
LPBITMAPINFOHEADER pbmph;
bool CDisplay::initBmp(byte* Img)
{
if(pbi != NULL)
delete [] pbi;
if(btmp != NULL)
DeleteObject(btmp);
int headerSize = sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256;
try
{
pbi = (LPBITMAPINFO)new char [headerSize];
pbmph = &(pbi->bmiHeader);
memset(pbmph, 0, headerSize);
pbmph->biSize = sizeof(BITMAPINFOHEADER);
pbmph->biPlanes = 1;
pbmph->biCompression = BI_RGB;
pbmph->biClrUsed = 256;
pbmph->biClrImportant = 256;
pbmph->biBitCount = 8;
// fill RGBQUAD
LPRGBQUAD pRGBQ = (LPRGBQUAD)((LPSTR)pbmph + pbmph->biSize);
for( int i = 0; i < 256; i++ )
{
pRGBQ[i].rgbBlue =
pRGBQ[i].rgbGreen =
pRGBQ[i].rgbRed = i;
}
}
catch(...)
{
return false;
}
pbmph->biWidth = MaxX[0];
pbmph->biHeight = MaxY[0];
pbmph->biSizeImage = MaxX[0]*MaxY[0];
btmp = CreateDIBitmap(GetDC(), pbmph, CBM_INIT, Img, pbi, DIB_RGB_COLORS);
return true;
}
How create colour bitmap?
P.S.: Sorry for my english if I wrote with errors.
Nulla dies sine linea !!!
|
|
|
|
|
You might want to look at CreateDIBSection. This is similar to what you already have (it will return a HBITMAP handle and a pointer to the bits). You can directly modify the bits via that pointer and use the handle for selecting the object into DCs.
If you simply want to create a 24-bit colour image, you don't need to create palette information in the BITMAPINFOHEADER (set those values to 0). Then simply write an RGB TRIPLE (Blue, Green, Red) for each pixel using the pointer. Remember you will need to pad each scanline to the DWORD boundary. If you want to write a 256-colour (paletted) image, you will need to provide a colour table. Check out MSDN documentation for that information.
Another gotcha is that if you want the bitmap to be "top-down" i.e. pixel (0,0) is in the top-left corner, you must specify a NEGATIVE height value in the BITMAPINFOHEADER structure.
Hope that helps
|
|
|
|
|
TNX, That helped me.
I did it.
Nulla dies sine linea !!!
|
|
|
|
|
Hi,
I am trying to use a COM component in MFC client app. I call one Method of a this component but it throws and error with HRESULT as 0x80020008. The error code I verified corresponds to FACILITY_DISPATCH and DISP_E_BADVARTYPE.
The problem is - it works on another machine but not on my machine. Also, I am using TLH, TLI file generated for this component using #import directive.
Please provide me with some solution to this.
Thanks in advance.
Have a great day ahead!
Regards,
Sohail Kadiwala
(My Blog - http://blogs.wdevs.com/sohail/[^])
modified 21-Apr-21 21:01pm.
|
|
|
|
|
Difficult for saying without further info. But from the description I think, that you're passing some VARIANT parameter into the function, or the function expects it. (or some other VARIANT conversion takes place on the way).
Then for the problem one-machine-works-other-not I would check the values passed to the function (or possibly it can be also some operation inside the COM object) for some regional setting specific parts - number with decimal dot, dates... If you pass e.g. a number 1.2 as a VARIANT type string (VT_BSTR ) on some machines it can be a working construct, because they know that decimal dot is a separator and then can safely convert it to required number. On other machine, where is comma set as separator, the conversion can fail.
But these are just thoughts, without more details it's difficult to tell what can be wrong.
|
|
|
|
|
Hi geo
Thanks for information. Look I am not passing anything myself. The Method got absoluetly no [IN] parameter.
Also I said in my post that I am using TLH and TLI files and these are generated using #import "component.dll"
Even I have only limited information.
If possible try giving me some info regarding this error. Also, I don't have source of the Component
Have a great day ahead!
Regards,
Sohail Kadiwala
(My Blog - http://blogs.wdevs.com/sohail/[^])
modified 21-Apr-21 21:01pm.
|
|
|
|
|