|
Not sure if the answer is simple or not, but I'm trying to track down a bunch of memory leaks in some code from an article here and in tracing through the code, my WTF-meter is starting to glow a bit. Does it make sense to define a member function as static, then within that method, call another static member function and then within the second static member function, create an instance of your self on the stack in order to call non-static functions and then invoke pseudo copy constructors to copy member data from the stack based object to parameters that were passed to the static member function call. If you can understand that description, my question really comes from, why would the functions be made static in the first place. Had they not been made static, there would be no need to instantiate a stack object, nor copy it's member data into parameters in the first place. It seems like jumping through hoops for the sake of hoop jumping. Any comments or thoughts? Thanks.
Chris Meech
I am Canadian. [heard in a local bar]
Remember that in Texas, Gun Control is hitting what you aim at. [Richard Stringer]
Nice sig! [Tim Deveaux on Matt Newman's sig with a quote from me]
|
|
|
|
|
Chris Meech wrote:
It seems like jumping through hoops for the sake of hoop jumping.
Sometimes this is the only exercise that programmers get!
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
LOL. I guess the developer in question needed to lose some weight.
Chris Meech
I am Canadian. [heard in a local bar]
Remember that in Texas, Gun Control is hitting what you aim at. [Richard Stringer]
Nice sig! [Tim Deveaux on Matt Newman's sig with a quote from me]
|
|
|
|
|
Probably there are historical forces acting here. Maybe at one time a static function was useful without subsequently instantiating anything, and then life went downhill from there.
|
|
|
|
|
I make member functions static for a few reasons:
1. Entire class is composed of static functions and there is NO member data. No need to make an instance.
2. The static member function is used as a placeholder for a callback, the static function accepts data (such as the ubiquitous LPVOID or LPARAM) and casts it to a pointer of the class and then calls a non-static member function. This is very common to convert a parameter to _beginthreadex, for example, into a class' instance. Also, some Windows API callbacks allow you to pass 'user' data, which I usually make a pointer to a class.
3. The static function returns the pointer to the singleton class' instance.
No knowing much more about the class or its history, it seems like the class you describe needs some serious refactoring. Maybe it was a submission to the 'Obfuscated C++ Code Contest'
|
|
|
|
|
Three very good reasons for making a class or member static. In this case, I suspect that some unknown history was at work here. The callback is a possibility that I will look at today. The code uses winsock.h extensively and so there may be some dependancy on this that I've overlooked. And I will be doing some serious refactoring in order to remove the memory leaks.
Thanks for the comments to all.
Chris Meech
I am Canadian. [heard in a local bar]
Remember that in Texas, Gun Control is hitting what you aim at. [Richard Stringer]
Nice sig! [Tim Deveaux on Matt Newman's sig with a quote from me]
|
|
|
|
|
I need to get data from that Win32_PerfFormattedData_PerfProc_Thread class. How can I do that?
I need to get detailed info about thread.
Thanks.
Alex
|
|
|
|
|
There is an article about WMI on CodeProject!
Don't try it, just do it!
|
|
|
|
|
|
Something like:
HRESULT hr;
_variant_t v;
ULONG ulReturned;
DWORD dwAuthLevel;
IWbemLocator *pLocator;
IWbemServices *pService = NULL;
IEnumWbemClassObject *pEnum = NULL;
IWbemClassObject *pClass;
hr = CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *) &pLocator);
if (S_OK == hr)
{
hr = pLocator->ConnectServer(_bstr_t(L"root\\cimv2"), NULL, NULL, NULL, NULL, 0, NULL, &pService);
if (WBEM_S_NO_ERROR == hr)
{
hr = CoQueryProxyBlanket(pService, NULL, NULL, NULL, &dwAuthLevel, NULL, NULL, NULL);
hr = CoSetProxyBlanket(pService, RPC_C_AUTHN_DEFAULT, RPC_C_AUTHZ_NONE, NULL, dwAuthLevel,
RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE);
hr = pService->CreateInstanceEnum(_bstr_t("Win32_PerfFormattedData_PerfProc_Thread"),
WBEM_FLAG_RETURN_IMMEDIATELY | WBEM_FLAG_FORWARD_ONLY, NULL, &pEnum);
if (WBEM_S_NO_ERROR == hr)
{
do
{
hr = pEnum->Next(WBEM_INFINITE, 1, &pClass, &ulReturned);
if (WBEM_S_NO_ERROR == hr)
{
hr = pClass->Get(L"Caption", 0, &v, NULL, NULL);
if (VT_NULL != v.vt)
TRACE("Caption = %s\n", V_BSTR(&v));
}
} while (WBEM_S_NO_ERROR == hr);
pEnum->Release();
}
pService->Release();
}
pLocator->Release();
}
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Thanks a lot. Thats what I need.
Alex
|
|
|
|
|
Is there an easy way to hide the taskbar button of an application. I found an MSDN article which makes the window a child of an invisible window. Has anyone found another way to hide the button that is a little less complicated?
|
|
|
|
|
Can anyone tell me how to write a change of color in c++ for a program running in ms-dos?
|
|
|
|
|
Better use QBasic
Don't try it, just do it!
|
|
|
|
|
Change the color of what? Have you seen this API?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Dear All
I am a student of BS(CS).
I am doing my final project and thesis. I need some
help regarding my project
The Project title is:-
"Display Enlargement using Multiple Monitors and Image
Enhancement"
The objective is to make a software that can split
the primary monitor's display on 4 other monitors
(that are secondary monitors) shch like if we placse 4
moniters like a matrix they will show the same display
as primary monitor's display
Primary Moniror and secondary monitors are attach with
a single system unit that has 5 VGA Cards .
I am also sending u a jpg file that can help you to
illutrate the problem
The purposed solution where i have thought is make
resoloution 800 x 600 of primary monitor
and assign 400 x 300 to other secondry monitors.
But problem is that
1:- How can i detact VGA Cards
2:- How can capture video stream from one VGA and to Split or collect specific coordinates and sent this to other VGA's
3:- How can i change the resoloution of different in my program
4:- how can i assign them this resoloution.
If u find any information regarding this
please tell me OR If you have any new solution regarding this
please send me information and code as well on my e-mail touqeer_khan@yahoo.com.
The solution Should be in Visual C++ OR in Visual Basic
Thanking n anticipation.
Take Care
Regards
Touqeer
I will very thank ful to you for this consideration
Regards
Touqeer
Touqeer_khan@yahoo.com
|
|
|
|
|
My app registers filetype ".xyz" so that opening "fred.xyz" automatically
opens the data file in our app.
However ... if I click on a link to "fred.xyz" in internet explorer, it
simply opens it as text (.xyz is a text format). What additional steps are
needed to enable IE to launch my app when someone clicks on a link to
"fred.xyz" ?
Many thanks,
Steve
|
|
|
|
|
How did you go about registering the .xyz extension?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
If memory serves, this is lifted from the MFC base classes (VC++6) and adapted somewhat:
SetRegKey(HKEY_LOCAL_MACHINE, _T("software\\microsoft\\windows\\currentversion\\app paths\\MYPROG.EXE"), szPathName);<br />
SetRegKey(HKEY_LOCAL_MACHINE, _T("software\\microsoft\\windows\\currentversion\\app paths\\MYPROG.EXE"), szPath, _T("Path"));<br />
<br />
DelRegTree(HKEY_CLASSES_ROOT, _T("MyProg.File"));<br />
SetRegKey(HKEY_CLASSES_ROOT, _T("MyProg.File"), _T("MyProg File"));<br />
<br />
CString szDefaultIconCommandLine;<br />
szDefaultIconCommandLine.Format(_T("%s,-%d"),szPathName,UI_CONFIG_DOCFRAME_ID);<br />
SetRegKey(HKEY_CLASSES_ROOT, _T("MyProg.File\\DefaultIcon"), szDefaultIconCommandLine);<br />
SetRegKey(HKEY_CLASSES_ROOT, _T("MyProg.File\\QuickView"), _T("*"));<br />
<br />
SetRegKey(HKEY_CLASSES_ROOT, _T("MyProg.File\\shell\\open\\ddeexec"), _T("[open(\"%1\")]"));<br />
SetRegKey(HKEY_CLASSES_ROOT, _T("MyProg.File\\shell\\print\\ddeexec"), _T("[print(\"%1\")]"));<br />
SetRegKey(HKEY_CLASSES_ROOT, _T("MyProg.File\\shell\\printto\\ddeexec"), _T("[printto(\"%1\",\"%2\",\"%3\",\"%4\")]"));<br />
<br />
CString szPathDDE = szPathName + _T(" /dde");<br />
SetRegKey(HKEY_CLASSES_ROOT, _T("MyProg.File\\shell\\open\\command"), szPathDDE);<br />
SetRegKey(HKEY_CLASSES_ROOT, _T("MyProg.File\\shell\\print\\command"), szPathDDE);<br />
SetRegKey(HKEY_CLASSES_ROOT, _T("MyProg.File\\shell\\printto\\command"), szPathDDE);<br />
<br />
SetRegKey(HKEY_CLASSES_ROOT, _T("MyProg.File\\shell\\open\\ddeexec\\application"), szApplicationKeyValue);<br />
SetRegKey(HKEY_CLASSES_ROOT, _T("MyProg.File\\shell\\print\\ddeexec\\application"), szApplicationKeyValue);<br />
SetRegKey(HKEY_CLASSES_ROOT, _T("MyProg.File\\shell\\printto\\ddeexec\\application"), szApplicationKeyValue);<br />
<br />
SetRegKey(HKEY_CLASSES_ROOT, _T("MyProg.File\\shell\\open\\ddeexec\\topic"), szTopicKeyValue);<br />
SetRegKey(HKEY_CLASSES_ROOT, _T("MyProg.File\\shell\\print\\ddeexec\\topic"), szTopicKeyValue);<br />
SetRegKey(HKEY_CLASSES_ROOT, _T("MyProg.File\\shell\\printto\\ddeexec\\topic"), szTopicKeyValue);<br />
<br />
SetRegKey(HKEY_CLASSES_ROOT, _T(".xyz"), _T("MyProg.File"));
a few names have been changed, etc
Any clues?
Steve
|
|
|
|
|
I have an unmanaged C++ project that is largely complete. Up to this point I have used a CVS repository on my local machine to do version control.
I would like to run a series of tests on some past versions of the project, however only the source itself is part of the repository and I can't use the old .vcproj files.
If I check out an old version of the code and add it to a new project, it behaves very differently - sluggish response, takes a lot longer to load and there are different things shown in the output window when debugging. I've changed as many settings as I can think of (it's a multithreaded project, and uses winmm.lib for MIDI etc.) and as far as I can see I've taken this into account. Is there any way I can copy the current project settings, or even the current project file itself and use that without it complaining that most of files no longer exist in the older versions?
|
|
|
|
|
hello friends
i m making my project's backend in vc++ and i want to use gui in VB. so plz guide me that how i can wrap these coding through com wrapper
|
|
|
|
|
|
smarty12 wrote:
i m making my project's backend in vc++ and i want to use gui in VB. so plz guide me that how i can wrap these coding through com wrapper
Make A Com/ATL DLL!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
if you write like following code:
while(1)
{
create a instance of _CommandPtr
create a sql statement and bind it to command object
set command object's prepared attribute to false
execute the command
destroy the command object
......
}
if we use above code and use the same sql statement for command object to run, I want to know whether the db server will cache the sql, i.e. db will not parse the sql every time.
If we change the setting of the prepared attribute to true, whether the db will parse the sql statement?
Thanks.
|
|
|
|
|
I have created a dialog and it's corresponding class, but when I call DoModal(), the dialog does not appear. DoModal returns -1, and GetLastError() returns 1812.
I'm not sure what these codes mean, any help is appreciated.
-Alan
|
|
|
|
|