|
Save My Soul - (SMS) wrote: The first argument gives a value and the second argument returns a Long IDispatch Pointer. So for this implementation, where should the Addref for lptmp1 and lptmp2 occur. Should it be inside this function like
bool hello( LPDISPATCH lptmp1, LPDISPATCH &lptmp2 )
{
lptmp1->AddRef() ;
lptmp2->AddRef() ;
}
Good question....
For lptmp1 it could be inside hello because the use of lptmp1 finishes here in hello and for lptmp2 it could be outside hello because it continues to exist beyond hello . Because I believe AddRef and Release should take place in the same scope.
Nibu thomas
Software Developer
|
|
|
|
|
Hi,
I am using the MSXML API for xml processing. Suppose I declare a
IXMLDOMElementPtr spRootElem ;
pointer. Do I have to AddRef this and Release it after I have finished? Do I have to do something like
IXMLDOMElementPtr spRootElem ;<br />
spRootElem->AddRef() ;<br />
...<br />
spRootElem->Release() ;
Please Advise.
Thanks.
---
With best regards,
A Manchester United Fan
The Genius of a true fool is that he can mess up a foolproof plan!
|
|
|
|
|
Yes of course. All COM object works likewise. Go through the tutorial that I suggested.
Nibu thomas
Software Developer
|
|
|
|
|
COM objects use reference counting. When you make a copy of an interface pointer you call AddRef to increment the reference count and when you're getting rid of one you call Release to decrement it. When an object's reference count transitions to zero it does whatever needs to be done to clean up house. In C++ code this is typically a delete this; or some such.
Steve
|
|
|
|
|
I have just one more question.
Lets say that I have used LPDISPATCH lpTemp. Then I pass this lpTemp as an argument to another function. Now what goes on behind the scenes when this happens? Is the AddRef of lpTemp called? How do I handle this scenario? Also is lpTemp->Release() enough to free up the used memory or do I have to use delete lpTemp to free the memory?
Thanks.
---
With best regards,
A Manchester United Fan
The Genius of a true fool is that he can mess up a foolproof plan!
|
|
|
|
|
If the other function makes a copy of lpTemp , say for later use, it will call AddRef through it. When it doesn’t need the copy anymore it will call Release . What, if anything, has to be done to free the storage occupied by the pointer itself depends on where it's stored. If it's a local variable (as is typical) nothing has to be done as locals variables take care of themselves. Same for a global. If it's a member variable it depends on the storage used by the object - if it's local or global again no action needs to be takes. The exception in all of this is for heap allocated objects. If a variable in on the heap you have to free it. The rule is simple, if you new something remember to delete it.
Steve
|
|
|
|
|
guys,
What is meant by call back Function. why it is
called so?. Explain with some real time examples.
Thanks
Vivek.s
viveks
|
|
|
|
|
As the name says callback . Means call me back when you feel like calling me.
A good example would be timer functions. We pass a function as an argument and we forget about it. We write the necessary code inside this function.
When the timer fires this function will be called. Hence the name callback.
If you've used AfxBeginThread or SetTimer you will understand what this means.
Nibu thomas
Software Developer
|
|
|
|
|
assume: string s1 = "abcd"; string s2 = "2.53",
how to detect (code)that s2 representing a numeber, whereas s1 a character string ?
|
|
|
|
|
CString str="asd";-->return 0
CString str2="253";-->return 253
int index=atoi(str2);
-- modified at 0:14 Thursday 16th March, 2006
|
|
|
|
|
my question is how you know s2 is a digital ?
|
|
|
|
|
I tested this code if s1=abcd the return is 0
and for 2.53 return 253
|
|
|
|
|
how did you tested ? with which function or code segments?
|
|
|
|
|
Can you not read? He answered with atoi . It fails with a 0 return value if a numerical conversion is not possible.
--
The Blog: Bits and Pieces
|
|
|
|
|
Johann Gerell wrote: It fails with a 0 return value if a numerical conversion is not possible.
And what if the number was 0? It will still return 0 as if it failed.
I can't understand why people still use atof
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
|
|
|
|
|
Nemanja Trifunovic wrote: I can't understand why people still use atof
Me neither, but that was not the point of my post.
I personally use
long strtol( const char *nptr, char **endptr, int base );
long wcstol( const wchar_t *nptr, wchar_t **endptr, int base ); with which a 0 return value can be checked against the endptr parameter to see if a conversion occurred or not.
--
The Blog: Bits and Pieces
|
|
|
|
|
Johann Gerell wrote: I personally use
long strtol( const char *nptr, char **endptr, int base );long wcstol( const wchar_t *nptr, wchar_t **endptr, int base );
with which a 0 return value can be checked against the endptr parameter to see if a conversion occurred or not.
Finally a voice of reason.
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
|
|
|
|
|
Brute force and pig ignorance - step through the string, checking:
(1) that every character is either a digit or a decimal point, and
(2) that there is at most one decimal point
It's only a bit more compliicated if you want to allow Hex numbers (0x....), etc.
Alternatively, try to use one of the string-to-real functions - maybe the return code will tell you if there is an error.
|
|
|
|
|
mrby123 wrote: how to detect (code)that s2 representing a numeber
Scan through the string and check using _istdigit . If a
particular character is a number then this function returns a non zero value.
mrby123 wrote: whereas s1 a character string ?
Same here too except use _istalpha .
Nibu thomas
Software Developer
|
|
|
|
|
how to use _istdigit or _istalpha ? give me a code segment ?
|
|
|
|
|
Code[^] segment.
Nibu thomas
Software Developer
|
|
|
|
|
I tried that those functions do not take a string as argument.
|
|
|
|
|
Exactly they take a single char.
That is what I said before. Scan through the string picking out each character and checking it.
Nibu thomas
Software Developer
|
|
|
|
|
I personally use
long strtol( const char *nptr, char **endptr, int base );
long wcstol( const wchar_t *nptr, wchar_t **endptr, int base ); with which a 0 return value can be checked against the endptr parameter to see if a conversion occurred or not.
--
The Blog: Bits and Pieces
|
|
|
|
|
Can anyone tell me how to write entries into "History Fodler" programmatically?
Thanks and Regards,
Anil
|
|
|
|