System.Xml.Schema in VC++ 6.0

  • Thread starter Thread starter Maansi Sanghi
  • Start date Start date
M

Maansi Sanghi

Hi,

Is there a way to use the System.Xml.Schema classes in VC++ 6.0?

Regards,
Maansi
 
Maansi Sanghi said:
Is there a way to use the System.Xml.Schema classes in VC++ 6.0?

VC++ 6.0 is only capable of generating unmanaged Win32 executables and DLLs.
The classes of the .Net platform are available only in managed code. So, the
short answer is no.

Alternatively, you can download the Visual C++ toolkit which contains the
same compiler and linker as in Visual Studio 2003 available here:

http://msdn.microsoft.com/visualc/vctoolkit2003/

and create a managed class to use the whole of the framework, XML included.

The least attractive option on a system in which the .Net platform is
installed would have you develop an unmanaged native Win32 executable with
VC++ 6.0 to host the Common Language Runtime (CLR) and use the COM
interfaces that the .Net framework provides start the CLR, get access to the
default domain, load an assembly into that domain, create and instance of a
managed type (i.e. a .Net class) and call a method of that class to perform
whatever XML related task you need. That begs the question as to how you
would create the managed class. For that, you could use the command line C#
compiler that comes with the .Net SDK.

Regards,
Will
 
The catch in the solution is that the XML functionality is required for an
existing large application
already developed using unmanaged code.

(1) An managed class cannot be declared in the unmanaged classes of my
application.
Both the alternatives suggest creating a managed class.

(2) I have .Net licence for very few machines and rest of the developers
ahave licence
for 6.0 ..even so i do not want to shift to .NET that is do not want to
compile the whole
application with the option of Managed Code as ON.

(3) This is the solution i was thinking of.



1. Create .NET DLL use regasm for creating Use the
COM object
using managed class ----> a COM object from -----> from the
unmanaged code
System.Xml.Schema .NET dll
of legacy application.


(4) I am not sure if this solution would work. Have not been able to develop
a proof of concept as yet
for the above approach.

Regards,
Maansi
 
Maansi Sanghi said:
The catch in the solution is that the XML functionality is required for an
existing large application
already developed using unmanaged code.

(1) An managed class cannot be declared in the unmanaged classes of my
application.
Both the alternatives suggest creating a managed class.

(2) I have .Net licence for very few machines and rest of the developers
ahave licence
for 6.0 ..even so i do not want to shift to .NET that is do not want to
compile the whole
application with the option of Managed Code as ON.

(3) This is the solution i was thinking of.

I took your question to mean that you _only_ had VC++ 6.00 as a development
tool and wanted to get some interoperability without the upgrade in
development tool. So, I sketched your options in the free tools world.

Just by the way, what I sketched does not involve declaring managed classes
in unmanaged code as in #1.

Yes, you certainly can treat a .Net assembly as a COM component in maanged
code. In the book "Essential Guide to Managed Extensions for C++ (Apress)
Challa and Laksberg offer a few options.

I'm a little busy now, but if no one provides some snippets you can use a
proof of concept, I'll post them here later tonight.

Regards,
Will
 
Maansi Sanghi said:
(3) This is the solution i was thinking of.



1. Create .NET DLL use regasm for creating Use
the
COM object
using managed class ----> a COM object from -----> from the
unmanaged code
System.Xml.Schema .NET dll
of legacy application.


(4) I am not sure if this solution would work. Have not been able to
develop
a proof of concept as yet for the above approach.

I am happy to report that it works as doc'd. :-)

With VS.Net 2003 I created this toy class in C#

using System;
using System.Runtime.InteropServices;

namespace ClassLibrary1
{
[ClassInterface(ClassInterfaceType.AutoDual)]
public class Class1
{
public Class1()
{
}

public void SayHello()
{
Console.WriteLine("C# says hello!");
}
}
}

Note that if your class doesn't have a dual interface you'll need to talk to
it via IDispatch. Yuck!

Then I registered the assembly and created a type library from it with the
command

regasm /tlb:ClassLibrary1Lib.tlb ClassLibrary1.dll

With VC++ 6.0 I created this toy application which used the compiler's
import facility to read the type library and create the wrapper.

#include <windows.h>
#import "mscorlib.tlb" raw_interfaces_only

using namespace mscorlib;
#import "ClassLibrary1Lib.tlb"
using namespace ClassLibrary1;

int main()
{
CoInitialize(0);

_Class1Ptr class1(__uuidof(Class1));

class1->SayHello();

CoUninitialize();
return 0;
}

I put the C# assembly in the same directory as the executable and ran it. C#
speaks.

Regards,
Will
 
Thanks Will,

I hope this example of yours will be a help.
Actually I was looking into the example in VB given here to create a client
in VC++
http://www.15seconds.com/Issue/010214.htm?voteresult=3

Kept getting a class not registered inspite of using regasm and checking the
registry.
I hope this one works. Seems straightforward. Will send a post once
successful.

Regards,
Maansi




William DePalo said:
Maansi Sanghi said:
(3) This is the solution i was thinking of.



1. Create .NET DLL use regasm for creating Use
the
COM object
using managed class ----> a COM object from -----> from the
unmanaged code
System.Xml.Schema .NET dll
of legacy application.


(4) I am not sure if this solution would work. Have not been able to
develop
a proof of concept as yet for the above approach.

I am happy to report that it works as doc'd. :-)

With VS.Net 2003 I created this toy class in C#

using System;
using System.Runtime.InteropServices;

namespace ClassLibrary1
{
[ClassInterface(ClassInterfaceType.AutoDual)]
public class Class1
{
public Class1()
{
}

public void SayHello()
{
Console.WriteLine("C# says hello!");
}
}
}

Note that if your class doesn't have a dual interface you'll need to talk to
it via IDispatch. Yuck!

Then I registered the assembly and created a type library from it with the
command

regasm /tlb:ClassLibrary1Lib.tlb ClassLibrary1.dll

With VC++ 6.0 I created this toy application which used the compiler's
import facility to read the type library and create the wrapper.

#include <windows.h>
#import "mscorlib.tlb" raw_interfaces_only

using namespace mscorlib;
#import "ClassLibrary1Lib.tlb"
using namespace ClassLibrary1;

int main()
{
CoInitialize(0);

_Class1Ptr class1(__uuidof(Class1));

class1->SayHello();

CoUninitialize();
return 0;
}

I put the C# assembly in the same directory as the executable and ran it. C#
speaks.

Regards,
Will
 
Maansi Sanghi said:
Thanks Will,

You are welcome.
I hope this example of yours will be a help.

Me too.
Actually I was looking into the example in VB

I just can't ever bring myself to do any flavor of basic however far removed
from Dartmouth ... :-)
Kept getting a class not registered inspite of using regasm
and checking the registry.

Did you put the managed assembly in the same directory as your unmanaged
executable?

Regards,
Will
 
From: "William DePalo [MVP VC++]" <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.vc
Sent: Thursday, March 03, 2005 10:45 PM
Subject: Re: System.Xml.Schema in VC++ 6.0
Did you put the managed assembly in the same directory as your unmanaged
executable?

No I have created a Lib folder and kept both libraries to be imported over
there
that is
mscorlib.tlb and MyXSDWriter.tlb and then compiled. I still get a class not
registered error.

Some of the archives mention that you need to give the assembly a string
name.
Looking into the sn.exe tools right now.

Regards,
Maansi
 
Maansi Sanghi said:
No I have created a Lib folder and kept both libraries to be imported over
there that is mscorlib.tlb and MyXSDWriter.tlb and then compiled.

If you put the managed assembly in the same directory as the unmanaged
executable then you will be pleased with the results. :-)
I still get a class not registered error.
Yup.

Some of the archives mention that you need to give the assembly a string
name.

Well, it doesn't hurt but it is _not_ required. I didn't do that in my
little test.

Regards,
Will
 
Some of the archives mention that you need to give the assembly a string
Well, it doesn't hurt but it is _not_ required. I didn't do that in my
little test.

Regards,
Will


Thanks Will! I have been able to create the prototype. :)
Will go ahead with my application now. For that i will have to be able
to use the assembly from anywhere.

Its a big relief! :)

Thanks n Regards,
Maansi
 
I tried your example but it did not work until I used "/codebase" like this:

C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\regasm
C:\work\learn\ClassLibrary1\ClassLibrary1\bin\Debug\ClassLibrary1.dll
/tlb:C:\work\learn\CallDotNetDLL\ClassLibrary1Lib.tlb /codebase
file:///C:\work\learn\ClassLibrary1\ClassLibrary1\bin\Debug\ClassLibrary1.dll

C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\regasm
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\mscorlib.dll
/tlb:C:\work\learn\CallDotNetDLL\mscorlib.tlb /codebase
file:///C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\mscorlib.dll



William DePalo said:
Maansi Sanghi said:
(3) This is the solution i was thinking of.



1. Create .NET DLL use regasm for creating Use
the
COM object
using managed class ----> a COM object from -----> from the
unmanaged code
System.Xml.Schema .NET dll
of legacy application.


(4) I am not sure if this solution would work. Have not been able to
develop
a proof of concept as yet for the above approach.

I am happy to report that it works as doc'd. :-)

With VS.Net 2003 I created this toy class in C#

using System;
using System.Runtime.InteropServices;

namespace ClassLibrary1
{
[ClassInterface(ClassInterfaceType.AutoDual)]
public class Class1
{
public Class1()
{
}

public void SayHello()
{
Console.WriteLine("C# says hello!");
}
}
}

Note that if your class doesn't have a dual interface you'll need to talk to
it via IDispatch. Yuck!

Then I registered the assembly and created a type library from it with the
command

regasm /tlb:ClassLibrary1Lib.tlb ClassLibrary1.dll

With VC++ 6.0 I created this toy application which used the compiler's
import facility to read the type library and create the wrapper.

#include <windows.h>
#import "mscorlib.tlb" raw_interfaces_only

using namespace mscorlib;
#import "ClassLibrary1Lib.tlb"
using namespace ClassLibrary1;

int main()
{
CoInitialize(0);

_Class1Ptr class1(__uuidof(Class1));

class1->SayHello();

CoUninitialize();
return 0;
}

I put the C# assembly in the same directory as the executable and ran it. C#
speaks.

Regards,
Will
 
SS said:
I tried your example but it did not work until I used "/codebase" like
this:

Without specifying that switch does it work if you put the assembly in the
same directory as the executable?

Regards,
Will
 
Back
Top