|
CArray <FileInfo, FileInfo &> fileArray;
|
|
|
|
|
Or, alternatively, use CTypedPtrArray to store pointers.
No generalization is 100% true.
Not even this one.
|
|
|
|
|
would it be the way to use CTypedPrtArray??
<br />
CTypedPtrArray <FileInfo,FileInfo*> *a;<br />
FileInfo *fileinfo = new FileInfo();<br />
FileInfo *fileinf = new FileInfo();<br />
<br />
fileinfo->name = "he ha";<br />
a->Add(fileinfo);<br />
<br />
fileinf = a->GetAt(0);<br />
MessageBox(fileinf->name);<br />
|
|
|
|
|
Not quite. CTypedPtrArray is, like CArray, a template class. You can get more info from MSDN, but in a nutshell:
CTypedPtrArray<CPtrArray, FileInfo *> a;
Then do the rest like you had there. Note that since it is an array of pointers, you are responsible for deleteing the pointers when necessary.
No generalization is 100% true.
Not even this one.
|
|
|
|
|
i got it. now.
<br />
CTypedPtrArray <CPtrArray,FileInfo*> a;<br />
FileInfo *fileinfo = new FileInfo();<br />
FileInfo *fileinf = new FileInfo();<br />
<br />
fileinfo->name = "he ha";<br />
a.Add(fileinfo);<br />
<br />
fileinf = a.GetAt(0);<br />
MessageBox(fileinf->name);<br />
rose! thanks
|
|
|
|
|
uh... i dont' know how to use it.. coz i get run time error again..
please tell me how.
this is what i did
<br />
CArray <FileInfo,FileInfo &>*a;<br />
FileInfo fileinfo;;<br />
<br />
fileinfo.name = "testing... testing....";<br />
a->Add(fileinfo);<br />
FileInfo fileInfo;<br />
<br />
fileInfo = a->GetAt(0);<br />
MessageBox(fileInfo.name);<br />
|
|
|
|
|
I am sorry, I should be more specific. Do this:
CArray <FileInfo, FileInfo &> fileArray;
FileInfo fileinfo;
fileinfo.name = ...
fileArray.Add(fileinfo);
...
fileinfor = fileArray[0];
MessageBox(fileInfo.name);
|
|
|
|
|
thanks...
rose!
|
|
|
|
|
do you have demos using this ocx ?
I need to make a program that can send video/sounds to anypersons sometime
Tks
|
|
|
|
|
New VC++ source code demo "AV ICQ" is included in avphone3 control:
http://www.banasoft.net/avphone3/avphone3.htm
|
|
|
|
|
I have the following function to receive all the applications running on the desktop:
BOOL CALLBACK AddWinsList(HWND hWnd, LPARAM lParam)
{
if (!IsWindowVisible(hWnd) || GetWindow(hWnd, GW_OWNER) != NULL)
return TRUE;
TCHAR szClassName[80];
GetClassName(hWnd, szClassName, 80);
if (lstrcmpi(szClassName, _T("Progman")) == 0)
return TRUE;
char szWndText[556];
GetWindowText(hWnd, szWndText, 556);
if (strlen(szWndText) > 0)
AfxMessageBox(szWndText);//just print at moment
return TRUE;
}
void CCommunicatorView::ReadApplications()
{
EnumWindows((WNDENUMPROC)AddWinsList, (LPARAM)NULL);
}
The above returns all running windows. How can I retrieve the applications filename from the 'hWnd' variable above? If Visual c++ was running i would receive the file name MSDEV.EXE.
Its has to run on Windows 95(second edition),ME,NT,2000,XP
Thanks
Neil
|
|
|
|
|
There may be an easier way, but you could
1) Call GetWindowThreadProcessId to get the ProcessID which owns the window.
2) Call OpenProcess to get a HANLDE for the process
3) Call GetModuleFileName
4) Close CloseHandle.
I haven't tried this, but I think this will work for you.
|
|
|
|
|
This is exactly how you have to do it, except in step 3, I believe that you meant GetModuleFileNameEx .
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
I though GetModuleFileNameEx would only work under NT,2000. Isn't a part of the PSAPI?
|
|
|
|
|
Matt Gullett wrote:
I though GetModuleFileNameEx would only work under NT,2000. Isn't a part of the PSAPI?
You are right about that.
The problem with GetModuleFileName though, is that it queries a module for the current process, it does not let you specify the process handle that you want to query. So I do not think that this solution will work.
Some how GetModuleFileName needs to be called from the process that owns the window.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
Is there any other way of getting the filename from the 'hWnd' of an application?
|
|
|
|
|
What we just determined is that the function that you need to do it only exists on NT.
So if you want a portable way of doing it from the Win 9X series of operating systems you will need to find a way to execute the GetModuleFileName function from inside of that process. One way to do this is to load a dll into that process, and that DLL can then call that function. If you are interested in this method I can find you some more details about it.
If I think of any other methods I will post them as well.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
This article may not directly answer your question, but is worth looking at if you haven't already.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Hi.
I am stuck at on design that include extensive use of pointer. I prefer using point because with pointers, I have more options such as when to create the data structure and when to delele the data structure. Furthermore, I have more options when passing the pointers to functions. Nonetheless, pointers can be tricky when dealing with some API and other Windows based tools such as MFC.
Here is the problem. In Winsock programming, there are API functions that does "clean up," according to Anthony Jones and Jim Ohlund, authors of Network Programming for Microsoft Windows, Second Edition. Some of these API functions include these functions:
// closesocket(...) // you pass in a sock
// freeaddrinfo(...) // you pass a pointer to a struct addinfo
// WSACleanUp() // you pass in nothing
Okay. Those are just a few "clean up" functions for Winsock. I am sure there are some other ones. Here is my question.
As I have mentioned that I prefer using pointer and creating a new data structure and deleting the pointer when needed. That technique gives me more flexibility. However, with respect the the "clean up" functions above, how do they react to pointers? For example:
// sock *mySocket = socket(...); // mySocket is a pointer to a socket
Now I close it.
// closesocket(*mysocket);
Now, should I still call delete mySocket afterward? My main concern is I do not know whether each the API function mentioned above the pointer if you pass it a pointer.
The same scenarios holds for freeinddrinfo and WSACleanup().
In the case of a struct inaddrinfo, you pass in a pointer. However, do you delete that pointer afterard?
In the case of WSAData, do you delete the pointer to a WSAData structure after calling WSACleanup()?
Currently, I *do* delete all pointers even after calling WSACleanup().
Thanks,
Kuphryn
|
|
|
|
|
sock *mySocket = socket(...);
Now I close it.
closesocket(*mysocket);
Now, should I still call delete mySocket afterward?
Nope. socket(...) does not return a (direct) pointer to something it returns a socket descriptior that you use to reference the created endpoint in the future.
Since you did not directly allocate any memory (using new ), you should not be so hasty to delete it. Also, you should not be passing socket pointers to those functions.
In the case of a struct inaddrinfo, you pass in a pointer [...]
Just because something takes a pointer as a parameter, that does not mean that you automatically are required to dynamically allocate something. You can create a inaddrinfo on the stack, and pass in its address to whatever functions takes a pointer-to-a-inaddrinfo structure.
In the case of WSAData, do you delete the pointer to a WSAData structure after calling WSACleanup()?
Only if you actually allocated the WSADATA structure earlier. If you just created one on the stack, and passed its address to WSAStartup , the structure will go out of scope automatically.
Peace!
-=- James.
"Fat people are hard to kidnap."
(Try Check Favorites Sometime!)
|
|
|
|
|
Thanks.
Several members at Anandtech and GameDev mentioned a easy technique. They both implied that call delete only if you have called new.
I will adopt that technique.
Kuphryn
|
|
|
|
|
A good general practice...! Except when dealing with poorly designed hand-off code (e.g. a function that returns allocated memory, and requires you to clean it up, like strdup(...) ).
Code that does that continues to be a problem even today (ever see someone forget to call SysFreeString(...) on an [out] BSTR pointer...?
Peace!
-=- James.
"Fat people are hard to kidnap."
(Try Check Favorites Sometime!)
|
|
|
|
|
Thanks.
I think it no cool that there is code that mishandles pointers.
Kuphryn
|
|
|
|
|
Is there a way for me to set a minimum size that a window can be resized to? I don't want the user to be able to resize the screen smaller than a certain size. Is there a way to set that to a fixed size that the user cannot pass?
|
|
|
|
|
handle the OnGetMinMaxInfo() message
"... and so i said to him ... if it can't dance and you can't eat it either f**k it or throw it away" 8028finder.com
|
|
|
|