Carl -
Thanks for your reply. I have kind of been on this track but was unaware of
COMVisible attribute. I am still having a bit of a problem though; here is
my code:
vb.net project: PTSUI
Imports System.Runtime.InteropServices
<ComVisible(True)> Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
components = New System.ComponentModel.Container
Me.Text = "Form1"
End Sub
#End Region
Public Function SampleFunction() As Integer
Return 10
End Function
End Class
run:
regasm PTSUI.dll /verbose
output:
Types registered successfully
vc++ code
#import "Z:\Development\Experimental\PTS\VBUI\PTSUI\bin\PTSUI.tlb"
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
CoInitialize(NULL);
PTSUI::_Form1Ptr ptr(__uuidof(PTSUI::_Form1));
CoUninitialize();
return 0;
}
Now Intellisense can "see" _Form1Ptr and _Form1 when I type PTSUI::
Here is my compile error:
z:\Development\Experimental\PTS\VC Core\AVPTS\AVPTS\AVPTS.cpp(13): error
C2653: 'PTSUI' : is not a class or namespace name
Thanks for your help!!
Carl Daniel said:
To create a .NET class from unmanaged C++, you either need to compile your
C++ with /clr and use #using to bring the definitions from the .NET assembly
in, or for truly native C++, you need to expose your .NET object via COM.
This can be done by using the COMVisible attribute on your form class and
using regasm (a command line tool from the .NET framework SDK) to register
your .NET assembly as a COM component.
Once your assembly is COM callable, you can use #import from native C++ to
bring in the definitions in the COM type library and use them to instantiate
the VB.NET form from your native C++ code.
-cd