How to write in VB.NET from this code?

C

Cylix

The following is a c# code about using browser helper object(BHO)
anyone know in VB.NET?

[
ComVisible(true),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
Guid("FC4801A3-2BA9-11CF-A229-00AA003D7352")
]
public interface IObjectWithSite
{
[PreserveSig]
int SetSite([MarshalAs(UnmanagedType.IUnknown)]object site);
[PreserveSig]
int GetSite(ref Guid guid, out IntPtr ppvSite);
}

Thanks a lot.
 
T

Tom Shelton

The following is a c# code about using browser helper object(BHO)
anyone know in VB.NET?

[
ComVisible(true),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
Guid("FC4801A3-2BA9-11CF-A229-00AA003D7352")
]
public interface IObjectWithSite
{
[PreserveSig]
int SetSite([MarshalAs(UnmanagedType.IUnknown)]object site);
[PreserveSig]
int GetSite(ref Guid guid, out IntPtr ppvSite);
}

Thanks a lot.

hmmm, something like:

< _
ComVisible(true), _
InterfaceType(ComInterfaceType.InterfaceIsIUnknown), _
Guid("FC4801A3-2BA9-11CF-A229-00AA003D7352") _Public Interface IObjectWithSite
<PreserveSig> _
Function SetSite _
(<MarshalAs(UnmanagedType.IUnknown)> site As Object) As Integer

<PreserveSig> _
Function GetSite _
(ByRef guid As Guid, ByRef ppvSite As IntPtr) As Integer
End Interface

Anyway, that should be fairly close :)
 
C

Cor Ligthert [MVP]

Tom,

You old VB6 guys show in fact often a lack of that.

You all are experts in taken all kind of interfaces, Api's or whatever for
what is now mostly an easier to maintenance class not in the language but in
the .Net and therefore for everybody.

It was just the thought I wanted to deal with you.
(And tickling for a reaction from Herfried)

:)

Cor

Tom Shelton said:
The following is a c# code about using browser helper object(BHO)
anyone know in VB.NET?

[
ComVisible(true),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
Guid("FC4801A3-2BA9-11CF-A229-00AA003D7352")
]
public interface IObjectWithSite
{
[PreserveSig]
int SetSite([MarshalAs(UnmanagedType.IUnknown)]object site);
[PreserveSig]
int GetSite(ref Guid guid, out IntPtr ppvSite);
}

Thanks a lot.

hmmm, something like:

< _
ComVisible(true), _
InterfaceType(ComInterfaceType.InterfaceIsIUnknown), _
Guid("FC4801A3-2BA9-11CF-A229-00AA003D7352") _Public Interface IObjectWithSite
<PreserveSig> _
Function SetSite _
(<MarshalAs(UnmanagedType.IUnknown)> site As Object) As Integer

<PreserveSig> _
Function GetSite _
(ByRef guid As Guid, ByRef ppvSite As IntPtr) As Integer
End Interface

Anyway, that should be fairly close :)
 
T

Tom Shelton

Tom,

You old VB6 guys show in fact often a lack of that.

Lack of what? I'm not sure I'm following here.
You all are experts in taken all kind of interfaces, Api's or whatever for
what is now mostly an easier to maintenance class not in the language but in
the .Net and therefore for everybody.

Are BHO's implemented in the framework? They maybe, but I'm not aware of
them.
It was just the thought I wanted to deal with you.
(And tickling for a reaction from Herfried)

:)

Cor

Sorry Cor, I'm not following the meaning of your post. All I did was try and
convert his C# code to VB.NET. I'm not certain it was 100% accurate - I'm not
in a mind to fully test it, but I think it was pretty close for an on the fly
conversion :)
 
C

Cor Ligthert [MVP]

Tom,

When it is about using this kind of code
ComVisible(true),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
Guid("FC4801A3-2BA9-11CF-A229-00AA003D7352")

It are always you, Herfried, in past Armin, and some others I cannot get the
name from our Scandinavian friend, who answer this. But one thing they have
in common almost forever formely VB6 people.

That is all.

Cor
 
H

Herfried K. Wagner [MVP]

Cor,

Cor Ligthert said:
When it is about using this kind of code


It are always you, Herfried, in past Armin, and some others I cannot get
the name from our Scandinavian friend, who answer this. But one thing they
have in common almost forever formely VB6 people.

That's true. Many "young" developers who started with ".NET Framework and
C#" don't have the background knowledge about COM/Win32 programming.
However, there are certain things which can unfortunately only archieved
using p/invoke and COM interop, like BHOs.
 
C

Cylix

Thanks Tom,
I do really weak in concept of COM.
Please give me further help.

'------------------- My Code Now ----------------------------------
Public Class BHO

< _
ComVisible(true), _
InterfaceType(ComInterfaceType.InterfaceIsIUnknown), _
Guid("FC4801A3-2BA9-11CF-A229-00AA003D7352") _


Public Interface IObjectWithSite
<PreserveSig()> _
Function SetSite _
(<MarshalAs(UnmanagedType.IUnknown)> ByVal site As Object) As
Integer

<PreserveSig()> _
Function GetSite _
(ByRef guid As Guid, ByRef ppvSite As IntPtr) As Integer
End Interface


End Class
 
C

Cylix

Sorry for such silly question,
I forget to import System.Runtime.InteropServices.

I search for sites and still dunno what is the meaning of PreserveSig
and MarshalAs.
Does anyone can explain whats that.

Thank you so much.
 
T

Tom Shelton

Sorry for such silly question,
I forget to import System.Runtime.InteropServices.

I search for sites and still dunno what is the meaning of PreserveSig
and MarshalAs.
Does anyone can explain whats that.

Thank you so much.

Sure...

MarshalAs is a hint to the marshaling engine about what type is expected. For
example, it is a mapping so to speak between the native .net type and the
native data type of the called assembly.

PreserveSig tells the runtime to ignore normal HRESULT, retval behavior. The
real return value of a COM function is an HRESULT. All other return values
are returned via a [out, retval] parameter... So, a function that looked like
this in COM:

HRESULT DoCoolStuff ([in] int i, [out, retval] int* j);

would translate into:

Function DoCoolStuff (ByVal i As Integer) As Integer

That's well and good - unless your function can return a success value other
then S_OK.... See, there are times when you can have COM functions that can
return other values that still represent success. So, you want to capture
that (and sometimes it is important)... But, the problem is if the function
returns anything other then S_OK the .net runtime will discard the [out,
retval] parameter and throw an exception based of the HRESULT (some HRESULTS
map to native .NET exceptions - some don't, in that case you get a
COMException). PreserveSig prevents this behavior. By adding PreserveSig you
can then get the actual HRESULT value for inspection... So, your above
function is now something like:

Function DoCoolStuff (ByVal i As Integer, <Out> ByRef j) As Integer

HTH,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top