473,414 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Convert Interface definition to VB.NET

Can anyone convert the following C++ interface definition to VB.NET? I have
had a go, but I cannot make the Load function work and the IsDirty function
gives an error (Object not set to an instance).

MIDL_INTERFACE("7FD52380-4E07-101B-AE2D-08002B2EC713")
IPersistStreamInit : public IPersist
{
public:
virtual HRESULT STDMETHODCALLTYPE IsDirty( void) = 0;
virtual HRESULT STDMETHODCALLTYPE Load(/* [in] */ LPSTREAM pStm) =
0;
virtual HRESULT STDMETHODCALLTYPE Save(/* [in] */ LPSTREAM pStm, /*
[in] */ BOOL fClearDirty) = 0;
virtual HRESULT STDMETHODCALLTYPE GetSizeMax(/* [out] */
ULARGE_INTEGER *pCbSize) = 0;
virtual HRESULT STDMETHODCALLTYPE InitNew( void) = 0;
};

One thing I am not sure of is whether I have to include an 'Inherits
IPersist' at the start (which itself would include an Inherits IUnknown), or
not. If so, I would also need VB.NET versions of these other two interfaces.

TIA

Charles
Nov 19 '05 #1
7 6366
Hi,
Can anyone convert the following C++ interface definition to VB.NET? I have had a go, but I cannot make the Load function work and the IsDirty function gives an error (Object not set to an instance).
Can you show non-working VB.NET implementation of IPersistStreamInit
interface? I don't have VB .NET IPersistStreamInit implementation, only C#
one, but probably I'll be able tell you what is wrong.
One thing I am not sure of is whether I have to include an 'Inherits
IPersist' at the start (which itself would include an Inherits IUnknown), or not.


Not you shouldn't. Note, .NET declaration for IPersistStreamInit should
contain methods for base interfaces as well (IPersist), in vtable order.
...
Regards,
Vadim.
Nov 19 '05 #2
Charles,
One thing I am not sure of is whether I have to include an 'Inherits
IPersist' at the start
You can, but you still have to duplicate the base interface methods in
the derived interface. See below

(which itself would include an Inherits IUnknown)


IUnknown shouldn't be declared, since you don't write your own
implementation for it. The runtime takes care of it.
Try it like this

<ComImport(), Guid("0000010c-0000-0000-C000-000000000046"), _
InterfaceType(ComInterfaceType.InterfaceIsIUnknown )> _
Interface IPersist
Sub GetClassID(ByRef pClassId As Guid)
End Interface

<ComImport(), Guid("7FD52380-4E07-101B-AE2D-08002B2EC713"), _
InterfaceType(ComInterfaceType.InterfaceIsIUnknown )> _
Interface IPersistStreamInit : Inherits IPersist
Shadows Sub GetClassID(ByRef pClassId As Guid)
<PreserveSig()> _
Function IsDirty() As Integer
Sub Load(ByVal pStm As IStream)
Sub Save(ByVal pStm As IStream, _
<MarshalAs(UnmanagedType.Bool)> ByVal fClearDirty As Boolean)
Sub GetMaxSize(ByRef pCbSize As Long)
Sub InitNew()
End Interface

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 19 '05 #3
Hi Vadim

I have implemented Mattias's suggestion in the thread following this one
which gives better results than I was getting, but I am still not quite
there yet.

I will explain in the other thread.

Thanks for your reply.

Regards

Charles
"Vadim Melnik" <vm****@REMOVETHISdocsultant.com> wrote in message
news:uk****************@TK2MSFTNGP11.phx.gbl...
Hi,
Can anyone convert the following C++ interface definition to VB.NET? I have
had a go, but I cannot make the Load function work and the IsDirty

function
gives an error (Object not set to an instance).


Can you show non-working VB.NET implementation of IPersistStreamInit
interface? I don't have VB .NET IPersistStreamInit implementation, only C#
one, but probably I'll be able tell you what is wrong.
One thing I am not sure of is whether I have to include an 'Inherits
IPersist' at the start (which itself would include an Inherits

IUnknown), or
not.


Not you shouldn't. Note, .NET declaration for IPersistStreamInit should
contain methods for base interfaces as well (IPersist), in vtable order.
..
Regards,
Vadim.

Nov 19 '05 #4
Hi Mattias

I have implemented your suggestion and I now get much more sensible results.

IsDirty() now returns 1, which is more what I expect. However, although
Load() goes off for several seconds it does not load my HTML into the
browser.

It may not be the interface definition now, but could be the way I am
getting my HTML into the stream.

I have copied the example from the MSDN article "HOW TO: Wrap a UCOMIStream
in a Stream Class in Visual Basic .NET". This allows me to put an HTML
string into a UCOMIstream, which I am passing to the Load() function, but it
is not rendering even simple HTML, and when I view source, my HTML is
missing.

Although your definition uses IStream, can I replace this with UCOMIstream?
Is there another, easier way to get some string data into an
IStream/UCOMIstream object, that I can pass to the Load() function,
preferably within VB.NET, without having to resort to an unmanaged C++ DLL?

Thanks for your help.

Regards

Charles
"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:Ov*************@tk2msftngp13.phx.gbl...
Charles,
One thing I am not sure of is whether I have to include an 'Inherits
IPersist' at the start


You can, but you still have to duplicate the base interface methods in
the derived interface. See below

(which itself would include an Inherits IUnknown)


IUnknown shouldn't be declared, since you don't write your own
implementation for it. The runtime takes care of it.
Try it like this

<ComImport(), Guid("0000010c-0000-0000-C000-000000000046"), _
InterfaceType(ComInterfaceType.InterfaceIsIUnknown )> _
Interface IPersist
Sub GetClassID(ByRef pClassId As Guid)
End Interface

<ComImport(), Guid("7FD52380-4E07-101B-AE2D-08002B2EC713"), _
InterfaceType(ComInterfaceType.InterfaceIsIUnknown )> _
Interface IPersistStreamInit : Inherits IPersist
Shadows Sub GetClassID(ByRef pClassId As Guid)
<PreserveSig()> _
Function IsDirty() As Integer
Sub Load(ByVal pStm As IStream)
Sub Save(ByVal pStm As IStream, _
<MarshalAs(UnmanagedType.Bool)> ByVal fClearDirty As Boolean)
Sub GetMaxSize(ByRef pCbSize As Long)
Sub InitNew()
End Interface

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.

Nov 19 '05 #5
Hi Charles,
I have copied the example from the MSDN article "HOW TO: Wrap a UCOMIStream in a Stream Class in Visual Basic .NET". This allows me to put an HTML
string into a UCOMIstream, which I am passing to the Load() function, but it is not rendering even simple HTML, and when I view source, my HTML is
missing.


I'd propose unmanaged and more efficient way- use Marshal.StringToHGlobalXXX
to retrieve string unmanaged memory, and then call CreateStreamOnHGlobal API
via PInvoke. And in Mattias definition you can update IStream with
UCOMIStream.

...
Regards,
Vadim.
Nov 19 '05 #6
Vadim

Sorry to appear dim, but is this something I can do entirely from within
VB.NET? I see the Marshal.StringToHGlobalXXX functions, but not the
CreateStreamOnHGlobal function. You refer to this as an API, so does it need
a Declare? I don't suppose you have the appropriate VB.NET version?

After passing the resultant stream to the Load() function, do I have to
release the stream/memory?

Thanks for your help.

Regards

Charles

"Vadim Melnik" <vm****@REMOVETHISdocsultant.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hi Charles,
I have copied the example from the MSDN article "HOW TO: Wrap a UCOMIStream
in a Stream Class in Visual Basic .NET". This allows me to put an HTML
string into a UCOMIstream, which I am passing to the Load() function,

but it
is not rendering even simple HTML, and when I view source, my HTML is
missing.
I'd propose unmanaged and more efficient way- use

Marshal.StringToHGlobalXXX to retrieve string unmanaged memory, and then call CreateStreamOnHGlobal API via PInvoke. And in Mattias definition you can update IStream with
UCOMIStream.

..
Regards,
Vadim.

Nov 19 '05 #7
Charles,

I talked about unmanaged way, CreateStreamOnHGlobal is not part of .NET
Framework, it's inside "ole32.dll" . Use DllImportAttribute to import this
API to VB.NET. Unfortunately I am not well familiar with VB, below just code
prototype, so please forgive me possible errors:

<DllImport("OLE32.DLL")> _
Public Shared Sub CreateStreamOnHGlobal(hGlobal As IntPtr, fDelete bool As
Boolean, ByRef stm As UCOMIStream)
End Sub
After passing the resultant stream to the Load() function, do I have to
release the stream/memory?
It depends on the way you declare/invoke CreateStreamOnHGlobal and Load.
HGLOBAL returned from Marshal.StringToHGlobal need to be released by
FreeHGlobal call. CreateStreamOnHGlobal has options (2nd parameter) allowing
to automatically invoke GlobalFree for passed HGLOBAL handle, when stream
will be released. So if you set this option to true, FreeHGlobal call in
unnecessary.

Regarding stream interface pointer - for current case CLR automatically will
release stream. You can force it by Marshal.ReleaseComObject call.

"Charles Law" <la****@btinternet.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl... Vadim

Sorry to appear dim, but is this something I can do entirely from within
VB.NET? I see the Marshal.StringToHGlobalXXX functions, but not the
CreateStreamOnHGlobal function. You refer to this as an API, so does it need a Declare? I don't suppose you have the appropriate VB.NET version?

After passing the resultant stream to the Load() function, do I have to
release the stream/memory?

Thanks for your help.

Regards

Charles

"Vadim Melnik" <vm****@REMOVETHISdocsultant.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hi Charles,
I have copied the example from the MSDN article "HOW TO: Wrap a

UCOMIStream
in a Stream Class in Visual Basic .NET". This allows me to put an HTML
string into a UCOMIstream, which I am passing to the Load() function,

but
it
is not rendering even simple HTML, and when I view source, my HTML is
missing.


I'd propose unmanaged and more efficient way- use

Marshal.StringToHGlobalXXX
to retrieve string unmanaged memory, and then call CreateStreamOnHGlobal

API
via PInvoke. And in Mattias definition you can update IStream with
UCOMIStream.

..
Regards,
Vadim.


Nov 19 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Anon Email | last post by:
Hi people, I'm learning about header files in C++. The following is code from Bartosz Milewski: // Code const int maxStack = 16; class IStack
8
by: Steven Livingstone | last post by:
Anyone able to explain to me why you cannot define an interface that can then be implemented using static methods? I understand the C# CLS states this, but just interested in the reasons behind...
5
by: Peter Berry | last post by:
I was surprised and somewhat disappointed by the fact that you cannot declare types in an interface. I discovered this when defining an interface that included events, where the definition of the...
7
by: Charles Law | last post by:
Can anyone convert the following C++ interface definition to VB.NET? I have had a go, but I cannot make the Load function work and the IsDirty function gives an error (Object not set to an...
0
by: Mark | last post by:
I create a simple interface in a com object: public interface ISimple { void a(); int b(); } I build the object in Visual Studio and load the object from Excel. I can call a and b...
4
by: Raja Chandrasekaran | last post by:
Hai friends, I really wonder, If the interface does not have any definition, Y do we need to use interface. You can then only we can use Multiple inheritance. I really cant understand, Just for...
8
by: Serge BRIC | last post by:
My application, written in .NET VB, tries to get a communication port handle from a TAPI object with this code: Dim vFileHandle As Byte() = appel.GetIDAsVariant("comm/datamodem") The...
5
by: Random | last post by:
How can I use reflection (or some other method) to find the type of an object that has been passed in to my method under an interface definition? I try to use GetType, but that won't work.
15
by: Xah Lee | last post by:
On Java's Interface Xah Lee, 20050223 In Java the language, there's this a keyword “interfaceâ€. In a functional language, a function can be specified by its name and parameter specs....
52
by: Ben Voigt [C++ MVP] | last post by:
I get C:\Programming\LTM\devtools\UselessJunkForDissassembly\Class1.cs(360,27): error CS0535: 'UselessJunkForDissassembly.InvocableInternals' does not implement interface member...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.