|
Now I am able to get the correct value's
The problem is with resource id's, I haven't defined same resource id in dll and in mfc application.
|
|
|
|
|
Super Hornet wrote: m_hinstLib
What's that? Your resource DLL's handle is hinsttance ...
|
|
|
|
|
thank you for pointing the error
|
|
|
|
|
I m doing a database application.
in my OnNewDocument() i have the following code..
HRESULT hr;
try
{
AfxMessageBox("Inside try executed.",NULL,MB_OK); //Excecuted
hr = m_pConnection.CreateInstance(__uuidof(Connection));
AfxMessageBox("Created instance executed.",NULL,MB_OK);
if(SUCCEEDED(hr))
{
AfxMessageBox("If hr succeeded.",NULL,MB_OK);//Not Executed
hr = m_pConnection->Open(_bstr_t(L"Provider=sqloledb;Data Source=C:\\Program Files\\Microsoft SQL Server\\MSSQL\\Data\\LibDB.mdf;"),_bstr_t(L""),_bstr_t(L""),adModeUnknown);
if(SUCCEEDED(hr))
{
AfxMessageBox("Open connection executed.",NULL,MB_OK); //not executed
m_pConnection=TRUE;
}
}
AfxMessageBox("out",NULL,MB_OK);
}
catch(_com_error &e)
{
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
TRACE( "Exception thrown for classes generated by #import" );
TRACE( "\tCode = %08lx\n", e.Error());
TRACE( "\tCode meaning = %s\n", e.ErrorMessage());
TRACE( "\tSource = %s\n", (LPCTSTR) bstrSource);
TRACE( "\tDescription = %s\n", (LPCTSTR) bstrDescription);
}
catch(...)
{
TRACE( "*** Unhandled Exception ***" );
}
return TRUE;
}
In the above code the if(SUCCEEDED(hr)) block is not executed.What could be the reason ?
|
|
|
|
|
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]
|
|
|
|