In this case, what can I Write return-code ? 
Author Message
 In this case, what can I Write return-code ?

I think that No-Problem-case return S_OK.

In this case, what can I Write return-code ?

S_FALSE ?? E_FAIL   .... ??  -- I dont't know..

Thanks in advance.

My Test code -- Please correct return-code !!
////// Com method  ////////////
STDMETHODIMP CDBManager::Open(BSTR bstrTable)
{
 AFX_MANAGE_STATE(AfxGetStaticModuleState())

 // TODO: Add your implementation code here
 USES_CONVERSION;
 CString str = bstrTable;
 if(str != "4")
              return E_FAIL;  <==  Please correct!
                   ///   ( Because of "return E_FAIL", Assertiion error
occrred )

         return S_OK;

Quote:
}

/// MFC client
///////////////////////////////
CString s = "4";
short nIndex = 3;

HRESULT hr = m_pDBManager->Open(s.AllocSysString(), nIndex);
if(FAILED(hr))
     AfxMessageBox("Fail");

////////////////////////////



Tue, 04 Nov 2003 16:58:24 GMT  
 In this case, what can I Write return-code ?
Hi,
You can create your own HRESULTs and return.
or you could use the error info interface.

Murtuza.

Quote:
> I think that No-Problem-case return S_OK.

> In this case, what can I Write return-code ?

> S_FALSE ?? E_FAIL   .... ??  -- I dont't know..

> Thanks in advance.

> My Test code -- Please correct return-code !!
> ////// Com method  ////////////
> STDMETHODIMP CDBManager::Open(BSTR bstrTable)
> {
>  AFX_MANAGE_STATE(AfxGetStaticModuleState())

>  // TODO: Add your implementation code here
>  USES_CONVERSION;
>  CString str = bstrTable;
>  if(str != "4")
>               return E_FAIL;  <==  Please correct!
>                    ///   ( Because of "return E_FAIL", Assertiion error
> occrred )

>          return S_OK;

> }

> /// mfc client
> ///////////////////////////////
> CString s = "4";
> short nIndex = 3;

> HRESULT hr = m_pDBManager->Open(s.AllocSysString(), nIndex);
> if(FAILED(hr))
>      AfxMessageBox("Fail");

> ////////////////////////////



Tue, 04 Nov 2003 20:34:08 GMT  
 In this case, what can I Write return-code ?
Since you are checking the input argument and it is incorrect, you
have to return E_INVALIDARG. Never create custom HRESULTs when you
can use the standard ones for the purpose!

Overall I find the code stupid - why use an input argument if only one
value is permissible...

BTW, you have a memory leak. AllocSysString returns a BSTR which you
are responsible for freeing afterwards. However, you lose it right in
the function call and it is never freed. Instead, assign it to a variable
and SysFreeString it after the call.

One more thing - the client code you showed doesn't call the server
code snippet - the arguments are incompatible...

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD

MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================


Quote:
> I think that No-Problem-case return S_OK.

> In this case, what can I Write return-code ?

> S_FALSE ?? E_FAIL   .... ??  -- I dont't know..

> Thanks in advance.

> My Test code -- Please correct return-code !!
> ////// Com method  ////////////
> STDMETHODIMP CDBManager::Open(BSTR bstrTable)
> {
>  AFX_MANAGE_STATE(AfxGetStaticModuleState())

>  // TODO: Add your implementation code here
>  USES_CONVERSION;
>  CString str = bstrTable;
>  if(str != "4")
>               return E_FAIL;  <==  Please correct!
>                    ///   ( Because of "return E_FAIL", Assertiion error
> occrred )

>          return S_OK;

> }

> /// mfc client
> ///////////////////////////////
> CString s = "4";
> short nIndex = 3;

> HRESULT hr = m_pDBManager->Open(s.AllocSysString(), nIndex);
> if(FAILED(hr))
>      AfxMessageBox("Fail");

> ////////////////////////////



Wed, 05 Nov 2003 01:58:29 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. CGI script returning a GIF and HTML code (written in C)

2. Select returning UPPER & LOWER CASE

3. Paths returned in Lower case ONLY

4. Synchronisation problem : a reading/writing simple case

5. Tutorial books on writing an ActiveX control - in my case a calendar

6. Determining what canned preprocessor symbols are available

7. Beginner [Q] Using Canned File Open/Save dialog

8. Help with compiling a "canned" program

9. Canned Dialogs

10. Help needed: Code generation for CASE/SWITCH statements

11. case-insensitive strstr - my code, need help

12. Embedded SQL code needed for case sudy

 

 
Powered by phpBB® Forum Software