Put CInternetException content into a std::string

Flaviu_ 971 Reputation points
2023-11-14T12:12:40+00:00

How can I put a CInternetException message to a std::string? I have tried:

	catch (CInternetException* pEx)
	{
		pEx->GetErrorMessage(&error[0], _MAX_PATH);
		pEx->Delete();
	}

But I got:

*error C2664: 'BOOL CInternetException::GetErrorMessage(LPTSTR,UINT,PUINT) const': cannot convert argument 1 from 'char ' to 'LPTSTR'

How can I overcome this problem?

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,694 questions
{count} votes

Accepted answer
  1. Minxin Yu 11,581 Reputation points Microsoft Vendor
    2023-11-15T02:33:54.7566667+00:00

    Hi,@Flaviu_
    Try the snippet:

    	try {
    		
    		CInternetSession session;
    		auto pFile = session.OpenURL(_T("htt://www.example.com"));//custom link error 
    	
    	}
    	catch (CInternetException* pEx) {
    		TCHAR szError[1024];
    		pEx->GetErrorMessage(szError, 1024);
    		std::string errorMessage;
    #ifdef  _UNICODE
    
    		 errorMessage = CW2A(szError);
    #else
    		errorMessage=  szError;
    #endif 
    
    
    
    		OutputDebugStringA(("error: "+ errorMessage).c_str());
    		pEx->Delete();
    	}
    

    Best regards,

    Minxin Yu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


2 additional answers

Sort by: Most helpful
  1. RLWA32 45,326 Reputation points
    2023-11-14T12:36:32.76+00:00

    Try

    
    char error[_MAX_PATH];
    pEx->GetErrorMessage(error, _MAX_PATH);
    

  2. Guido Franzke 2,196 Reputation points
    2023-11-14T12:43:34.22+00:00
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.