|
An hint is given by the hr 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]
|
|
|
|
|
vital_parsley2000 wrote: if(SUCCEEDED(hr)) block is not executed.What could be the reason ?
Get the hr value and pass it to FormatMessage function. You will get the cause.
To convert an HRESULT to DWORD you can use the following code snippet!
BOOL WIN32_FROM_HRESULT(HRESULT hr, OUT DWORD *pdwWin32)
{
if ((hr & 0xFFFF0000) == MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32)) {
*pdwWin32 = HRESULT_CODE(hr);
return TRUE;
}
if (hr == S_OK) {
*pdwWin32 = HRESULT_CODE(hr);
return TRUE;
}
return FALSE;
}
I found this from here
|
|
|
|
|
where do i insert this
code ?
|
|
|
|
|
vital_parsley2000 wrote: where do i insert this code ?
In your source files, dear!
It is a function , you can either put it in your .cpp file or .h file in global scope or add as a member function in your class.
Am I missing something ?
|
|
|
|
|
Another Tip:
Put the variable hr in the debug watch window, append ", hr" (without the quotes) to it to have Visual C++ translate it for you!
Or you can use pseudo variable $err as $err,hr in Watch window.The $err pseudo variable provides the value, and the hr format specifier tells the watch window to format it as an error code.
http://i.msdn.microsoft.com/dd252945.fig05_L(en-us).gif[^]
modified on Thursday, May 14, 2009 2:21 AM
|
|
|
|
|
vital_parsley2000 wrote: In the above code the if(SUCCEEDED(hr)) block is not executed.
Which one?
vital_parsley2000 wrote: What could be the reason ?
CreateInstance() or Open() failed and control did not return to the subsequent if() statement.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Hi,
I'm developing an application and i would display data from database(access, sqlserver, oracle) in a bcg grid.
So can someone help me by a simple example of code or how can i do for this.
Thank you very much.
|
|
|
|
|
|
is this solution will work with SqlServer and Oracle database ?
|
|
|
|
|
khaliloenit wrote: is this solution will work with SqlServer and Oracle database ?
Had you bothered to go through the links given to you, then you would have noticed the answer to your same exact question in the CP article:
"The sample has been tested with both MS Access and SQL Server, in theory you should be able to use it against all data sources that support OLE-DB."
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Sorry, but there is a solution with BCG Grid?
|
|
|
|
|
Please i try to use MS DataGrid in the Using MS DataGrid control with ADO[^] but i work with VS2003 and i don't find where i can add the Microsoft datagrid control with ADO !!!!?
So can you help me
|
|
|
|
|
Below is the code to append Bstr, but in debug mode it gives error
' ::SysFreeString(dest); ' and in release mode if i dont write ' ::SysFreeString(dest); ' it corrupts heap. What optimization i do.
BSTR StringAppend(const BSTR dest,const BSTR src)
{
long destLen=::SysStringByteLen(dest);
long srcLen=::SysStringByteLen(src);
BSTR st3 = ::SysAllocStringByteLen(NULL,destLen+srcLen);
try
{
if(st3==NULL)
{
throw "Insufficient Memory";
}
else
{
wcscpy(st3, dest);
wcscat(st3, src);
::SysFreeString(dest);// here it gives error in debug mode
}
}
catch(char * error)
{
throw error;
}
return st3;
}
“You will never be a leader unless you first learn to follow and be led.”
–Tiorio
"Coming together is a beginning, staying together is progress, and working together is success." Henry Ford
|
|
|
|
|
A const BSTR dest ?
Why const ?
|
|
|
|
|
Why are you freeing dest ?
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]
|
|
|
|
|
CPallini wrote: Why are you freeing dest?
Because if i do not free, it gives error that heap is violated in release mode and when i traced down it goes in the NULL condition.
“You will never be a leader unless you first learn to follow and be led.”
–Tiorio
"Coming together is a beginning, staying together is progress, and working together is success." Henry Ford
|
|
|
|
|
Please show us the calling code.
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]
|
|
|
|
|
Here is my calling code. value variable is of type BSTR
BSTR GetNewRow()
{
value=GetLoggedInUser();
BSTR strComma=::SysAllocString(L",");
BSTR strNewLine=::SysAllocString(L"\n");
value=StringAppend(value,strComma);
value=StringAppend(value,strCategory);
value=StringAppend(value,strComma);
value=StringAppend(value,strItemName);
value=StringAppend(value,strComma);
value=StringAppend(value,strInstallDate);
value=StringAppend(value,strComma);
value=StringAppend(value,strVersion);
value=StringAppend(value,strComma);
value=StringAppend(value,strValue1);
value=StringAppend(value,strComma);
value=StringAppend(value,strValue2);
value=StringAppend(value,strComma);
value=StringAppend(value,strValue3);
value=StringAppend(value,strNewLine);
::SysFreeString(strComma);
::SysFreeString(strNewLine);
return value;
}
“You will never be a leader unless you first learn to follow and be led.”
–Tiorio
"Coming together is a beginning, staying together is progress, and working together is success." Henry Ford
|
|
|
|
|
It looks like the problem is in your bad mixing of char and wchar calls:
with the following line
BSTR st3 = ::SysAllocStringByteLen(NULL,destLen+srcLen);
you're allocating (destLen + srcLen + 1) bytes.
while in the following calls
wcscpy(st3, dest);
wcscat(st3, src);
you need, (destLen + srcLen + 2) bytes.
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]
|
|
|
|
|
Thanks working great now .
i don't know the +2 funda , actually i am c# developer but my firm wants me to develop project in c++.
::SysFreeString(dest);
can i free this in StringAppend function itself or after my function returns.
“You will never be a leader unless you first learn to follow and be led.”
–Tiorio
"Coming together is a beginning, staying together is progress, and working together is success." Henry Ford
|
|
|
|
|
Technically you can do it inside. However you probably should revise your design, for instance using a prototype like the following for your function:
HRESULT StringAppend( BSTR * pdst, const BSTR src);
or, better, using, as suggested, the handy _bstr_t wrapper.
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]
|
|
|
|
|
1. BSTR * pdst
why pointer here.
BSTR is itself a pointer.
2. What code you have write for StringAppend function ?
I want to take some idea from you.It would be very helpful for me.It's a humble request from a programmer to a professional.
“You will never be a leader unless you first learn to follow and be led.”
–Tiorio
"Coming together is a beginning, staying together is progress, and working together is success." Henry Ford
|
|
|
|
|
Mogaambo wrote: 1. BSTR * pdst
why pointer here.
BSTR is itself a pointer.
Because the function will internally change the value of the original pointer, i.e. pdst is a INOUT parameter (this way you state clearly that the function may alter the original dst string).
Mogaambo wrote:
2. What code you have write for StringAppend function ?
Something like
HRESULT StringAppend(BSTR * pdest, const BSTR src)
{
if (pdest == NULL) return E_FAIL;
long destLen=::SysStringLen(*pdest);
long srcLen=::SysStringLen(src);
BSTR tmp = ::SysAllocStringLen(NULL,destLen+srcLen);
if( tmp == NULL) return E_FAIL;
wcscpy(tmp, *pdest);
wcscat(tmp, src);
::SysFreeString(*pdest);
pdest = &tmp;
*pdest = tmp;
return S_OK;
}
Beware: I didn't check this code (moreover I've used just the very basic E_FAIL failure
return value, a good function should be more informative on failure.
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, May 13, 2009 8:02 AM
|
|
|
|
|
BSTR tmp = ::SysAllocStringLen(NULL,destLen+srcLen);
dude you haven't added +2 bytes, it is crashing as that of mine, but when i added +2 it is running fine, so whenever i want allocate BSTR do i have 2 add + bytes.
BSTR tmp = ::SysAllocStringLen(NULL,destLen+srcLen+2);
“You will never be a leader unless you first learn to follow and be led.”
–Tiorio
"Coming together is a beginning, staying together is progress, and working together is success." Henry Ford
|
|
|
|
|
Mogaambo wrote: dude you haven't added +2 bytes
I know, I don't need to (I'm using SysAllocStringLen , not SysAllocStringByteLen ).
Mogaambo wrote: it is crashing as that of mine, but when i added +2 it is running fine
This is very strange.
Mogaambo wrote: so whenever i want allocate BSTR do i have 2 add + bytes
Nope. Even if your point about the crash is true (and is true, I know) this is a wrong conclusion.
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]
|
|
|
|