|
|
The definition of your functor is wrong. You have:
Stuart Dootson wrote: struct Finder : std::unary_function<bool, int>
It should read:
struct Finder : std::unary_function<int, bool>
Here's the definition of std::unary_function from <functional> :
template<class _A, class _R>
struct unary_function {
typedef _A argument_type;
typedef _R result_type;
};
The result type comes second, not first (which I've always thought was strange).
Also, you should be #include ing <functional> for std::unary_function , as things stand you seem to be relying on some other include file including it indirectly.
And finally, this technique is not very efficient. Try something like this:
#include "stdafx.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
void main()
{
using namespace std;
typedef vector<int> data_t;
data_t data;
data.push_back(1);
data.push_back(3);
data.push_back(2);
data.push_back(1);
data.push_back(5);
data.push_back(1);
cout << "Contents before:" << endl;
copy(data.begin(), data.end(), ostream_iterator<int>(cout, " "));
cout << endl << endl;
sort(data.begin(), data.end());
data_t::iterator new_end = unique(data.begin(), data.end());
cout < "Contents after:" < endl;
copy(data.begin(), new_end, ostream_iterator<int>(cout, " "));
cout << endl << endl;
}
Steve
|
|
|
|
|
You might note the first sentence of the post you're replying to:
If the order of elements is unimportant, sort the vector (with std::sort ) before using unique .
The whole reason for using the set and stuff is to preserve the order of the elements.
|
|
|
|
|
|
|
Hi, I just want to know if it's possible to access a vector object by it's unique id.
In vector objects don't have id's you can just access them by their locations!
for example:
std::vector<myobject> objs;
objs.at(1).my_property = 'qwerty';
here 1 is the location of the object in that vector and it's not unique..
it can change if you delete or add a object on top of this object.
but i want to give them a unique id and access them by that.
Any suggestions?
|
|
|
|
|
Use std::map or std::hash_map . Use the unique ID as the map's key, the object as the associated value.
#include <map>
class MyObject
{
...
int UniqueID() const;
...
};
std::map<int, MyObject> myMap;
To insert an item:
MyObject o;
myMap.insert(std::make_pair(o.UniqueID(), o));
To retrieve an item:
MyObject anotherO = myMap[someID];
|
|
|
|
|
I have a problem with an OLE document container, which is developed in VS 6.0 and by the use of ATL no MFC is involved.
It is so when a document is loaded in the container it is loaded maximized and the menu with comes with the document is show ok. But if I restore the document down and then maximize it again then is the menu/toolbar, which comes with the document, not correctly redrawn. If I then minimize the document and then maximize it seems to be OK again. I have tried to search for similar cases on the internet but no luck so if anybody have a proposal to the solution then it would be great - many thanks in advance.
Jakob
|
|
|
|
|
Hi
I want to create a combobox and Insert/attach a ActiveX Control for writing in Hindi , So How can I Insert/attach ActiveX Control on ComboBox .
dabara
|
|
|
|
|
Hi,
I am struggling to retrieve the data returned in a safe array.
Have created two safearrays to send and receive byte[] from .net, managed to send a test string to the dll , which returns the same string back.
However when I convert that to char *, it copies all the contents of the void* from the array appending some junk characters at the end of the original string.
When i send "Test", i receive "Testxxxxxxx" in the pvdata element of the safearray structure.
Do I need to create array with any other data type?
SAFEARRAY *sfaret = NULL ;
SAFEARRAYBOUND sfBoundret[1];
sfaret = SafeArrayCreate(VT_UI1,1,sfBoundret);
sfaret = iDotNetPtr->Encrypt(sfa,"DLL.dll","DRDotNetDLLClass","Encrypt") ;
std::string str = (const char *) (sfaret)->pvData ;
I would appreciate any sugestions.
Cheers
|
|
|
|
|
How do you copy the string into the SAFEARRAY? Do you preserve the NULL terminator? If not, there's no way to determine the amount of the SAFEARRAY used by the string.
|
|
|
|
|
how to Registering namespace handlers for HTTP and HTTPS protocols within the Internet Explorer process ?
wqewqqeweqwrwerewrwe
|
|
|
|
|
|
I want to change in display of my toolbar application icon according to url value from address bar typed & clicked to go event in internet explorer.My application is internet toolbar to verify whether url typed in address bar is registered client or not & then display icon accordingly.
My objective is to get reflection in application image with go event of IE. I am using WTL,ATL,MFC with VC++6. If any one having any idea then pls. reply.
|
|
|
|
|
Hi,
I am getting this compilation while passing lpszFileName which is a char[260] to GetPrivateProfileInt which accepts LPWSTR. Can I know how to typecast this inorder to avoid compilation error.
Thanks,
Venkat
|
|
|
|
|
There's no typecast - but one of these might help:
- Use
GetPrivateProfileIntA , which is the the ASCII version of GetPrivateProfileInt . - If the string is a literal, pass it as
L"string-literal" rather than "string-literal" - Convert the char buffer(s) to wchar_t before passing into
GetPrivateProfileInt :
<div style="margin-left: 80px;"><code>char charBuffer[260];
wchar_t wcharBuffer[260];
mbtowc(wcharBuffer, charBuffer, 260);</code></div>
|
|
|
|
|
Hi, I'm new to ATL development. I've created an ATL project that creates a window embedded inside a webbrowser using an ATL control. I can compile, link and run this project and see the desired result in IE. I'm now in the process of adding functionality inside this window by calling functions in other none ATL DLLs (no DllRegisterServer inside these dlls). After adding these new dll dependencies I get the following:
In VS2003 the error states: "PRJ0019: A tool returned an error code from "Performing registration"
Doing a manual registration of my DLL I get: "DllRegisterServer in WebPlugin.dll failed. Return code was: 0x8007000e
My "WebPlugin.dll" is being compiled and linked but seems to be failing the last step of registration. Any ideas how to resolve this?
Thanks,
Chris
|
|
|
|
|
Using Ajax how we access the value from other page into the current page without redirect to other page
|
|
|
|
|
Hi Friends,
I want to do some intialization work for my addin DLL for Outlook Express/Windows MailI have implemented _IDTExtensiblity2 interface and all it's methods in my class, but none of it's methods like onConnection etc are getting invoked.
May anyone confirm whether _IDTExtensiblity2 interface works for non-office addins also?
If no, then kindly suggest some other means for doing intialization work for my addin.
Please help!!!
Thanks a lot in advance!
dolly,
N,IN
|
|
|
|
|
Hi all,
I made a dialog a preference page of some sort that transacts with the system registry. Then after i finished it i was instructed to make it a tab and have another tab. I tried that by doing this:
CPropertySheet sheet( _T("Preference"), 1 );
CPropertyPage<IDD_PREFDLG> pgPreference;
sheet.AddPage(pgPreference);
sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW | PSH_NOCONTEXTHELP;
sheet.DoModal ( *this );
Now it cannot initiate and load the functions its just the dialog thats loading and my buttons and the contents of my combobox doesnt work. What do i need to do?
This is the whole initdialog:
LRESULT CPrefDlg::OnInitDialog(UINT , WPARAM , LPARAM , BOOL& )
{
CenterWindow();
HICON hIcon = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDD_PREFDLG),
IMAGE_ICON, ::GetSystemMetrics(SM_CXICON), ::GetSystemMetrics(SM_CYICON), LR_DEFAULTCOLOR);
SetIcon(hIcon, TRUE);
HICON hIconSmall = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDD_PREFDLG),
IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR);
SetIcon(hIconSmall, FALSE);
DWORD dwDisp;
TCHAR szKey[256];
szKey[0] = _T('\0');
_tcscpy(szKey, ServiceRegEntry);
_tcscat(szKey, UPDATEMGR);
_tcscat(szKey, ServiceParam);
if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, szKey,
0, 0, REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS, NULL, &Regentry, &dwDisp))
{
printf("Could not create the registry key.");
return 0;
}
BufferSize = TOTALBYTES;
PPERF_DATA_BLOCK PerfData = (PPERF_DATA_BLOCK) malloc( BufferSize );
AttachItems();
QueryAutoCheck();
QueryAutoDownload();
QueryDownloadDay();
QueryDownloadTime();
QueryPath();
QueryEmail();
QueryReRite();
QueryMP();
CenterWindow(GetParent());
QuerySetProd();
RegCloseKey(Regentry);
Regentry = NULL;
delete Regentry;
return TRUE;
}
Thanks!,
jayjay
|
|
|
|
|
hi to all , i have 2 enum on my IDL file :
interface myInterFace
{
typedef enum RPTR_RETRACTBIN_STATUS
{
RPTR_RETRACTBIN_OK,
RPTR_RETRACTBIN_FULL,
RPTR_RETRACTBIN_HIGH,
RPTR_RETRACTBIN_NOT_SUPPORTED,
RPTR_RETRACTBIN_UNKNOWN
}RPtrRetractBinStatus;
...
HRESULT SyncRetract([out,retval] RPtrRetractBinStatus * status);
}
library myLIB
{
typedef enum RPTR_RETRACT_TRESHOLD
{
RPTR_THRESHOLD_RETRACTBIN_FULL,
RPTR_RETRACTBIN_HIGH
}RPtrRetractThreshold;
...
dispinterface _IXFSReceiptPrinterEvents
{
properties :
methods:
HRESULT StackOK(RPtrRetractThreshold reason);
};
...
}
after compile i have this error ::>> redefinition : RPTR_RETRACTBIN_HIGH
what is its solution ?(NOTE : i can not rename any enum members)
|
|
|
|
|
Hello Friends,
I am having a c++ ATL DLL built in VC 6.0
And Vista's DEP blocks it, As I found that we can set the NXCOMPAT bit (IMAGE_DLLCHARACTERISTICS_NX_COMPAT) to mark it DEP compatible so that Vista DEP will allow it to run.
by following command: (as post build step)
editbin.exe /NXCOMPAT <your binary="">
but I want to do the same in VC 6.0, and we dont have editbin command or NXCOMPAT bit in VC 6.
It's in Visual Studio 2005 and later versions.
Kindly tell me how to do the same as there must be some way out other than this command so that DEP will not block my DLL built in older vc++ 6 compiler.
Please Help!!!
dolly,
N,IN
|
|
|
|
|
Before you think about that - are you using CWindow objects? ATL 3.0 (&7.1, IIRC) relied on constructing code thunks in data memory to perform dispatching of window messages to C++ objects. This is precisely the sort of code that DEP is intended to protect against.
If you believe your DLL is OK - what's to stop you using the editbin.exe from VS2005? To make it easier, copy it into your solution's root directory and use it from there.
|
|
|
|
|
Stuart Dootson wrote: Before you think about that - are you using CWindow objects? ATL 3.0 (&7.1, IIRC) relied on constructing code thunks in data memory to perform dispatching of window messages to C++ objects. This is precisely the sort of code that DEP is intended to protect against.
If you believe your DLL is OK - what's to stop you using the editbin.exe from VS2005? To make it easier, copy it into your solution's root directory and use it from there.
------------------------------------------------------------------
Hi and thanks for replying!
I am using a simple ATL 3.0 c++ DLL project, and compiling it through Visual C++ 6.0
editbin.exe is not working even if i explicitely copy it in my root folder along with the required DLLs and exes it needs to execute.
It says unrecognized option /NXCOMPAT and is ignored!
I read some where that VS 2005 onwards every compiled page has IMAGE_DLLCHARACTERISTICS_NX_COMPAT bit set, which makes it DEP compatible, but we dont have such bit setting option in earlier VS versions. That is the main issue with me!
But I am sure there is some way of running the old built DLLs so that DEP will not stop them.
I am using ATL for the first time, so trying hard to find a way out!
Please help if u can!
Thanks a lot!
dolly,
N,IN
|
|
|
|
|
Here's a program I knocked together which will set the bit for you. It's been tested so I know it works.
#include "stdafx.h"
#include <windows.h>
#include <tchar.h>
#include <Imagehlp.h>
#include <shlwapi.h>
#include <malloc.h>
#include <iostream>
#include <string>
#pragma comment(lib, "Imagehlp.lib")
#pragma comment(lib, "shlwapi.lib")
using namespace std;
#ifndef IMAGE_DLLCHARACTERISTICS_NX_COMPAT
# define IMAGE_DLLCHARACTERISTICS_NX_COMPAT 0x0100
#endif
#ifdef UNICODE
# define tcout wcout
# define tcerr wcerr
typedef wstring tstring;
#else
# define tcout cout
# define tcerr cerr
typedef string tstring;
#endif
void PrintUsage()
{
tcout << _T("Usage:") << endl;
tcout << _T("\tSetNXCompat <file>") << endl;
}
bool Worker(LPCTSTR pDir, LPCTSTR pFile)
{
LOADED_IMAGE li;
BOOL ok = MapAndLoad(
const_cast<LPTSTR>(pFile),
const_cast<LPTSTR>(pDir),
&li,
FALSE,
FALSE
);
if (!ok)
{
return false;
}
IMAGE_NT_HEADERS *pHeaders = li.FileHeader;
pHeaders->OptionalHeader.DllCharacteristics |= IMAGE_DLLCHARACTERISTICS_NX_COMPAT;
DWORD org_sum;
DWORD new_sum;
IMAGE_NT_HEADERS *pNT = CheckSumMappedFile(
li.MappedAddress,
li.SizeOfImage,
&org_sum,
&new_sum
);
if (pNT != NULL)
{
pNT->OptionalHeader.CheckSum = new_sum;
}
else
{
tcerr << "WARNING: Failed to update checksum." << endl;
}
ok = UnMapAndLoad(&li);
return (ok) ? true : false;
}
int main(int argc, TCHAR* argv[])
{
if (argc != 2)
{
PrintUsage();
return -1;
}
tstring dir;
if (PathIsRelative(argv[1]))
{
DWORD len = GetCurrentDirectory(0, NULL);
LPTSTR pBuffer = static_cast<LPTSTR>(_alloca((len+1)*sizeof(TCHAR)));
GetCurrentDirectory(len+1, pBuffer);
dir = pBuffer;
}
else
{
dir = argv[1];
tstring::size_type pos = dir.find_last_of(_T("\\/"));
if (pos == -1)
{
tcerr << "Error in file path!" << endl;
return -2;
}
dir.erase(pos);
}
if (!Worker(dir.c_str(), argv[1]))
{
tcerr << "Failed!" << endl;
return -3;
}
return 0;
}
Steve
modified on Friday, July 11, 2008 3:33 AM
|
|
|
|
|