M
Maansi Sanghi
Hi,
Is there a way to use the System.Xml.Schema classes in VC++ 6.0?
Regards,
Maansi
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?
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.
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.
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,
I hope this example of yours will be a help.
Actually I was looking into the example in VB
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?
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.
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
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: