Calling ImportRTF in NIRTF.DLL from Visual Basic.NET

Hello,

I have a requirement to call the ImportRTF function in NIRTF.DLL from Visual Basic .NET. I’m not sure how to delare and call the function.

Can anyone help?

The difficult part for me is how to set up the EditImportData structure… In LotusScript it’s done like this:

Type EditImportData

 FileName As String * 100

 FontID As Long

End Type

But, I’m not sure how to set this up in VB and send it to the function. Here’s what I have on the function declaration itself:

Declare Function ImportRTF Lib “NIRTF” Alias “ImportRTF” _

( D As EditImportData, Byval F As Integer, Byval M As Long, Byval A As String, Byval N As String) As Integer

Thanks.

Bill

Subject: Re: Calling ImportRTF in NIRTF.DLL from Visual Basic.NET

In VB.Net you want a structure:

Structure EditImportData

Dim FileName As String * 100

Dim FontID As Long

End Structure

Subject: Re: Calling ImportRTF in NIRTF.DLL from Visual Basic.NET

Thanks for the reply.

Here’s what I have so far in my Module1:

======================================================

Imports System.Runtime.InteropServices

Public Structure EditImportData

Dim FileName As String * 100

Dim FontID As Long

End Structure

Module Module1

<DllImport("NIRTF.dll", CharSet:=CharSet.Unicode)> _

Function ImportRTF(ByVal D As EditImportData, _

                   ByVal F As Integer, _

                   ByVal M As Long, _

                   ByVal A As String, _

                   ByVal N As String) As Integer



End Function



Sub main()



    Dim D As EditImportData

    D.FileName = "c:\DeleteMe.tmp" & Chr(0)

    D.FontID = 0



    Dim s As Integer

    s = ImportRTF(D, 3, 0, "", "C:\test.rtf")

End Sub

End Module

======================================================

The compiler doesn’t like the “* 100” part of the structure and will not run the module. If I remove it, the module will run, but it blows up on the Import() function call with this unhandled exception:

======================================================

=====================================================

Here are the details:

System.AccessViolationException was unhandled

Message=“Attempted to read or write protected memory. This is often an indication that other memory is corrupt.”

Source=“NotesAPI”

StackTrace:

   at NotesAPI.Module1.ImportRTF(EditImportData D, Int32 F, Int64 M, String A, String N)

   at NotesAPI.Module1.main() in C:\Users\bfields\Documents\Visual Studio 2008\Projects\NotesAPI\NotesAPI\Module1.vb:line 25

   at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)

   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)

   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)

   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

   at System.Threading.ThreadHelper.ThreadStart()

InnerException: