|
The pointer points to an address on the stack (local declared variable)
this address still exist after the function returns. When you immediatly
use the pointer to get its value there is no problem.
But if there are serveral function calls happend in between or a large object
is created on stack the data at the specific address will be lost. When
your stack size is decreased you could also get an access violation.
codito ergo sum
|
|
|
|
|
U will get some consideration in a debug build that is the allocated space and pointer accessing etc. it wont fail in some cases ( but it should fail in such scenarios).
Just try the same code in release build. it wont definitely behave like debug build.
In release build too the application error is not occuring because the mapped address in its process address space.
SaRath
"D on't blindly follow rules you read somewhere without verifying that it makes sense for your situation!"
|
|
|
|
|
SaRath C wrote: In release build too the application error is not occuring because the mapped address in its process address space
yes..u r absolutely right. It is giving some other value in release build.
Now i understood the reason.
Thanks buddies.
Appu..
"If you judge people, you have no time to love them."
|
|
|
|
|
After this statement
NiceNaiduprintf("Value of *pPointer: %d\n", *pPointer);
do this
BOOL b = IsBadReadPtr(pPointer,sizeof(int));
check the value of b... it will be false because of the invalid pointer.
SaRath
"D on't blindly follow rules you read somewhere without verifying that it makes sense for your situation!"
|
|
|
|
|
The local variable nNumber is allocated on the thread's stack. When SomeFunction() returns, its stack variables are not erased (or "deleted"), the stack pointer is just moved back to a higher address. The stack data will still be there in memory until some later code reuses that area of memory for its stack.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
I'm currently reading some articals about Singleton.
It mentioned the following data structure is for single thread only
Class Singleton
{
public:
static Singleton * GetInstance()
{
static Singleton instance;
return &instance;
}
protected:
Singleton();
~Singleton();
}
Instead of using local static variable; using new operator to create an object will be thread-safe.
Class Singleton
{
private:
Singleton * m_pInstance;
public:
static Singleton * GetInstance()
{
if (! m_pInstance)
m_pInstance = new Singleton();
return m_pInstance;
}
protected:
Singleton();
~Singleton();
}
I can't see the real difference between these two implementation. Why the one with new operator is thread-safe?
Thanks
|
|
|
|
|
you are correct, the second sample is NOT threadsafe. Its worse there can also be a memory leak
You should protect the creation with a critical section.
But beware, it is not because the creation of your singleton is threadsafe that the data the singleton wraps will be threadsafe.
codito ergo sum
|
|
|
|
|
None of them are thread-safe, and actually chances are you would experience a threading problem with the second version sooner than with the first one.
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
|
|
|
|
|
Hi again
I hava a problem again executing an sql statment(INSERT) in my program
can anyone help me find whats wrong?
hr = S_OK;<br />
CoInitialize(NULL);<br />
<br />
try<br />
{<br />
_ConnectionPtr m_pConn;<br />
HRESULT hr =m_pConn.CreateInstance(__uuidof(Connection));<br />
if (FAILED( hr ))<br />
cout<<"Can't create an intance of ADO.Connection"<<endl;<br />
<br />
if (FAILED( m_pConn->Open(_bstr_t("Provider=Microsoft.Jet.OLEDB.4.0;Data Source =ADOTestDB.MDB"),<br />
_bstr_t( "" ),<br />
_bstr_t( "" ), <br />
adModeUnknown )))<br />
<br />
cout<<"Can't open datasource"<<endl;<br />
<br />
<br />
<br />
<br />
_bstr_t strDepId="12";<br />
_bstr_t strName="Art";<br />
_bstr_t strOfficeNo="256";<br />
_bstr_t strTel="22491303";<br />
_bstr_t strDepHead="Dr.Antonis Marcou";<br />
<br />
_bstr_t strSQL("Insert into Dept(DeptID,Name,OfficeNo,Phone,DeptHead) Values(");<br />
strSQL += strDepId + strName + strOfficeNo + strTel + strDepHead ;<br />
<br />
printf("%s\n",(LPCSTR)strSQL);<br />
<br />
m_pConn->Execute(strSQL,NULL,adExecuteNoRecords);<br />
<br />
printf("Data Added Successfully\n",(LPCSTR)strSQL);<br />
<br />
m_pConn->Close();<br />
<br />
}catch( _com_error &ce )<br />
{<br />
printf("Error:%s\n",ce.Description);<br />
<br />
}<br />
<br />
CoUninitialize();
I wrote the program almost the same way as the sample code but still is not working
the fiels in the db are
DeptID: number
Name: Text
OfficeNo: number
Phone: text
DeptHead: text
Any ideas?
thanks a lot for all the help you gave me so far
|
|
|
|
|
I Think, u r going wrong in framing the Insert Statement.
antonaras wrote: printf("%s\n",(LPCSTR)strSQL);
What is the output of the above line ???
Appu..
"If you judge people, you have no time to love them."
|
|
|
|
|
Thanks for the reply NiceNaidu
this is the output that i get:
Insert into Dept(DeptID,Name,OfficeNo,Phone,DeptHead) Values(12Art25622491303Dr.
Antonis Marcou
Error:ΘX↔
Press any key to continue
|
|
|
|
|
Hey NiceNaidu
i got it you where right there was a problem with framing the values of the inser statment thanks for helping me out
|
|
|
|
|
Ok fine..keep going
Appu..
"If you judge people, you have no time to love them."
|
|
|
|
|
i think the program will throw a exception,you can look at the exception for finding out the error informtion.
|
|
|
|
|
hi
i want to set an option in Windows XP & 2000 that user must enter a username & password to login into a computer.(i.e i want to make authentication compulsory )
how to achieve this programmatically??
thanx in advance
"Every morning I go through Forbes list of 40 richest people in the world. If my name is not in there, I go to work..!!!"
|
|
|
|
|
QuickDeveloper wrote: i want to set an option in Windows XP & 2000 that user must enter a username & password to login into a computer.
I think that's the default behavour in Windows 2000/XP. So, what's the real problem? See you ...
|
|
|
|
|
Open your registry and find the key below.
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon]
Create a new string value called "ForceAutoLogon" and set it to 0.
All the above steps you can do programatically
If you want the user should press Ctrl+Alt+Del then
in [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon]
Create a new DWORD value, or modify the existing value called 'DisableCAD' to 0
-- modified at 4:44 Wednesday 31st May, 2006
NOTE: Before trying all the above save your registry. Modifying the registry can cause serious problems that may require you to reinstall your operating system
Regards
Anil
|
|
|
|
|
Open your registry and find the key below.
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon]
Create a new string value called "ForceAutoLogon" and set it to 0.
Ofcourse the above steps can be done programmatically but how will the windows detect ForceAutoLogon key when logging in .
Can that be done programmatically????
|
|
|
|
|
ForceAutoLogon is a predefined registry key for Windows.
It always check for it at start up. If not present in your registry then it will take default value. So no need to do anything programmatically or manually after setting the key.
Regards
Anil
|
|
|
|
|
Hi Anil,
thanx for ur suggestion
I have another question ..
I need to set AccountLock policies (accountlockout threshold & duration)in
controlpanel\administrative tools\local security policy\Account policy\Account Lockout policy)
Are there any registry keys to set these accountlockout threshold and
accountlockout duration??Could u suggest me on how to do this programmatically.
Thanx
|
|
|
|
|
ForceUnlockLogon
LockoutThreshold
LockoutDuration
are the registry key name which can help you. But the actual location I don't know. You can google it or search your registry. I have Window 2000 professional and no administrative tools in control panel.
So not able to find the location of these keys in my PC.
Regards
Anil
|
|
|
|
|
I got them using dos command ,ex:- Net Accounts /lockoutthreshold:6
Thanx for ur suggestions
|
|
|
|
|
My PC "A" is connected to another PC "B". How to get the time of PC "B" in VC++ from PC "A".
|
|
|
|
|
acemahesh@yahoo.co.in wrote: How to get the time of PC "B" in VC++ from PC "A".
Make client application of PC 'B' to send the time to the server in PC 'A'.
Nibu thomas
A Developer
Programming tips[^] My site[^]
|
|
|
|
|
Use DCOM
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|