Translate from C++ to C#

  • Thread starter Thread starter PL
  • Start date Start date
P

PL

Hi,

I would need the equivalent in C#, suggestion?

HRESULT LoadWebBrowserFromStream(IWebBrowser* pWebBrowser, IStream* pStream)
{
HRESULT hr;
IDispatch* pHtmlDoc = NULL;
IPersistStreamInit* pPersistStreamInit = NULL;

// Retrieve the document object.
hr = pWebBrowser->get_Document( &pHtmlDoc );
if ( SUCCEEDED(hr) )
{
// Query for IPersistStreamInit.
hr = pHtmlDoc->QueryInterface( IID_IPersistStreamInit,
(void**)&pPersistStreamInit );
if ( SUCCEEDED(hr) )
{
// Initialize the document.
hr = pPersistStreamInit->InitNew();
if ( SUCCEEDED(hr) )
{
// Load the contents of the stream.
hr = pPersistStreamInit->Load( pStream );
}
pPersistStreamInit->Release();
}
}
}
 
PL said:
Hi,

I would need the equivalent in C#, suggestion?

HRESULT LoadWebBrowserFromStream(IWebBrowser* pWebBrowser, IStream* pStream)
{
HRESULT hr;
IDispatch* pHtmlDoc = NULL;
IPersistStreamInit* pPersistStreamInit = NULL;

// Retrieve the document object.
hr = pWebBrowser->get_Document( &pHtmlDoc );
if ( SUCCEEDED(hr) )
{
// Query for IPersistStreamInit.
hr = pHtmlDoc->QueryInterface( IID_IPersistStreamInit,
(void**)&pPersistStreamInit );
if ( SUCCEEDED(hr) )
{
// Initialize the document.
hr = pPersistStreamInit->InitNew();
if ( SUCCEEDED(hr) )
{
// Load the contents of the stream.
hr = pPersistStreamInit->Load( pStream );
}
pPersistStreamInit->Release();
}
}
}

As it looks like COM code, have you tried using the COM objects in C#?
With questions like yours: post what you have tried yourself, instead of
doing all the work for you.

Frans


--
 
Obviously, I've tried the COM object with C#... I would not sent message
like this if I was able to translate this code from C++ to C#...
 
PL said:
Obviously, I've tried the COM object with C#... I would not sent message
like this if I was able to translate this code from C++ to C#...

Well, post what you have done already in C# and describe what went wrong or
what's the issue.

Willy.
 
Well, I don't have any conclusive code...

I don't find the class or interface for IStream, IPersistStreamInit and
IDispatch. Just with that, it would be more easier...
 
Back
Top