Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > Visual C++
|
Visual C++ Questions specific to Microsoft's Visual C++. For questions not specific to this Microsoft version, use the C++ Programming forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual C++ section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 13th, 2006, 11:59 PM
Registered User
 
Join Date: Jul 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default BSTR * is not returning value

hi all,

 I am having server and client code in VC6 so i updated the server code from VC6 to

 VC8 now the server code is not able to return the BSTR * value to the client .

The client is still in VC6 only.

The client is in Release Min Dependency and the server code is in unicode character set

  The client is calling the server function from

 ////////////////////////////Client Code ///////////////////////////

CComBSTR bstrPSRSSName;

int intResult;

ISupportUnit * pSupportUnit;

pSupportUnit->GetCurrentSystemSetup(CComBSTR(mstrSupportUnitNam e),&bstrPSRSSName.m_str,&intResult);

/////////////////////////////////END OF CLIENT CODE///////////////////////////////

//////////////////////////server code ///////////////////////////////////

STDMETHODIMP CSupportUnit::GetCurrentSystemSetup(BSTR bstrSUName, BSTR *bstrSSName,int *intResult)

{

// USES_CONVERSION ; // shan;

//Update to Database

CComBSTR bstrQuery(_T("SELECT txtSystemSetup FROM tSupportUnitInfo WHERE txtSUName='"));

bstrQuery.AppendBSTR(bstrSUName);

bstrQuery.Append(_T("' "));

CComBSTR bstrResult(_T("Nothing"));

fncExecuteQuery(bstrQuery,bstrSSName,intResult);

return S_OK;

}



void CSupportUnit::fncExecuteQuery(BSTR bstrQuery, BSTR *bstrResult,int *intResult, BOOL blnIsUpdate)

{

TCHAR lpConnectionString[100];

TCHAR sql[1000];


HRESULT hr;

BOOL blnConnected=FALSE;

_RecordsetPtr mpRecordSet;

_ConnectionPtr mpConnection;


mpConnection.CreateInstance(__uuidof(Connection));


CString strDBName = CString(mbstrDBName.copy()) ;

swprintf(lpConnectionString,_T("Provider=Microsoft .Jet.OleDB.4.0;Data Source=%s"),strDBName);

try

{

hr=mpConnection->Open(_bstr_t(lpConnectionString),mbstrDBUser,mbst rDBPwd,adModeUnknown);


if(SUCCEEDED(hr))

{

blnConnected=TRUE;

swprintf(sql,CString(bstrQuery));

if(blnIsUpdate)

{

mpConnection->Execute(sql,NULL,0);

*intResult=ERR_NONE;

}

else

{

mpRecordSet.CreateInstance(__uuidof(Recordset));

mpRecordSet->Open(sql,mpConnection.GetInterfacePtr(),adOpenDyn amic,adLockOptimistic,adCmdText);



if(VARIANT_FALSE==mpRecordSet->adoEOF)

{

_bstr_t bstrColDelim("~");

_bstr_t bstrRoDelim("@");

_bstr_t bstrUserString;

_bstr_t bstrQueryResult;

bstrQueryResult=mpRecordSet->GetString(adClipString,1000,bstrColDelim,bstrRoDe lim," ");


*bstrResult=bstrQueryResult.copy();

*intResult=ERR_NONE;

}

else

{

mpRecordSet->Close();

mpConnection->Close();

_bstr_t bstrQueryResult("No Records Found");

*bstrResult=bstrQueryResult.copy();

*intResult=ERR_NONE;

return;

}

}

}

mpConnection->Close();

return;

}

catch(_com_error e)

{

mpConnection->Close();

BSTR bstrErr=e.Description().copy();

if(DEBUG_LEVEL_ONE)

{

fncLogDebugMsg(CString(bstrErr));

}

*intResult=ERR_UNKNOWN;

return;

}

}

///////////////////////////////END OF SERVER CODE/////////////////////////////////

//////////////////////////////SERVERS IDL FILE /////////////////////////////////

[id(26), helpstring("method GetCurrentSystemSetup")] HRESULT GetCurrentSystemSetup(BSTR bstrSUName,[out

]BSTR *bstrSSName,int *intResult);

///////////////////////// END OF IDL FILE////////////////////////////////////////



My Server code in VC6 worked properly but when i upgraded it to VC8 it is not able to return bstrSSName

value and also giving runtime exception after calling GetCurrentSystemSetup function

so pls tell me if there are any more changes to be made so that i would get the bstrSSName and also

avoid from Runtime Exception ie

" The exception unknown software exception (0xc0000409 ) occurred in the application at location

0x0040a576"

 
Old October 16th, 2006, 04:27 AM
Registered User
 
Join Date: Jul 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi all,

I converted my client code to VC8 now my entire code ie client and server code is in VC8 now it is running fine and no runtime exceptions.

Thanks for all who spent there valuable time for this problem






Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting junk bstr values in C# dll from VC++ dotnetuncle Visual C++ 2005 0 July 4th, 2007 10:41 AM
Getting junk bstr values in C# dll from VC++ dotnetuncle C# 0 July 4th, 2007 10:40 AM
Getting junk bstr values in managed C# DLL from VC dotnetuncle C++ Programming 0 July 4th, 2007 10:38 AM
Converting BSTR to const char* wambozi C++ Programming 5 September 8th, 2006 05:08 AM
Converting BSTR to const char* wambozi C# 1 September 6th, 2006 05:37 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.