473,408 Members | 1,870 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,408 software developers and data experts.

Using C# ClassLibrary/WindowsControlLibrary in MSVC6/VB

Hi,
Was wondering if anybody could help. I'm slowly trying to migrate over to
the .NET using windows forms, but still have a need to support existing
systems developed in MSVC 6 using MFC and VB6.

So my question is, can I develop code in C# in a DLL that I can then invoke
from MSVC 6 using MFC. As yet I have not seen any examples or samples of
this being done.

Thanks

Wayne Gibson
Nov 16 '05 #1
5 2923
hi ,
You can do that
using tlbexp.exe and regasm you can interoperate with a .net dll

for more details check this link
http://msdn.microsoft.com/library/de...nentstocom.asp

regards
Ansil
Dimensions
Technopark Trivandrum

"Wayne Gibson" wrote:
Hi,
Was wondering if anybody could help. I'm slowly trying to migrate over to
the .NET using windows forms, but still have a need to support existing
systems developed in MSVC 6 using MFC and VB6.

So my question is, can I develop code in C# in a DLL that I can then invoke
from MSVC 6 using MFC. As yet I have not seen any examples or samples of
this being done.

Thanks

Wayne Gibson

Nov 16 '05 #2
Thanks for the link. I had seen something about the tlbexp.exe and
regasm.exe and tried to do this.
But had problems with my methods becoming available within MSVC 6 and VB 6.

Has anybody seen a walkthrough or an sample projects that I can download

Thanks
Nov 16 '05 #3
hi Gibson,

The following are links which i got after searching .

http://www.dnzone.com/ShowDetail.asp?NewsId=126

http://www.codeproject.com/dotnet/cominterop.asp

i think the second one is good

regards
Ansil

"Wayne Gibson" wrote:
Thanks for the link. I had seen something about the tlbexp.exe and
regasm.exe and tried to do this.
But had problems with my methods becoming available within MSVC 6 and VB 6.

Has anybody seen a walkthrough or an sample projects that I can download

Thanks

Nov 16 '05 #4
Thanks, I'll take a look..
Nov 16 '05 #5
Hi again,

Still having a few problems...
I have managed to get the .NET ClassLibrary created and now have it working
with VB 6. But I'm having a few problems getting it working with MSVC 6...

Here is the code for the .NET Class Library
--------------- Start ----------------
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace ClassLibrary1
{
interface IDotNetInterface
{
void Initialize();

string Caption
{
set;
}

int ShowDialog();
}

[ClassInterface(ClassInterfaceType.AutoDual)]
public class Class1 : IDotNetInterface
{
public Class1()
{
}

public void Initialize()
{
m_sCaption = "";
}

public string Caption
{
set { m_sCaption = value; }
}

public int ShowDialog()
{
System.Windows.Forms.MessageBox.Show("Hello World");
return 1;
}

private string m_sCaption;
}
}
---------------End ------------------

I then ran REGASM ClassLibrary1.DLL /TLB:ClassLibrary1.tlb
I then created a simple VB App. I added a reference to the
ClassLibrary1.tlb. Add a Button to the form with the following code:
////////////// VB Code
Private Sub Command1_Click()
Dim Test As New ClassLibrary1.Class1
Dim Result As Long

Result = Test.ShowDialog()
End Sub
////////////////////////////////
This at first didn't work, so I build an EXE and place the EXE and
ClassLibrary1.dll in the same directory. It worked!!!

So I thought I would try MSVC 6, as this where I really need to use the .NET
dll.
I created a simple MFC Dialog Based application. I added a button to the
dialog and added the following code:
////////////////////////////////////////////////////////// VC Code
#import "c:\test\ClassLibrary1\bin\debug\ClassLibrary1.tlb "
raw_interfaces_only

void CTestAppDlg::OnButton1()
{
ClassLibrary1::_Class1Ptr Class1;

HRESULT hr =
Class1.CreateInstance(__uuidof(ClassLibrary1::_Cla ss1Ptr) );
if(hr != S_OK)
{
switch(hr)
{
case E_NOINTERFACE:
::AfxMessageBox("E_NOINTERFACE");
break;

case CLASS_E_NOAGGREGATION:
::AfxMessageBox("CLASS_E_NOAGGREGATION");
break;

case REGDB_E_CLASSNOTREG:
::AfxMessageBox("REGDB_E_CLASSNOTREG");
break;

default:
::AfxMessageBox("Error");
}
}
else
{
::AfxMessageBox("OK");
}
}
//////////////////////////////////////////////////////////
The code always seems to get the following line..
::AfxMessageBox("REGDB_E_CLASSNOTREG");

Any ideas

Thanks

Wayne


Nov 16 '05 #6

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

Similar topics

0
by: Will Waggoner | last post by:
Ok, I've been hung up on this issue for quite some time now and I would like some help in getting it to work. I think this may be a setup issue but I'd like to ask your eminences first. Here's...
6
by: John | last post by:
MSVC6 (SP5) gives this error when I try to use a non-pointer type to a class that is forward-referenced: reo.cpp(8) : error C2027: use of undefined type 'B' However Borland's free 5.5 compiler...
3
by: Rene | last post by:
I notice that VS lets you choose to create a WindowsControlLibrary and ClassLibrary, I created a class library and then added a user control and it let me do that. I am assuming that the opposite...
7
by: A.M-SG | last post by:
Hi, We have a class library application that needs to read some application settings from it's own app.config file. I assume that a ClassLibrary.DLL can have a app.config file, but...
2
by: Poobalam | last post by:
Hi, I just got VS.NET 2005. It has a new template called WebControlLibrary. I normally use ClassLibrary to build my business logic and use that dll into ASP.NET project. However I'm assuming...
5
by: christian | last post by:
Hi! I have a problem with a template function im MSVC6 the template function is defined as: template <__Type1, __Type2> int MyFunc(int param1, double param2) {__Type1 var1; __Type2 var2; ...
7
by: Stefan | last post by:
Hi! I´m creating a classlibrary project. The output will be a dll. This dll will have to read some settings from some kind of config-file. Normally, when creating a standard .exe-program I use...
0
by: Reini | last post by:
We are developing an Asp.Net 2.0 application (Web Administration) for the IIS 5.0 to 6.0 and the W2K to W2K3 operating system. The application consists of several layers. One layer is a .Net 2.0...
0
by: Nenefta | last post by:
Here's the thing I am trying to do: I have a HTMLEditor control in a WindowsControlLibray. I want to use this control on a webpage to let users fill out text in HTML-format. It won't show. A...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.