|
if your customer allow you to use stl and function OnFunctionkeysCallsate and OnWindowNewlogview have same signature, you can use this piece of code to achieve same:-
void Function1(int i)
{
cout<<"Hello in Function 1 Number " <<i;
}
void function2(int i)
{
cout<<"Hello in Function 2 Number " <<i;
}
typedef void (*MySingleArgFunction) (int);
vector<MySingleArgFunction> vecFuncPtr;
vector<MySingleArgFunction>::iterator it;
vecFuncPtr.push_back(&Function1);
vecFuncPtr.push_back(&function2);
it=vecFuncPtr.begin();
while(it!=vecFuncPtr.end())
{
(*it)(20);
it++;
}
and if still insist on CPtrArray, so here is the pointer to solve above problem :-
you missed a & in
Vaclav_Sal wrote: pArray.Add((void*) (OnFunctionkeysCallsate)); pArray.Add((void) (OnWindowNewlogview));
which should be written as
pArray.Add((void*) &OnFunctionkeysCallsate);
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Thanks for your reply.
I have already tried adding &. The compiler does not like it.
pArray.Add((void*)&OnFunctionkeysCallsate);
And here is the error message
E:\0 OpenLog\V1\TCC\MainFrm.cpp(683) : error C2276: '&' : illegal operation on bound member function expression
I'll take a look at the vector method.
I am also looking at MFC CMenu.
Vaclav
|
|
|
|
|
Vaclav_Sal wrote: have already tried adding &. The compiler does not like it. pArray.Add((void*)&OnFunctionkeysCallsate); And here is the error message
ahh i understand, i believe OnFunctionkeysCallsate is the function defined in the class, if yes then you have to put the code like this:-
pArray.Add((void*)&YouClassNameWhereFunctionISDefines::OnFunctionkeysCallsate);
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Sorry, still no go
Here is the compiler error message:
MainFrm.cpp
E:\0 OpenLog\V1\TCC\MainFrm.cpp(685) : error C2589: '&' : illegal token on right side of '::'
E:\0 OpenLog\V1\TCC\MainFrm.cpp(685) : error C2059: syntax error : '::'
It seems that this should work. BTW it is all in MainFrm.cpp
pArray.Add((void*)CMainFrame::&OnFunctionkeysCallsate);
Unless you are just curious why it does not, you can just drop it. I am still looking at the CMenu , maybe that will work.
I basically need an array of function pointers I can execute in desired sequence.
Thanks for all your help.
Vaclav
|
|
|
|
|
I'm working on a class array, but I thought it would structure my data different.
I'm working with this code below. I was hoping it would create a single object, with 2 internal members of [0] and [1] creating a single object uaListBoxPtrArray with 2 members [0] Tim and [1] John, Tim and John being inside uaListBoxPtrArray.
But it looks like it creates separate objects
uaListBoxPtrArray[0] which is Tim
uaListBoxPtrArray[1] which is John
and I would have to pass uaListBoxPtrArray[0], uaListBoxPtrArray[1] to a function.
I want to be able to pass the single object to a function in the future, and not separate objects. pass uaListBoxPtrArray by itself, with Time and John inside it.
Q: Is my result or implementation correct?, and that this is the correct result format for the method below?. Or do I now need to work on the constructor, to form a single object of records.
DWORD dwCount;
DB_UserAccount dbUA;
dwCount = dbUA._get_UserAccount_Listbox_Count();
UA_Listbox **uaListBoxPtrArray;
uaListBoxPtrArray = new UA_Listbox*[dwCount];
uaListBoxPtrArray[0] = new UA_Listbox;
uaListBoxPtrArray[0]->iUserID = 47;
uaListBoxPtrArray[0]->szFirstName = L"Tim";
uaListBoxPtrArray[0]->szLastName = L"Parker";
uaListBoxPtrArray[0]->szAccountName = L"tparker";
uaListBoxPtrArray[1] = new UA_Listbox;
uaListBoxPtrArray[1]->iUserID = 48;
uaListBoxPtrArray[1]->szFirstName = L"Joe";
uaListBoxPtrArray[1]->szLastName = L"Smoe";
uaListBoxPtrArray[1]->szAccountName = L"jsmoe";
|
|
|
|
|
jkirkerx wrote: I was hoping it would create a single object
But the lines:
uaListBoxPtrArray = new UA_Listbox*[dwCount];
uaListBoxPtrArray[0] = new UA_Listbox;
...
uaListBoxPtrArray[1] = new UA_Listbox;
specifically say: create an array of object pointers and create two new objects which can be referenced by the pointers in the array. If you want a single object to hold both names then you need a different class definition.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Thanks Richard
I just want to make sure that I understood your thoughts correctly first.
Richard MacCutchan wrote: create an array of object pointers
uaListBoxPtrArray = new UA_Listbox*[dwCount];
Richard MacCutchan wrote: create two new objects which can be referenced by the pointers in the array
uaListBoxPtrArray[0] = new UA_Listbox;
uaListBoxPtrArray[1] = new UA_Listbox;
|
|
|
|
|
That's correct, if you break things down to their constituent parts you get:
UA_Listbox UA_Listbox* UA_Listbox*[dwCount] uaListBoxPtrArray
So the statement
uaListBoxPtrArray = new UA_Listbox*[dwCount];
initialises an array variable by creating the array of pointers (via the new operator). Each array element can then be initialised with a pointer to an object of the type previously defined.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Thanks again Richard.
Well my class array worked. I was able to pass the array to the function and get the values back. But after implementing it, changing the design and format several times, I determined that it will never work in the way I wanted it to.
After studying how they work in principle, the source which is a ODBC function creates pointers to buffers in the heap, in which the SQL Handle maintains, and once the handle is freed, the pointers are lost.
So I brought the GUI (hWnd) to the ODBC, populated the listbox, and exited.
No one wonder I was confused, but overall in the end, I learned alot about pointers. Oh Well.
|
|
|
|
|
Why not this way?
UA_Listbox *uaListBoxArray;
uaListBoxArray = new UA_Listbox[dwCount];
uaListBoxArray[0].iUserID = 47;
uaListBoxArray[0].szFirstName = L"Tim";
uaListBoxArray[0].szLastName = L"Parker";
uaListBoxArray[0].szAccountName = L"tparker";
uaListBoxArray[1].iUserID = 48;
uaListBoxArray[1].szFirstName = L"Joe";
uaListBoxArray[1].szLastName = L"Smoe";
uaListBoxArray[1].szAccountName = L"jsmoe";
delete [] uaListBoxArray;
|
|
|
|
|
That's a question to a question, in which I cannot answer at the moment.
|
|
|
|
|
You asked how to define a single object containing two UA_ListBox objects and I gave you a definition: Rather than define an array of two pointers, I defined an array of two UA_ListBox objects. If that is not what you want, then sorry, I don't understand the question. (Besides, even your own definition of an array of two pointers to objects in a way satisfies your request: it is a single object representing two objects. Why is this not sufficient for your purposes?)
|
|
|
|
|
I can comment on it now, it was a fine post.
I implemented your revised edition, and liked it better, because I wasn't using the new statement for each record.
It worked great, thank you very much.
I ended up deleting the whole thing, and took the gui (hwnd)to the ODBC function. The ODBC function created pointers to buffers, that were held by the SQLHandle. The first array record was fine, but records after that were corrupted.
So I have to rethink how this would work in ODBC, Which is another subject. I'm thinking that I need to implement your version of the array inside the ODBC Function itself.
The code below was a bad idea. I tried using the array directly in the GetData, but I wasn't able to use the size in the array elements. Anyways, that's a different subject.
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS) {
INT i = 0;
INT pzUserID; <- This should of been an array element
WCHAR pzFirstName[cbFirstName]; <- This should of been an array element
WCHAR pzLastName[cbLastName]; <- This should of been an array element
WCHAR pzUserName[cbUserName]; <- This should of been an array element
while (SQLFetch(hstmt) == SQL_SUCCESS) {
SQLGetData(hstmt, 1, SQL_C_ULONG, &pzUserID, 0, NULL );
SQLGetData(hstmt, 2, SQL_C_WCHAR, &pzFirstName, cbFirstName, NULL );
SQLGetData(hstmt, 3, SQL_C_WCHAR, &pzLastName, cbLastName, NULL );
SQLGetData(hstmt, 4, SQL_C_WCHAR, &pzUserName, cbUserName, NULL );
}
|
|
|
|
|
Hello,
Im writing an MFC App,
I want to create some threads using the CreateThread function.
The function that i send as a parameter to the createThread function must be declared as static and then i cant reference none static members of my object,how can i by pass it?
Thanks
|
|
|
|
|
You can still pass an object reference to a static function.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
something like this:
int CMyClass::staticFunc(void *p)
{
CMyClass *pObj = (CMyClass *)p;
...
return 0;
}
void CMyClass::someFunc()
{
CreateThread(NULL, 0, staticFunc, (void *)this, ... );
}
|
|
|
|
|
Why cast the object to a void * and the back to a CMyClass * ?
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
not sure i understand the question.
threadprocs take a void* param...
|
|
|
|
|
Sorry, I mis-read what you had posted; I was thinking of something else I suspect.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
If you're using MFC, you should rather use the AfxBeginThread()[^] call that MFC provides to create thread. There are many good reasons to this, mainly that MFC has its own storekeeping mechanism that you'll bypass if you call a windows API instead of the MFC call to create thread. Likewise, use _beginthreadex()[^] otherwise. There should be basically no good reason for you to call CreateThread() directly.
"Real men drive manual transmission" - Rajesh.
|
|
|
|
|
Have also a look at Newcomer's assays:"Threads and Processes series".
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi, I am new to this forum, but have been messing with programming for years. I have worked only a couple of computer jobs over the years, one after I completed a Novell Netware cert course (yeah, I know, dinosaur. lol) and one for a fella who wrote billing software code in C. My main employ has been in the remodeling trades and that has been why I have been in and out of this. (had to take care of my family, of course). But now I really want to get serious about this as it is really what I love.
I have spent more time learning C than anything else. I dont know C++ very well yet and I really haven't written any apps in either langs as yet.
I see that C# is the hot language now unless I am mistaken and my main question is: what should I concentrate my efforts on? Should I just write and debug as much as I can in what I know to hone my skills? Should I abandon C altogether and concentrate on C# specifically? And as far as finding work, should I frequent the bidding sites and post myself if I think I can do the job?
I know you all have 'been there' so any advice would be welcome.
THanks!
Dave
|
|
|
|
|
Why didn't you write apps? You should do it.
The following is just my own personal opinion:
I think you may find C jobs only if you wish to program for microcontrollers and C++ jobs are usually harder to find than C# ones. If you really love native programming languages then, study (and master) C/C++ but you should know you'll have to deal with a rather niche market.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Thanks for the quick reply. Yeah, that is about what I thought. But should I just move to C# to make myself more marketable? Or do I need to master C++ first?
And to writing apps, I guess I haven't done it due to a combination of laziness and lack of commitment. But that is going to change...after all, it IS the New Year!
|
|
|
|
|
In my opinion you don't need to master C++ for moving to C# (moreover if you master C++ then probably you won't move to C# ). So if you really like native languages then go on with C++ . If you want to be 'more marketable' (or simply because you wish to learn a more 'evolving' language) go on with C# . And, of course, good luck!
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|