473,785 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems using IPersistFile with VB.NET

I'm having problems with the IPersistFile interface. We have in house
objects that support IPersistFile (and have done for years). I would like
to load an object using this interface with VB.NET (note: I'm already
successfully using our IPersistStorage interface for structured storage with
other of our file types, but these particular file types do not support
IPersistStorage ). Anyway, the result I get from IPersistStorage ::Load
is -2147467259, or "Unspecifie d Error". The software that generates, writes
and reads these files (MFC C++ program) has no problem with them. Is there
something wrong with my interface definition or usage here?

Any pointers would be great, thanks.
*************** ***** MY WRAPPER FOR IPersistFile *************** ********

<ComImport(), InterfaceType(C omInterfaceType .InterfaceIsIUn known),
Guid("0000010b-0000-0000-C000-000000000046")> _
Public Interface IPersistFile

<PreserveSig( )> _
Function GetClassID(ByRe f pClassID As IntPtr) As Integer

<PreserveSig( )> _
Function IsDirty() As Integer

<PreserveSig( )> _
Function Load(<MarshalAs (UnmanagedType. LPStr)> ByVal pszFilename As
String, ByVal dwMode As Integer) As Integer

<PreserveSig( )> _
Function Save(<MarshalAs (UnmanagedType. LPStr)> ByVal pszFilename As
String, <MarshalAs(Unma nagedType.Bool) > ByVal fRemember As Boolean) As
Integer

<PreserveSig( )> _
Function SaveCompleted(< MarshalAs(Unman agedType.LPStr) > ByVal
pszFilename As String) As Integer

<PreserveSig( )> _
Function GetCurFile(ByRe f theFile As String) As Integer
End Interface

*************** ***** THE FUNCTION USING IPersistFile *************** ********

Dim Result As Boolean
Dim theData() As Byte

Dim theIPersistFile As COM.IPersistFil e

Try
Dim theImage As TherMonitor.Ima ge

' Get type ID

Dim theType As Type = Type.GetTypeFro mProgID("TherMo nitor.Image")

' Create a blank instance.

theImage = CType(Activator .CreateInstance (theType), TherMonitor.Ima ge)

' Cast to IPersistFile

theIPersistFile = CType(theImage, COM.IPersistFil e)

' Now atempt to open it

Dim hResult As Integer = theIPersistFile .Load(theFile, 0)

' Save from document into theData

If hResult = 0 Then

..............
..............

' Success

Result = True
Else

' Failed

Result = False
End If

Catch ex As Exception

' Failed

Result = False

Finally

End Try

' Return the result...

Return Result
Nov 20 '05 #1
2 3428
I'm not sure if the definitions the problem, but if it is, it would be
easier for you to use System.Runtime. InteropServices .UCOMIPersistFi le... It
should be what you want. :)

Dan

"Robin Tucker" <id************ *************@r eallyidont.com> wrote in
message news:cd******** ***********@new s.demon.co.uk.. .
I'm having problems with the IPersistFile interface. We have in house
objects that support IPersistFile (and have done for years). I would like
to load an object using this interface with VB.NET (note: I'm already
successfully using our IPersistStorage interface for structured storage with other of our file types, but these particular file types do not support
IPersistStorage ). Anyway, the result I get from IPersistStorage ::Load
is -2147467259, or "Unspecifie d Error". The software that generates, writes and reads these files (MFC C++ program) has no problem with them. Is there something wrong with my interface definition or usage here?

Any pointers would be great, thanks.
*************** ***** MY WRAPPER FOR IPersistFile *************** ********

<ComImport(), InterfaceType(C omInterfaceType .InterfaceIsIUn known),
Guid("0000010b-0000-0000-C000-000000000046")> _
Public Interface IPersistFile

<PreserveSig( )> _
Function GetClassID(ByRe f pClassID As IntPtr) As Integer

<PreserveSig( )> _
Function IsDirty() As Integer

<PreserveSig( )> _
Function Load(<MarshalAs (UnmanagedType. LPStr)> ByVal pszFilename As
String, ByVal dwMode As Integer) As Integer

<PreserveSig( )> _
Function Save(<MarshalAs (UnmanagedType. LPStr)> ByVal pszFilename As
String, <MarshalAs(Unma nagedType.Bool) > ByVal fRemember As Boolean) As
Integer

<PreserveSig( )> _
Function SaveCompleted(< MarshalAs(Unman agedType.LPStr) > ByVal
pszFilename As String) As Integer

<PreserveSig( )> _
Function GetCurFile(ByRe f theFile As String) As Integer
End Interface

*************** ***** THE FUNCTION USING IPersistFile *************** ********
Dim Result As Boolean
Dim theData() As Byte

Dim theIPersistFile As COM.IPersistFil e

Try
Dim theImage As TherMonitor.Ima ge

' Get type ID

Dim theType As Type = Type.GetTypeFro mProgID("TherMo nitor.Image")

' Create a blank instance.

theImage = CType(Activator .CreateInstance (theType), TherMonitor.Ima ge)

' Cast to IPersistFile

theIPersistFile = CType(theImage, COM.IPersistFil e)

' Now atempt to open it

Dim hResult As Integer = theIPersistFile .Load(theFile, 0)

' Save from document into theData

If hResult = 0 Then

..............
..............

' Success

Result = True
Else

' Failed

Result = False
End If

Catch ex As Exception

' Failed

Result = False

Finally

End Try

' Return the result...

Return Result

Nov 20 '05 #2
Ahhhh ok I hadn't realised we had a wrapper already with .net. thanks will
give it a go.

"Daniel" <da******@hotma il.com> wrote in message
news:Oe******** ******@TK2MSFTN GP11.phx.gbl...
I'm not sure if the definitions the problem, but if it is, it would be
easier for you to use System.Runtime. InteropServices .UCOMIPersistFi le... It should be what you want. :)

Dan

"Robin Tucker" <id************ *************@r eallyidont.com> wrote in
message news:cd******** ***********@new s.demon.co.uk.. .
I'm having problems with the IPersistFile interface. We have in house
objects that support IPersistFile (and have done for years). I would like to load an object using this interface with VB.NET (note: I'm already
successfully using our IPersistStorage interface for structured storage

with
other of our file types, but these particular file types do not support
IPersistStorage ). Anyway, the result I get from IPersistStorage ::Load
is -2147467259, or "Unspecifie d Error". The software that generates,

writes
and reads these files (MFC C++ program) has no problem with them. Is

there
something wrong with my interface definition or usage here?

Any pointers would be great, thanks.
*************** ***** MY WRAPPER FOR IPersistFile *************** ********

<ComImport(), InterfaceType(C omInterfaceType .InterfaceIsIUn known),
Guid("0000010b-0000-0000-C000-000000000046")> _
Public Interface IPersistFile

<PreserveSig( )> _
Function GetClassID(ByRe f pClassID As IntPtr) As Integer

<PreserveSig( )> _
Function IsDirty() As Integer

<PreserveSig( )> _
Function Load(<MarshalAs (UnmanagedType. LPStr)> ByVal pszFilename As
String, ByVal dwMode As Integer) As Integer

<PreserveSig( )> _
Function Save(<MarshalAs (UnmanagedType. LPStr)> ByVal pszFilename As
String, <MarshalAs(Unma nagedType.Bool) > ByVal fRemember As Boolean) As
Integer

<PreserveSig( )> _
Function SaveCompleted(< MarshalAs(Unman agedType.LPStr) > ByVal
pszFilename As String) As Integer

<PreserveSig( )> _
Function GetCurFile(ByRe f theFile As String) As Integer
End Interface

*************** ***** THE FUNCTION USING IPersistFile

*************** ********

Dim Result As Boolean
Dim theData() As Byte

Dim theIPersistFile As COM.IPersistFil e

Try
Dim theImage As TherMonitor.Ima ge

' Get type ID

Dim theType As Type = Type.GetTypeFro mProgID("TherMo nitor.Image")

' Create a blank instance.

theImage = CType(Activator .CreateInstance (theType), TherMonitor.Ima ge)
' Cast to IPersistFile

theIPersistFile = CType(theImage, COM.IPersistFil e)

' Now atempt to open it

Dim hResult As Integer = theIPersistFile .Load(theFile, 0)

' Save from document into theData

If hResult = 0 Then

..............
..............

' Success

Result = True
Else

' Failed

Result = False
End If

Catch ex As Exception

' Failed

Result = False

Finally

End Try

' Return the result...

Return Result


Nov 20 '05 #3

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

Similar topics

0
2096
by: Jerome Lefebvre | last post by:
Hello, Hope this will interest a few. I been working with a friend on the problems given out during the "International Collegiate Programming Contest" (ICPC) http://icpc.baylor.edu/icpc/ . Started out just trying to find the solutions and then moving on, to "aggressively" trying to find the best solution for each problems. First started to work on the problems using C++ and then moved on to using Python, mostly since it was much easier...
14
2326
by: Jim Hubbard | last post by:
Are you up to speed on the difficulties in using the 1.1 .Net framework? Not if you are unaware of the 1,596 issues listed at KBAlertz (http://www.kbalertz.com/technology_3.aspx). If you are going to use .Net......I highly recommend signing up for the free KBAlertz newsletter at http://www.kbalertz.com/default.aspx. Looking at all of the errors and quirks sometimes makes me wonder if this thing is really ready for prime time.
6
2617
by: c d saunter | last post by:
Greetings All, In Widows Explorer there is a thumbnail view, where you see images as thumbnails. Applications such as MS Office and OpenOffice, when installed, cause their respective filetypes to be previewed as thumbnails as well. Thumbnails are stored in the Thumbs.db hidden file. There my knowledge ends. I'm asuming that aplications install registry keys somewhere that register an invocation that returns a thumbnail for a given...
26
2677
by: jamesbeswick | last post by:
I've been using Access since version 97 and I've migrated to 2003. I've noticed a substantial number of strange ActiveX/OLE and code corruption problems when writing databases. The only solution I've found is to create a new database and import all the objects from the corrupted file. Has anyone else found a solution to this annoying problem? I cannot find anything useful on Microsoft's website and I haven't seen any posts about the...
10
2416
by: BBFrost | last post by:
We just recently moved one of our major c# apps from VS Net 2002 to VS Net 2003. At first things were looking ok, now problems are starting to appear. So far ... (1) ComboBox.SelectedValue = db_value; If the db_value was not included in the ComboBox value list the ComboBox.SelectedIndex used to return -1, Now the very same code is
2
3183
by: Brian | last post by:
NOTE ALSO POSTED IN microsoft.public.dotnet.framework.aspnet.buildingcontrols I have solved most of my Server Control Collection property issues. I wrote an HTML page that describes all of the problems that I have encountered to date and the solutions (if any) that I found. http://users.adelphia.net/~brianpclab/ServerControlCollectionIssues.htm This page also has all of the source code in a compressed file that you are free to download...
1
7397
by: Plamen | last post by:
Hi , I need to change the ToolTip in Windows explorer that is shown when the cursor is over a file. Here is how it should work: you create a class that imports IPersistFile and IQueryInfo. After adding some registry values when you move the cursor over some file in Win Explorer, the shell will create object from your class and will call IPersistFile::Load. Well here is the problem - in my situation it is not called. The only method that is...
2
3277
by: Mike | last post by:
Hi, I am new to C and having problems with the following program. Basically I am trying to read some files, loading data structures into memory for latter searching. I am trying to use structres and arrays of pointers to them. I have gotten the program to compile with gcc on WinXP. If the file i read doesnt have alot of records, it runs thru. But once i add more, it dies. In this program i have 4 files setup to read. The
9
2417
by: =?Utf-8?B?SG93YXJkIFNtaXRo?= | last post by:
I am using VC++ 6.0 (with SP5 installed). When using WinXP this is with SP2 installed. I am developing an instrumentation system comprising a set of networked PCs connected using TCP/IP TCP links. Communications on the Windows PCs use a class derived from CAsyncSocket(). I have written client and server versions of my software for use on the appropriate PCs. I am also using communicating with a legacy DOS based system, with the software...
0
9646
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9484
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10097
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9957
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6742
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5386
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5518
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4055
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2887
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.