Google Groupes n'accepte plus les nouveaux posts ni abonnements Usenet. Les contenus de l'historique resteront visibles.

System.Xml.Schema in VC++ 6.0

20 vues
Accéder directement au premier message non lu

Maansi Sanghi

non lue,
2 mars 2005, 00:23:3802/03/2005
à
Hi,

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

Regards,
Maansi


William DePalo [MVP VC++]

non lue,
2 mars 2005, 01:16:2602/03/2005
à
"Maansi Sanghi" <maansi...@abosoftware.com> wrote in message
news:uW$FchuHF...@TK2MSFTNGP10.phx.gbl...

> 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

non lue,
2 mars 2005, 06:19:4702/03/2005
à
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


"William DePalo [MVP VC++]" <willd....@mvps.org> wrote in message
news:uFPwe9uH...@TK2MSFTNGP10.phx.gbl...

William DePalo [MVP VC++]

non lue,
2 mars 2005, 08:59:3002/03/2005
à
"Maansi Sanghi" <maansi...@abosoftware.com> wrote in message
news:ulst9ox...@TK2MSFTNGP14.phx.gbl...

> 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


William DePalo [MVP VC++]

non lue,
2 mars 2005, 21:01:5502/03/2005
à
"Maansi Sanghi" <maansi...@abosoftware.com> wrote in message
news:ulst9ox...@TK2MSFTNGP14.phx.gbl...

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

non lue,
3 mars 2005, 02:32:0603/03/2005
à
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 [MVP VC++]" <willd....@mvps.org> wrote in message

news:ORJA7T5H...@TK2MSFTNGP09.phx.gbl...

William DePalo [MVP VC++]

non lue,
3 mars 2005, 12:15:3603/03/2005
à
"Maansi Sanghi" <maansi...@abosoftware.com> wrote in message
news:eQIX5N8...@TK2MSFTNGP15.phx.gbl...
> 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

non lue,
6 mars 2005, 23:29:2406/03/2005
à
From: "William DePalo [MVP VC++]" <willd....@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++]

non lue,
6 mars 2005, 23:49:1106/03/2005
à
"Maansi Sanghi" <maansi...@abosoftware.com> wrote in message
news:u1r2f6sI...@TK2MSFTNGP10.phx.gbl...

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

non lue,
7 mars 2005, 09:09:4707/03/2005
à
> > 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


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


Le message a été supprimé

William DePalo [MVP VC++]

non lue,
15 mars 2005, 19:33:0415/03/2005
à
"SS" <s...@iwon.comdontspam> wrote in message
news:7F3A4755-23E3-4672...@microsoft.com...
>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

non lue,
16 mars 2005, 09:41:0216/03/2005
à
Yes, I had both TLB files in the same directory as the VC++ 6.0 EXE.
0 nouveau message