473,320 Members | 1,950 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,320 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 16 '05 #1
7 2341
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 16 '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 16 '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 16 '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 16 '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 16 '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 16 '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 16 '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...
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...
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...
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...
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
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.