Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

We have a VB6 application which dynamically loads OCXs as they are chosen by users. We'd like to start moving to .NET.

 

Is there any way we can write controls in .NET and still call them from the main VB6 app, or would we have to re-write this first?

  • *Experts*
Posted (edited)

Moving the whole application would be better then single components. You can create a wrapper for .NET class and use it, but framework will still be required.

Go to your projects properties, then from the left choose Configuration Properties, then build. Then check, Register For COM Interop.

Edited by mutant
  • *Experts*
Posted
There is other stuff you need to do, too, like use the GUID Generator to make you GUIDs for the COM object, the typelib, etc. You also need to make sure you give your class the ComClass attribute. Read the MSDN for more info.
Posted

Thanks for this - still a couple of teething problems, but this certainly got us started.

 

We'd really like to rewrite everything in one go, but there are time constraints and a Testing Manager who's liable to throw a wobbly if we suggest it!

  • 1 year later...
Posted

To test this you should open a new project (Visual Basic Project \ Class Library) and copy the code below to the class:

Imports System.Runtime.InteropServices

<Assembly: ComVisible(False)> 
<Assembly: ClassInterface(ClassInterfaceType.None)> 

<ComVisible(True), Guid("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"), InterfaceType(ComInterfaceType.InterfaceIsDual)> _
Public Interface SubsToExpose

  <DispIdAttribute(1)> Sub Load(ByVal strConn As String, ByVal strSelect As String, ByVal strTemDoc As String, ByVal strArcDoc As String)
  <DispIdAttribute(2)> Sub ExecuteWord()

  'NOTE:  If you add in more methods, increment DispIdAttribute by one for each...

End Interface

<ComVisible(True), Guid("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"), ClassInterface(ClassInterfaceType.None), ProgId("YourLibNameHere.YourClassNameHere")> _
Public NotInheritable Class clsAutomation
  Implements SubsToExpose

  Private Sub SubsToExpose_Load(ByVal strConn As String, ByVal strSelect As String, ByVal strTemDoc As String, ByVal strArcDoc As String) Implements SubsToExpose.Load
     On Error GoTo ShowError

     gstrTitle = Diagnostics.Process.GetCurrentProcess.ProcessName

     gstrConn = strConn
     gstrSelect = strSelect

     gstrTemDoc = strTemDoc
     gstrArcDoc = strArcDoc

     SetLicence()

     Exit Sub
ShowError:
     InfoError(Err.Number, Err.Description)
     Exit Sub
  End Sub

  Private Sub SubsToExpose_ExecuteWord() Implements SubsToExpose.ExecuteWord
     On Error GoTo ShowError

     ReplaceWord()

     Exit Sub
ShowError:
     InfoError(Err.Number, Err.Description)
     Exit Sub
  End Sub
End Class

It seems to be a little complicated at first time, but if you use this class just to gave a name to the procedures is very simple.

 

I have some modules with the code itself and here I just call the code.

 

The guid is a kind of identity, and can generate it with a very little program i've made just for this. (Attached) Then you just have to press 'Create new Guid' and replace XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX in the code by the string in the textbox.

 

You you have posted all public functions and procedures you'll need in the class go to Project Properties\Configuration properties\Build and check Register for COM Interop.

 

You'll have a .dll File, a .pdb File and .tlb File.

 

When you finish this, please let me know if you don't know how to register the file.

SysGuid.zip

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...