473,325 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Integrating with legacy code

Hello. I have a very large business application written all in VC++
and MFC. Now I want to interface some of it to the web. I have
VS.NET2003 and have been studing walkthroughs and documentation and
trying some things. I wanted to build an XML web service that would
interface to my existing data and classes. But most of the examples
are for C#, which I do not know, and which can not understand the C++
header files needed to interface to my existing libraries.

But I did find the walkthrough called "Creating an XML Web Service
Using Managed Extensions for C++", and built it. It worked fine and I
made a couple of mods to test returning strings, etc. Finally, I
figured, now all I have to do is add my C++ header files and link with
the C++ DLL's for my system.

WRONG! The dang application can not even recognize such basic types
as WORD and UINT, never mind CString, CPtrList, etc etc etc. When I
try to include the necessary windows headers to make it recognize
those things it no longer will compile or link, and if I add what it
takes to make it link, then it won't run. (This is without calling a
single function in my old DLL.)

So I decided I had to start from scratch and rewrite everything doing
it the .NET way. I started by creating a single class and putting two
variables in it, a bool and a CString. No problem with the bool, but
it chokes on the CString. After some study, I tried including
cstringt.h. No good, the compiler does not even recognize CString as
a valid type. Next I tried including atlstr.h. It now says "warning
C4935: assembly access specifier modified from 'public'", and "error
C2872: 'IServiceProvider' : ambiguous symbol".

Next I studied some more and discovered the String class for managed
C++. AHA says I, that is what I need.

NOPE! Now it says "cannot declare a managed 'm_Fname' in an unmanaged
'CTestClass'".

If I can't even get a simple string class to work, how the heck am I
going to get collection classes and all my polymorphic classes etc, to
work!!!

It looks like .NET is only good if you are writing everything over
again from scratch. That is a hell of a huge learning curve and a
huge project even if I knew how. I thought .NET was supposed to make
it possible for all platforms and all operating systems to communicate
- easily. What am I missing, PLEASE!

Russ

PS: If you think it sounds like I am frustrated, you are right.

Jul 21 '05 #1
8 1977
Hi Russ,

Currently I am looking for somebody who could help you on it. We will reply
here with more information as soon as possible.
If you have any more concerns on it, please feel free to post here.
Thanks for your understanding!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------

Jul 21 '05 #2
Hi,

Thanks for your post. I reviewed your description carefully, and now I'd
like to share the following information with you:

1. To use CString class in your .NET managed C++ applicaiton, please
include atlstr.h header file and see if it works:
#include <atlstr.h>

2. Concerning the error message "cannot declare a managed 'm_Fname' in an
unmanaged 'CTestClass'", there is a workaround which uses the gcroot
template class. Note the use of vcclr.h required for the gcroot template
class. Please refer to the following article for detailed information and
sample:

__gc Pointers in Unmanaged Classes
http://msdn.microsoft.com/library/de...us/vcmxspec/ht
ml/vcManagedExtensionsSpec_16_3.asp

In addition, I'd like to recommend you an article below:

Converting Managed Extensions for C++ Projects from Pure Intermediate
Language to Mixed Mode
http://msdn.microsoft.com/library/de...us/vcmex/html/
vcconconvertingmanagedextensionsforcprojectsfrompu reintermediatelanguagetomi
xedmode.asp

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Jul 21 '05 #3
Min Hyang, thank you for your answer. However your answer focused on
just one small part of my problems. Just making the CString class
work is a minor part of the overall picture. Please try to understand
the bigger picture that I am asking about and address it in your
response.

That bigger picture is the whole issue of making legacy code work with
a .NET application. Fixing CString just leads to a host of additional
but similar problems. For instance, your fix of including atlstr.h I
had already tried. It compiles but then gives a lot of link errors
for common routines like memmove. Including the CRT library in the
project produces:
error LNK2020: unresolved token (0A00003C) _CrtDbgReport
But since it compiles ok, I thought I would try adding something else
that I need, CPtrLists. That causes a new round of problems. And so
it will go. Below is an example class that I will need to include in
order to make my legacy code interface to a .NET application:

class DllExport CPrinterOptionList : public CObList {
public:
DECLARE_SERIAL (CPrinterOptionList)

CPrinterOptionList () {}
CPrinterOptionList (const CPrinterOptionList& in) { *this = in; }
~CPrinterOptionList () { RemoveAll (); }

void RemoveAll (bool bDelete = true);

CPrinterOption *GetNext (POSITION &pos) const
{ return (CPrinterOption*) CObList::GetNext (pos); }

CPrinterOption *GetAt (POSITION &pos)
{ return (CPrinterOption*) CObList::GetAt (pos); }

CPrinterOption *GetHead ()
{ return (CPrinterOption*) CObList::GetHead (); }

void Delete (CPrinterOption* p);

const CPrinterOptionList& operator= (const CPrinterOptionList
&in);
bool operator== (const CPrinterOptionList& in) const;
bool operator!= (const CPrinterOptionList& in) const
{ return ! (*this == in); }
};

I don't expect this to be anything strange to you, but this is a very
small example of the kind of header file that will have to be included
in my application. How to do it?

To review. I have a large business app for which I have built up
custom libraries to access the data (which is not SQL data and not
available through ADO or OBDC, etc. in any way). I need to build
internet access to this data in the way of the .NET methods that
dynamically create web pages when a customer connects and requests
certain operations.

My approach was to be via the method described in the walkthrough
entitled "Creating an XML Web Service Using Managed Extensions for
C++".

How can I accomplish this? Where is the reference or article that
will allow me to get started in this direction?

Thank you! Russ

On Mon, 10 May 2004 05:50:16 GMT, ti******@online.microsoft.com (Tian
Min Huang) wrote:
Hi,

Thanks for your post. I reviewed your description carefully, and now I'd
like to share the following information with you:

1. To use CString class in your .NET managed C++ applicaiton, please
include atlstr.h header file and see if it works:
#include <atlstr.h>

2. Concerning the error message "cannot declare a managed 'm_Fname' in an
unmanaged 'CTestClass'", there is a workaround which uses the gcroot
template class. Note the use of vcclr.h required for the gcroot template
class. Please refer to the following article for detailed information and
sample:

__gc Pointers in Unmanaged Classes
http://msdn.microsoft.com/library/de...us/vcmxspec/ht
ml/vcManagedExtensionsSpec_16_3.asp

In addition, I'd like to recommend you an article below:

Converting Managed Extensions for C++ Projects from Pure Intermediate
Language to Mixed Mode
http://msdn.microsoft.com/library/de...us/vcmex/html/
vcconconvertingmanagedextensionsforcprojectsfromp ureintermediatelanguagetomi
xedmode.asp

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


Jul 21 '05 #4
Hello Russ,

Thanks for your response. I now share the following information with you:

1. I created a C++ managed project which includes atlstr.h, and then it
works properly with CString variables (both compile and execute).

2. When we use unmanaged code in C++ .NET application, we should include
corresponding header and library files. As in this case, I suggest that you
can keep your unmanaged C++ project and perform the following two steps in
order to add managed code to it:

step 1: Add the following code:
#using <mscorlib.dll>

If you are using VS .NET 2003, you can simple add reference to mscorlib.dll
in your project.

step 2: compile with /clr:

a. Open the project's Property Pages dialog box.
b. Click the Configuration Properties folder.
c. Click the General property page.
d. Modify the Use Managed Extensions property.

3. If the problem persists, could you post a simple project which is able
to reproduce the problem?

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Jul 21 '05 #5
Ok Tian, if I understand you, you are saying that I can build some
managed code into my unmanaged DLL project and then access it from a
managed web server??? How does that work?

Meanwhile I found some information that helps and finally got my test
web service to compile. But there are problems.

First let me tell you what I have done.

Following the instructions in the article "Converting Managed
Extensions for C++ Projects from Pure Intermediate Language to Mixed
Mode", I changed my project settings as follows:

1. Link with /NOENTRY (was already set that way)
2. Removed nochkclr.obj as a linker input
3. Added msvcrt.lib as a linker input
4. Added __DllMainCRTStartup@12 to the Force Symbol References.

Also in stdafx.h, added includes for afx.h, afxwin.h, afxext.h,
afxdtctl.h, and afxcmn.h.

These changes allow me to compile and link and use such constructs as
CObject and CPtrList if they are created and used in the same test
project. But a strange thing happens. Every time I build the project
it indicates zero warnings and zero errors, but when I try to run the
project it tells me that the project is out of date and needs to be
rebuilt. If I build it again, it links only, but still tells me it is
out of date when I run it from VC++ (Ctrl + F5). In fact I can build
the project over and over and it relinks every time. This does not
happen when I change the project settings back to the original.

I cleaned/rebuilt, and then checked the date/time stamp of every item
in the debug folder and they were all the same (current time). I
waited until the next minute and hit "build solution" and the project
relinked.

However when I ignore the out of date warning and execute the program,
it works and all changes made in the last build are implemented
properly, so I have proceeded to try other things.

Once I had accomplished the above, I started to add code to use my MFC
Extention DLL. I had to make another change to the project settings,
changing the Configuration properties to "Use MFC in a Shared DLL".

This now works!!! I can create instances of classes in my library and
access them from within the web service, and display the results via
web methods.

I have now run smack into some security issues that I have not been
able to figure out, but I will start a new thread if/when I need help
with that.

But I would like some input from you about the "project out of date"
issue. That is very inconvenient and will cause problems when I get
ready to add projects like this to source control.

Thank you very much for your help. In the future if anyone else asks
about this issue, you could save some time by referring them to the
article "Converting Managed Extensions for C++ Projects from Pure
Intermediate Language to Mixed Mode".

Thanks again, Russ

On Fri, 14 May 2004 11:29:11 GMT, ti******@online.microsoft.com (Tian
Min Huang) wrote:
Hello Russ,

Thanks for your response. I now share the following information with you:

1. I created a C++ managed project which includes atlstr.h, and then it
works properly with CString variables (both compile and execute).

2. When we use unmanaged code in C++ .NET application, we should include
corresponding header and library files. As in this case, I suggest that you
can keep your unmanaged C++ project and perform the following two steps in
order to add managed code to it:

step 1: Add the following code:
#using <mscorlib.dll>

If you are using VS .NET 2003, you can simple add reference to mscorlib.dll
in your project.

step 2: compile with /clr:

a. Open the project's Property Pages dialog box.
b. Click the Configuration Properties folder.
c. Click the General property page.
d. Modify the Use Managed Extensions property.

3. If the problem persists, could you post a simple project which is able
to reproduce the problem?

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


Jul 21 '05 #6
Hi Russ,

Thanks for your response.
if I understand you, you are saying that I can build some managed code

into my unmanaged DLL project and then access it from a managed web
server??? How does that work?

As stated in my previous email, you can add reference to mscorlib.dll and
compile with /clr to build a mixed-mode assembly. I suggest that you can
create a Managed C++ XML Web Service, and then combine it to the mixed-mode
assembly.

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Jul 21 '05 #7
Adding #include <atlstr.h> to a C++.NET managed class library appears to cause linking errors on /MTd.

What am I doing wrong?

Thank you,

"Tian Min Huang" wrote:
Hi Russ,

Thanks for your response.
if I understand you, you are saying that I can build some managed code

into my unmanaged DLL project and then access it from a managed web
server??? How does that work?

As stated in my previous email, you can add reference to mscorlib.dll and
compile with /clr to build a mixed-mode assembly. I suggest that you can
create a Managed C++ XML Web Service, and then combine it to the mixed-mode
assembly.

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Jul 21 '05 #8
FYI... I found a solution

#ifdef _DEBUG
#pragma comment(lib,"msvcrtd.lib")
#else
#pragma comment(lib,"msvcrt.lib")
#endif

in the stdafx.h file... =)

"Spnbld" wrote:
Adding #include <atlstr.h> to a C++.NET managed class library appears to cause linking errors on /MTd.

What am I doing wrong?

Thank you,

"Tian Min Huang" wrote:
Hi Russ,

Thanks for your response.
> if I understand you, you are saying that I can build some managed code

into my unmanaged DLL project and then access it from a managed web
server??? How does that work?

As stated in my previous email, you can add reference to mscorlib.dll and
compile with /clr to build a mixed-mode assembly. I suggest that you can
create a Managed C++ XML Web Service, and then combine it to the mixed-mode
assembly.

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Jul 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ben Sizer | last post by:
I know the conventional wisdom is to write the whole app in Python and only extend with C++ where speed is an issue, but I already have a large C++ app that I'd like to add Python to. Ideally I'd...
4
by: JellBell | last post by:
I dont know what is a legacy system..please help me out Posted Via Usenet.com Premium Usenet Newsgroup Services ---------------------------------------------------------- ** SPEED ** RETENTION...
3
by: masood.iqbal | last post by:
In this day and age, you never say no to any work that is thrown at you ---- so when I was offered this short-term contract to convert legacy C code to C++, I did not say no. Personally I believed...
3
by: Sai Kit Tong | last post by:
I posted for help on legacy code interface 2 days ago. Probably I didn't make it clear in my original mail. I got a couple of answers but none of them address my issues directly (See attached...
2
by: John Stockton | last post by:
Ok, I have a funky situation here. The client has an existing windows application that they want exposed via their c# asp.Net application. The windows app is not .Net based and we do not have the...
8
by: Russ | last post by:
Hello. I have a very large business application written all in VC++ and MFC. Now I want to interface some of it to the web. I have VS.NET2003 and have been studing walkthroughs and documentation...
4
by: Jason Madison | last post by:
I would like to create a .net application that still uses a few screens from an old legacy application we have. I can list records from the database in my .net app, but when it comes to making...
3
by: unexpected | last post by:
Hi all, I'm currently working on a large, legacy Fortran application. I would like to start new development in Python (as it is mainly I/O related). In order to do so, however, the whole project...
2
by: akshalika | last post by:
Can some one assist me what are the limitation of BizTalk Server when Integrating legacy System Like AS/400 ? Someone help really appreciates
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.