Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / March 2005

Tip: Looking for answers? Try searching our database.

System.Xml.Schema in VC++ 6.0

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Maansi Sanghi - 02 Mar 2005 05:23 GMT
Hi,

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

Regards,
Maansi
William DePalo [MVP VC++] - 02 Mar 2005 06:16 GMT
> 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
Maansi Sanghi - 02 Mar 2005 11:19 GMT
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

> > Is there a way to use the System.Xml.Schema classes in VC++   6.0?
>
[quoted text clipped - 21 lines]
> Regards,
> Will
William DePalo [MVP VC++] - 02 Mar 2005 13:59 GMT
> The catch in the solution is that the XML functionality is required for an
> existing large application
[quoted text clipped - 11 lines]
>
> (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
William DePalo [MVP VC++] - 03 Mar 2005 02:01 GMT
> (3) This is the solution i was thinking of.
>
[quoted text clipped - 9 lines]
> 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 - 03 Mar 2005 07:32 GMT
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

> > (3) This is the solution i was thinking of.
> >
[quoted text clipped - 68 lines]
> Regards,
> Will
William DePalo [MVP VC++] - 03 Mar 2005 17:15 GMT
> 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
Maansi Sanghi - 07 Mar 2005 04:29 GMT
From: "William DePalo [MVP VC++]" <willd.no.spam@mvps.org>
Newsgroups: microsoft.public.dotnet.languages.vc
Sent: Thursday, March 03, 2005 10:45 PM
Subject: Re: System.Xml.Schema in VC++ 6.0

> > 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?

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
William DePalo [MVP VC++] - 07 Mar 2005 04:49 GMT
>> 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.

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
Maansi Sanghi - 07 Mar 2005 14:09 GMT
> > Some of the archives mention that you need to give the assembly a string
> > name.
[quoted text clipped - 4 lines]
> 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
SS - 15 Mar 2005 22:49 GMT
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

> > (3) This is the solution i was thinking of.
> >
[quoted text clipped - 68 lines]
> Regards,
> Will
William DePalo [MVP VC++] - 16 Mar 2005 01:33 GMT
>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
SS - 16 Mar 2005 15:41 GMT
Yes, I had both TLB files in the same directory as the VC++ 6.0 EXE.

> >I tried your example but it did not work until I used "/codebase" like
> >this:
[quoted text clipped - 4 lines]
> Regards,
> Will

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.