VC6 <-> C#(net 2.0) interaction

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi there.

We maintain a big VC6 project that we currently can´t convert to VS2005 for
various reasons. For our current project we need to establish a communication
channel between this VC6 project and another project that is running on
VS2005 C# and NET 2.0.

All our efforts so far were unsuccessful. Especially triggering events from
C++ to NET doesn´t work. We would be very thankfull for a set of sample
projects that actually interact VC6 <-> C#. Any help would be very
appreciated!

Thanks a lot!
 
Hi Elmar!
We maintain a big VC6 project that we currently can´t convert to VS2005 for
various reasons. For our current project we need to establish a communication
channel between this VC6 project and another project that is running on
VS2005 C# and NET 2.0.

All our efforts so far were unsuccessful. Especially triggering events from
C++ to NET doesn´t work. We would be very thankfull for a set of sample
projects that actually interact VC6 <-> C#. Any help would be very
appreciated!

What is this VC6 project??? DLL/LIB/EXE/(In/Out)COM-Server ?

Greetings
Jochen
 
We maintain a big VC6 project that we currently can´t convert to VS2005
for
various reasons. For our current project we need to establish a
communication
channel between this VC6 project and another project that is running on
VS2005 C# and NET 2.0.

All our efforts so far were unsuccessful. Especially triggering events
from
C++ to NET doesn´t work. We would be very thankfull for a set of sample
projects that actually interact VC6 <-> C#. Any help would be very
appreciated!

There are 2 ways:

1)build a plain C style DLL that communicates with your C++ app in whatever
way you see fit, and then consume that DLL in your .NET app.
..NET 2.0 has facilities for converting delegates to C style function
pointers so with some decent plumbing code, your should be able to make it
work.

2)build a .NET class library that communicates with your .NET app, and
register is for COM interop. then consume that COM class in your C++
application to work with the .NET application.

either way should work without too many problems.
 
Can we discuss this a little bit more?
Assuming I have a simple test class library with one class:

------
using System;
using System.Collections.Generic;
using System.Text;

namespace vc6interop
{
public class Interop
{
public static string GreetMe(string name)
{
return "Hallo " + name;
}
}
}
------

....that is compiled with "expose as COM" flag turned on.
What do I have to do in order to call this method in C++?

I found some code that would fit this sample but it gives me a lot of errors.

------
GreetMe function;
CString result;

HINSTANCE hinstLib = LoadLibrary("vc6interop.dll");

if (hinstLib) {

function = (GreetMe) GetProcAddress(hinstLib, "GreetMe");


if (function)
result = (function) ("John");


BOOL fFreeResult = FreeLibrary(hinstLib);
}

// Das Ergebnis anzeigen
if (!hinstLib || !function)
printf("Error\n");
else
printf("Result: %s\n", result);
 
Elmar said:
Can we discuss this a little bit more?
Assuming I have a simple test class library with one class:

------
using System;
using System.Collections.Generic;
using System.Text;

namespace vc6interop
{
public class Interop
{
public static string GreetMe(string name)
{
return "Hallo " + name;
}
}
}
------

...that is compiled with "expose as COM" flag turned on.
What do I have to do in order to call this method in C++?

I found some code that would fit this sample but it gives me a lot of
errors.
Don't know what that means.

CString result;

HINSTANCE hinstLib = LoadLibrary("vc6interop.dll");
Nope, only .NET framework can load a .NET assembly.

if (hinstLib) {

function = (GreetMe) GetProcAddress(hinstLib, "GreetMe");
Nope, .NET code doesn't have an address until the JIT compiles it.

Instead, you must use CoInitialize to enable COM support in your
application, and CoCreateObject to create an instance of a .NET class. Then
you will be able to call the methods.
 
Back
Top