why pApplication.CreateInstance( _T("Excel.Application") ) FAILED?
-
i am reading excel file . Excel::_ApplicationPtr pApplication; pApplication.CreateInstance( _T("Excel.Application") ); but i dont understand why pApplication.CreateInstance( _T("Excel.Application") ) failed on my PC while its working fine on another PC. please help me for this. thanks.
-
i am reading excel file . Excel::_ApplicationPtr pApplication; pApplication.CreateInstance( _T("Excel.Application") ); but i dont understand why pApplication.CreateInstance( _T("Excel.Application") ) failed on my PC while its working fine on another PC. please help me for this. thanks.
Le@rner wrote:
but i dont understand why pApplication.CreateInstance( _T("Excel.Application") ) failed
Because you didn't bother to check the return value.
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] -
Le@rner wrote:
but i dont understand why pApplication.CreateInstance( _T("Excel.Application") ) failed
Because you didn't bother to check the return value.
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 chk this
if ( FAILED( pApplication.CreateInstance( _T("Excel.Application") ) ) )
{
AfxMessage( _T("Failed to initialize Excel!") );return ; }
It is no use printing a message such as the above when something fails, as it provides no useful information. You need to capture the system error code from
GetLastError()
and print its details to find out why your program fails. I am assuming that you have all the necessary libraries installed on your PC in the first place. Oops: sorry you need to interpret your HRESULT as CPallini suggests.Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
-
no chk this
if ( FAILED( pApplication.CreateInstance( _T("Excel.Application") ) ) )
{
AfxMessage( _T("Failed to initialize Excel!") );return ; }
That way, you are discarding a precious info, the HRESULT return value.
HRESULT hr;
hr = pApplication.CreateInstance( _T("Excel.Application");
if ( FAILED(hr))
{
// show error message AND error code here
return;
}is far better.
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] -
It is no use printing a message such as the above when something fails, as it provides no useful information. You need to capture the system error code from
GetLastError()
and print its details to find out why your program fails. I am assuming that you have all the necessary libraries installed on your PC in the first place. Oops: sorry you need to interpret your HRESULT as CPallini suggests.Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
I believe that's the optimal way with standard
API
(likeWin32
). On the other hand,COM
calls provides error code in return value.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 believe that's the optimal way with standard
API
(likeWin32
). On the other hand,COM
calls provides error code in return value.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]You are, of course, correct; it was my bad (mea culpa) and I have fixed it.
Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
-
That way, you are discarding a precious info, the HRESULT return value.
HRESULT hr;
hr = pApplication.CreateInstance( _T("Excel.Application");
if ( FAILED(hr))
{
// show error message AND error code here
return;
}is far better.
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]HRESULT hr;
hr = pApplication.CreateInstance( _T("Excel.Application");
if ( FAILED(hr))
{
//format Message Of GetLastError();"An attempt was made to reference a token that does not exist" error comes when i format the message of GetLastError().
return;
} -
HRESULT hr;
hr = pApplication.CreateInstance( _T("Excel.Application");
if ( FAILED(hr))
{
//format Message Of GetLastError();"An attempt was made to reference a token that does not exist" error comes when i format the message of GetLastError().
return;
}I don't know about, however it looks like
Excel
doesn't allow your application to access it (I guessed that from this page[^]: they face the same error message, see the "Configure Excel application to be accessed by non-System account" section. You may try to run your application 'As Administrator
' to validate such hypothesys.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 don't know about, however it looks like
Excel
doesn't allow your application to access it (I guessed that from this page[^]: they face the same error message, see the "Configure Excel application to be accessed by non-System account" section. You may try to run your application 'As Administrator
' to validate such hypothesys.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]Hi. I am facing exactly same problem and posted in the query in below link. https://www.codeproject.com/Answers/5165616/Excel-applicationptr-createinstance-is-failing#answer1 Can any one explain how to resolve this CreateInstance() failure. Windows 10 - 64 bit and Office 365 64bit and VS2017 enterprise edition i am using.