|
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]
|
|
|
|
|
Hmmm,
Any idea where all of these managed applications are? I have about 1500 software packages installed on various PC workstations/servers... (13 workstations and 3 servers) and only a small fraction (about 7%) of them are .NET managed applications. Its not like I am downloading native applications on purpose... its just that nearly everything I have seems to be implemented in a native language. (I perform routine security scans and collect PE image metrics from all workstations/servers.)
Not really looking to enter a debate...Recently I've just been curious which large software companies are developing and distributing .NET managed software applications. Most of the major software I have from Adobe, Google, Apple, IBM, Qualcomm, Intel, VMware... is all native code. I replaced the Adobe PDF Reader on all of the workstations with the Foxit PDF reader... and it turns out to be native too. Even most of the day-to-day tools I am using like Putty,Immunity Debugger,WinDbg,Wireshark/WinPcap, Textpad, notepad++,Nero,VMware, OpenVPN and Subversion... are all native code.
Of the small fraction of managed applications that I do I find on my network... many of them are actually from Microsoft Corporation.
Best Wishes,
-David Delaune
|
|
|
|
|
Randor wrote: Any idea where all of these managed applications are?
I really don't know. But, at least here in Italy, it is far more easy to find a .NET job than a C++ one. So that was my personal two-cents bet about finding a job.
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]
|
|
|
|
|
Yeah, I am guessing that there must be hundreds of thousands of small businesses around the world that create in-house database software and other types of managed applications for their internal requirements. I have also noticed that there seems to be more managed jobs being listed these days.
Best Wishes,
-David Delaune
|
|
|
|
|
That was exactly my point.
In any case it would be an advantage for him if other people, like you, give more enlighting.
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]
|
|
|
|
|
It certainly seems that way to me, but, then again how can I tell if an app is .NET managed software? Also, I've heard that .NET software is slower than apps written in native/compiled code.
BTW, if this is the wrong forum for this discussion, admin pls move.
|
|
|
|
|
Usually 'code speed' of C++ is better than C# one.
Usually 'code development speed' of C# is better than C++ one.
BTW don't argue about these arguments at the pub or your life will be in serious danger.
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]
|
|
|
|
|
|