|
That way, you are discarding a precious info, the HRESULT return value.
HRESULT hr;
hr = pApplication.CreateInstance( _T("Excel.Application");
if ( FAILED(hr))
{
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))
{
"An attempt was made to reference a token that does not exist" error comes when i format the message of GetLastError().
return;
}
modified 17-Jan-12 7:33am.
|
|
|
|
|
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.
|
|
|
|
|
This is my first textbox using CreateWindow "edit", and I want to make sure the box is not empty.
So I sent the message, and the buffer comes back 0x0000, for the first wchar.
Is there a common method that folks use in c++ to check the contents of the box before performing any actions?
I wrote this, simple, but not good enough
LRESULT iTextSize = SendMessage(txt_SQL_DatabaseCreate_DB_Field, EM_GETLIMITTEXT, 0, 0);
WCHAR *szDatabaseName = new WCHAR[iTextSize];
SendMessage(txt_SQL_DatabaseCreate_DB_Field, WM_GETTEXT, iTextSize, (LPARAM)szDatabaseName);
if ((szDatabaseName[0] != 0x0000) && wcslen(szDatabaseName) >0)) {
|
|
|
|
|
jkirkerx wrote: LRESULT iTextSize = SendMessage(txt_SQL_DatabaseCreate_DB_Field, EM_GETLIMITTEXT, 0, 0);
You should probably be using WM_GETTEXTLENGTH instead.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
That was a good idea, I changed my code to that, it was more accurate.
|
|
|
|
|
I just use the GetWindowTextLength and GetWindowText functions, something like this:
case IDC_BTN_TEST:
editWnd = GetDlgItem(hwndDlg, IDC_EDIT1);
stringLength = GetWindowTextLength(editWnd);
if (stringLength != 0)
{
strBuffer = new WCHAR[stringLength+2];
GetWindowText(editWnd, strBuffer, stringLength+1);
MessageBox(hwndDlg, strBuffer, L"title", MB_OK);
delete strBuffer;
}
return TRUE;
For some reason, calling GetWindowText with stringLength (as opposed to stringLength+1) returns the string minus the last character...
|
|
|
|
|
enhzflep wrote: For some reason, calling GetWindowText with stringLength (as opposed to stringLength+1) returns the string minus the last character...
That is of course because 'C' strings are terminated with a NULL character. The GetWindowTextLength function sends the WM_GETTEXTLENGTH message[^] and therefore is returning only the length of the text excluding the NULL character. When allocating space for C-style strings you should always calculate the bytes required as:
((number of characters) * sizeof(TCHAR)) + sizeof(TCHAR)
Feel free to replace TCHAR with char or wchar_t dependent on your compiler/platform and ANSI/Unicode build.
Best Wishes,
-David Delaune
|
|
|
|
|
I didn't know that existed, makes sense, SetWindowText, GetWindowTextLength. So that's a quick way to see if there is data without sending a message, or get the size +1 for allocating space.
I did get the regex to work for wchar's, so now I can validate the input as well.
|
|
|
|
|
I'm building a pyramid of asterisk with for loop statement:
for (int i = 1, i < 5, i++)
{
for (int j = 1; j <= i, j++)
{
cout << "*";
}
cout << endl;
}
here's is the question: i need another for loop statement to reverse the pyramid. I need it has to do something with the spaces, but could not write one. Since i don't have a database to look at. Could someone hint me in the right direction?
|
|
|
|
|
Not clear... what do you mean a for loop to reverse the pyramid? ..you mean you want to undo what you just did?
|
|
|
|
|
"Normal" counts from 1 to 5, so I would guess that reverse counts down from 5 to 1.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Richard M.:
reverse count down from 5 to 1 only inverted the pyramid, not REVERSE it !
what I'm trying to create is a RIGHT-ALIGNED pyramid going from 1 to 5 in counts, as oppose to a left-aligned pyramid counting from 1 to 5. Hope you get this.
|
|
|
|
|
With this new information I think I misunderstood what you meant with reversing in my other post; you'll probably want to use this:
for (int i = 1; i < 5; i++){
for (int j = 1; j < 5-i; j++){
cout << " ";
}
for (; j < 5; j++){
cout << "*";
}
cout << endl;
}
modified 13-Sep-18 21:01pm.
|
|
|
|
|
You might want to declare j outside the for loop - according to the current C++ standard its scope would end with the end of the for loop and using it after that would result in a compiler error.
|
|
|
|
|
Thanks, good point. I use VC6 most of the time so I didn't get an error.
modified 13-Sep-18 21:01pm.
|
|
|
|
|
I believe most compilers supported this for a long time. I know for fact that it worked in VC7 (VS 2003), but it does not in VC10 (VS 2010).
|
|
|
|
|
Richard M.:
yes, but the asterisk pyramid is on the opposite of that count.
|
|
|
|
|
Yolande MR wrote: I need it has to do something with the spaces, but could not write one. Since i don't have a database to look at.
This is very unclear?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
DavidCrow:
What I mean is that I don't know how to write a for loop statement that write out spaces, instead of characters.
|
|
|
|
|
A space is just another character. What's wrong with:
for (int x = 0; x < 5; x++)
cout << " ";
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
The idea is to make a pyramid of spaces the same way you made the one you posted, but one character shorter, then write asterisks for the remainder of the line length:
for (int i = 1; i < 5; i++){
for (int j = 1; j < i; j++){
cout << " ";
}
for (; j < 5; j++){
cout << "*";
}
cout << endl;
}
Also your loops use commas rather than semicolons, which won't compile; I fixed that in my example.
modified 13-Sep-18 21:01pm.
|
|
|
|
|
Thaddeus Jones:
THANK YOU. I was able to to twist your codes around to achieve my goal. I know you are testing my c++ skills. Since I just learned how to write an inverted pyramid of asterisk, I was able to substitute asterisks for spaces, and write two pyramids into one project.
|
|
|
|
|
Anytime
modified 13-Sep-18 21:01pm.
|
|
|
|