|
I tried to modify your approach, or can not eliminate this error, I now have Mozhe the
(我试着用你的方法修改,还是不能消除这个错误,我现在已经没辙了)
Code is found in the online, open source
(代码是在网上找到的,开源的)
|
|
|
|
|
Try it (this code has good chances under CE and under PC as well) :
{
...
TCHAR* tszResult = _tcsdup(_T("先生"));
...
free(tszResult);
...
}
virtual void BeHappy() = 0;
|
|
|
|
|
What do you? Did not understand ah!
|
|
|
|
|
class A
{
int i;
public:
void func1() {cout << "func1" << endl;};
static void func2() {cout << "func2" << endl;};
void func3() {i =1; cout << "func3" << endl;};
};
template <class T> class Smart
{
private :
T *m_ptr;
public :
explicit Smart(T *p = 0) : m_ptr(p) {}
T& operator*() {return *m_ptr;}
T* operator->() {return m_ptr;}
~Smart() {delete m_ptr;}
};
int main()
{
Smart<A> s(0);
(*s).func1();
system("PAUSE");
}
On running it I saw that it prints "func1" but how it it possible. I initialize it as NULL.
|
|
|
|
|
Basically your problem is resumed to something like this:
A* a = NULL;
a->func1();
In fact, the code will not crash in such scenario because you do not access any member variable of the class. Class methods are similar to global function except that they take an additional implicit parameter: the 'this' pointer (in your case it will be NULL). So, as long as you don't access any class variable, the code will not crash. Try now to print the value of 'i' in func1 and you'll that the code will crash.
|
|
|
|
|
Weird as it might look, a instance of the class is not really needed when calling such method, try the following simple code:
#include <iostream>
using namespace std;
class A
{
public:
void show(){ cout << "The show must go on." << endl; }
};
int main()
{
A * pA = NULL;
pA->show();
}
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]
|
|
|
|
|
I tried this and it worked find. But I am still confusing why it is working. What are the scenarios in which this thing will work.
Does it mean that U can access methods from NULL pointer but not attribute?
|
|
|
|
|
akashag wrote: Does it mean that U can access methods from NULL pointer but not attribute?
Yes, try:
#include <iostream>
using namespace std;
class A
{
public:
int a;
A():a(1){}
void show(){ cout << "The show must go on." << endl; }
void dump(){ cout << "member value is << " << a << endl;}
};
int main()
{
A * pA = NULL;
pA->show();
pA->dump();
}
[added]
From a OOP point of view (IMHO) this is a point where object abstraction clashes with technical implementation.
[/added]
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]
modified on Wednesday, April 28, 2010 3:36 AM
|
|
|
|
|
Yes, as I said earlier a class method is similar as a global method (so, there is one single function even if there are mutliple instances of the class or even no instance at all). When the method is called, the address of the instance on which the function is called is passed to the function (the 'this' pointer). This means that as long as you don't access any variables of the class, you can perfectly call the function even if the instance is NULL.
|
|
|
|
|
There is one exception: if the function call is indierect because of a v-table (the method is virtual), even if the function itself don't refer the this pointer, a valid this is required to perform the runtime redirection.
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
Yes, I forgot that.
Mmmh, let's say I didn't want to confuse the OP with too much information
|
|
|
|
|
Cedric Moonen wrote: I didn't want to confuse the OP with too much information
But what about me? I am still trying to absorb this.
It's time for a new signature.
|
|
|
|
|
Err, what do you mean exactly ? I don't get it...
|
|
|
|
|
I mean I was confused by this thread, but now I'm beginning to understand, thanks to your comments.
It's time for a new signature.
|
|
|
|
|
There is difference between "global function" and "class member function" only when the latter refers to the object's "this pointer". If not, these two functions are the same.
In your situation, the "(*s).func1();" doesn't refer to "this pointer". So it behaves just like a "global function". It doesn't use "this pointer" which is NULL here, hence no error there.
|
|
|
|
|
Hi,
I am creating a setup & deployment project in Visual Studio 2008 (VC++). I need to install a driver while running installer.msi . I have the command line for installing the driver below
devcon -r install driverx.inf *driverx.sys
How to include the above exe in Setup and Deployment project? I tried custom action and specified parameters "-r install driverx.inf *driverx.sys". But during installation I am getting the error message "THere is a problem with this windows installer package. A program run as par of the project did not finish as exepected .."
How to configure Setup and Deployment project for executing above exe?
|
|
|
|
|
I'm not familiar with "setup&deployment" project, but know something about it in "InstallShield".
In "InstallShield", there is a place you can setup "support files". These files will be copy to temporary folder when your install program is running. Then you can use script language to execute the command line.
If there is a same place in "setup&deployment" project, you can add "devcon.exe" to the "support files", then use script language to run it.
Is the above useful for you?
|
|
|
|
|
Thank you very much. But I am still trying to find a way to install driver via Setup & Deployment Project. If nothing works out I will consider InstallShield.
|
|
|
|
|
Hi Forums
I am try to open Excel Protected workbook.I know how to open excel through microsoft office automation.
Excel::_ApplicationPtr pApplication;
Excel::_WorkbookPtr pBook;
HRESULT hr;
_variant_t varOption( (long) DISP_E_PARAMNOTFOUND, VT_ERROR);
CoInitializeEx(NULL,COINIT_MULTITHREADED);
hr = pApplication.CreateInstance(__uuidof(Excel::Application));
if (FAILED(hr) )
{
return 0;
}
pBook = pApplication->Workbooks->Open( (_bstr_t)fileNameopen,varOption, varOption, varOption, varOption, varOption, varOption, varOption, varOption, varOption, varOption, varOption, varOption );
Through this code i am eable to open ecxel Unprotected.But i have protected excel file then excel file ask password.So Can i remove password or get password?
I cann't use third party tool.Please advice me what i do? if any dll available then please give me link.
|
|
|
|
|
Why should we help you cracking Excel?
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]
|
|
|
|
|
ok i am not going to force to help me.Just i ask a question.If you think to help me then most welcome or if not then also most welcome.
I need this type of scenario.So I ask here.
Thanks
|
|
|
|
|
If you have lost the password, I guess you may search for a password recovery tool.
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]
|
|
|
|
|
No i am not trying to use third party tool.Any way
Can you give a one basic idia there is any more way to open excel file accept(office automation).
Regard's
Rdop
|
|
|
|
|
try using odbc ..
Failure is Success If we learn from it!!
|
|
|
|
|