|
-
October 16th, 2006, 09:05 AM
#1
passing vector by reference
I have a winapi where I try to pass a reference of a vector (but it is not as simple vector as in the tutorials or examples) to function but can not get it together...
I have a Gui. If a certain button is clicked it will initiate EnumProc. I would like to pass a reference of an empty vector in the additional LPARAM of EnumProc. If windows of my criteria are found under the EnumProc i would put the handle, name of the window and some other stuff in the vector. They would then be accessible when the EnumProc has ended...
Currently when Compiling i'm getting:
expected primary-expression before "arMyClass"
at the line where EnumProc is being called (2nd bolded line)
I tried to bold the parts that I think/know are causing this. Any help appreciated.
Code:
.
.
.
class CMyClass
{
public:
CMyClass() {}
CMyClass(int def_x, int def_y, string def_nimi, HWND def_handu) : x(def_x), y(def_y), nimi(def_nimi), handu(def_handu) {}
virtual ~CMyClass() {}
int x, y;
string nimi;
HWND handu;
};
BOOL CALLBACK EnumProc(HWND thwnd,vector<CMyClass*> &v);
HINSTANCE hInstance;
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
.
.
.
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
.
.
.
case WM_COMMAND :
.
.
.
case BN_CLICKED:
.
.
.
if ( LOWORD (wParam) == 6 ) {
vector<CMyClass*> arMyClass;
//testing if it works, adding some stuff
arMyClass.push_back(new CMyClass(2, 40, "kasdsdlle", NULL));
arMyClass.push_back(new CMyClass(4, 60, "visdsadlle", NULL));
EnumWindows((WNDENUMPROC) EnumProc,vector<CMyClass*> arMyClass);
.
.
.
}
.
.
.
}
BOOL CALLBACK EnumProc(HWND thwnd,vector<CMyClass*> l)
{
//THESE LINES JUST FOR TESTING
//testing if I can access the vector here
vector<CMyClass*>::iterator itPos = l.begin();
for(; itPos < l.end(); itPos++) {
string teksti = (*itPos)->nimi;
char *p;
p=&teksti[0];
MessageBox(NULL, p, "otsikko", MB_OK);
}
//End of test lines
char buff[MAX_PATH+1];
GetWindowText(thwnd,buff,MAX_PATH+1);
if(strstr(buff, myCriteria)) {
//adding to the vector
l.push_back(new CMyClass(2, 40, "third", NULL));
}
return TRUE;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|