473,399 Members | 2,478 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,399 software developers and data experts.

webservice ASP.net (c++) using unmanaged c++: Link problem

Post a new message to microsoft.public.dotnet.languages.vc
http://www.dotnet247.com/247reference/default.aspx


Hello,

I've been struggling for weeks with this problem, I hope I find some help here...

To start, in our company, we have a large existing c++ project (native code, unmanaged c++)

The objective is to write a webservice for some of the functionalities from this project.
The best way to do this in Visual Studio .NET 2003 seems to me by creating an ASP.NET Web service in c++.
I create the default template, wich works just fine.
Now I want to use some unmanaged c++ code, so I write a managed wrapperclass and delegate the old routines from identical methods. When I test this with an unmanaged c++ class in the same project, this works fine.
But when I include an header from the old project, and call some old routines, I get link problems for every implemented routine.

e.g.:
error LNK2001: unresolved external symbol "public: __thiscall test::~test(void)" (??1test@@$$FQAE@XZ)
error LNK2001: unresolved external symbol "public: char * __thiscall test::function(int,int)" (?function@test@@$$FQAEPADHH@Z)
...

I've read http://msdn.microsoft.com/library/de...ingProblem.asp concerning mixed dll problems, and figured out this could be my problem, and tried the solution at :
http://support.microsoft.com/?id=814472
But here rises another problem for me, none of the given solutions seems applicable to my particular problem,

I don't think my DLL isn't entered using DLL exports (__declspec(dllexport)),
not it seems to be a COM-based DLL.
and "Consumers of your DLL can use managed code, and your DLL contains either DLL exports or managed entry points." doesnt work for my project neither...

So I'm pretty stuck...

I need some help, if you wish you can simulate my problem:

just create a default ASP.NET webservice : called e.g. Webservice

add managedwrapper.h :

#pragma once

#include "test.h"

#pragma managed

__gc class ManagedWrapperClass{
private:
test * t;
public:
ManagedWrapperClass() {t = new test;}
~ManagedWrapperClass() {delete t;}
const char* function() {return t->function();}
};

in webserviceclass.cpp, include "managedwrapper.h" and rewrite the helloworld routine :
String* webserviceClass::HelloWorld()
{
ManagedWrapperClass *m = new ManagedWrapperClass();
return m->function();
}
and now create a console application (.NET) (c++) e.g. testconsole

add a file test.h :

class test{
public:
test() {}
~test() {}
char* function() {return "Wow you did it...";}
};
in webservice -> project settings -> c/c++ -> General -> Additional include Directories : add ../testconsole

I want to thank everyone who tries to help me with this one!
I've just started working and after 3 years of studying in VC6.0.. .NET and webservices are pretty new...

Thanks in Advance,


Kristof Thys

--------------------------------
From: Kristof Thys

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>KN8AQgEHLkeVPYRAvinIKg==</Id>
Nov 17 '05 #1
7 1713
Kristof Thys via .NET 247 wrote:
I need some help, if you wish you can simulate my problem:


Unfortunately, following your steps doesn't result in any errors for me. ..

--
Ben
http://bschwehn.de
Nov 17 '05 #2
On Mon, 20 Sep 2004 00:34:26 -0700, Kristof Thys via .NET 247
<an*******@dotnet247.com> wrote:
I managed to resolve a part of the above problem, by including msvcrt.lib
to the webservice, (properties->linker->input->additional dependencies)
but the same problem arises when I create a test.cpp in the testconsole,
where I place the body of the function:

test.cpp :

#include "test.h"
char* test::function()
{
return "Wow you really did it...";
}

webservice error LNK2001: unresolved external symbol "public: char *
__thiscall test::function(void)" (?function@test@@$$FQAEPADXZ)

(just as I need to do with the original project...)
--
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 17 '05 #3
I dit the test myself and you are right :S

But when I try to put a test.cpp in the testconsole, with the body of my
function :

////test.cpp

#include "stdafx.h"
#include "test.h"
char* test::function()
{
return "Wow you did it...";
}

I get the same errors I got all week...

thx for the effort!

On Mon, 20 Sep 2004 12:40:22 +0200, Ben Schwehn <b.*******@gmx.net> wrote:
Kristof Thys via .NET 247 wrote:
I need some help, if you wish you can simulate my problem:


Unfortunately, following your steps doesn't result in any errors for me.
..


--
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 17 '05 #4
Kristof wrote:
But when I try to put a test.cpp in the testconsole, with the body of
my function : [...] I get the same errors I got all week...


well, that's not surprising. in the webservice, you're including the
class definition (in test.h) but don't provide a class implementation.

this has nothing to do with mixing managed/unmanaged code.
Same as doing:

#include "stdafx.h"

class NoBody {
public:
static void Foo();
};
int _tmain(int argc, _TCHAR* argv[])
{
NoBody::Foo();
}

-> LNK2001
--
Ben
http://bschwehn.de
Nov 17 '05 #5
That's true,
when I include test.cpp, this simple program works fine.

But this way I keep encountering this link problems:

Suppose in test.cpp I change the function:

#include "testclass2.h"

char* function()
{
testclass2 t = new testclass2;
return t->function2();
}

In the testconsole project, this works perfectly.

But when I call test->function from the webservice, the compiler says
testclass2::function2 is unresolved.

Why isn't it unresolved when I build testconsole?

What is the solution to this problem? It can't be the issue to include all
cpp files (testclass2.cpp in this case), that way,
the list of includes would be giant and I will get lots of errors this
way...
Thx for the help!

On Mon, 20 Sep 2004 13:31:28 +0200, Ben Schwehn <b.*******@gmx.net> wrote:
Kristof wrote:
But when I try to put a test.cpp in the testconsole, with the body of
my function :

[...]
I get the same errors I got all week...


well, that's not surprising. in the webservice, you're including the
class definition (in test.h) but don't provide a class implementation.

this has nothing to do with mixing managed/unmanaged code.
Same as doing:

#include "stdafx.h"

class NoBody {
public:
static void Foo();
};
int _tmain(int argc, _TCHAR* argv[])
{
NoBody::Foo();
}

-> LNK2001


--
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 17 '05 #6
> But this way I keep encountering this link problems:

Suppose in test.cpp I change the function:

#include "testclass2.h"

char* function()
{
testclass2 t = new testclass2;
return t->function2();
}

In the testconsole project, this works perfectly.

But when I call test->function from the webservice, the compiler says
testclass2::function2 is unresolved.

Why isn't it unresolved when I build testconsole?
because it's a different project and probably you have testerclass2.cpp
included in this project -> class testerclass2 gets compiled and linked.
in the webservice you only have the class definition (by including the
header) but not the class implementation.

What is the solution to this problem? It can't be the issue to include
all cpp files (testclass2.cpp in this case), that way,
the list of includes would be giant and I will get lots of errors this
way...


if you want to use classes that are defined in other projects/dlls/libs
you'll have to use any of the standard ways of doing this. eg create a
lib file and staticlly link to it, statically link to an dll or
dynamicly load a dll at runtime, use com, the .net stuff, whatever.

You'll find plenty of info on that via a websearch.

This is really what you're (perhaps unknowingly) doing all the time
already: For example, say you want to use the windows socket function
"WSASend": what you do is
1. include the appropiate header (Winsock2.h) and
2. link to the appropiate library (Ws2_32.lib)
If you don't do 1., you'll get compile time errors (function is not
declared), if you don't do 2. you'll get link time errors (function not
implemented)

Hope this makes things a bit clearer.
--
Ben
http://bschwehn.de
Nov 17 '05 #7
Ben Schwehn wrote:
But this way I keep encountering this link problems:

Suppose in test.cpp I change the function:

#include "testclass2.h"

char* function()
{
testclass2 t = new testclass2;
return t->function2();
}

In the testconsole project, this works perfectly.

But when I call test->function from the webservice, the compiler says
testclass2::function2 is unresolved.

Why isn't it unresolved when I build testconsole?

because it's a different project and probably you have testerclass2.cpp
included in this project -> class testerclass2 gets compiled and linked.
in the webservice you only have the class definition (by including the
header) but not the class implementation.

What is the solution to this problem? It can't be the issue to include
all cpp files (testclass2.cpp in this case), that way,
the list of includes would be giant and I will get lots of errors
this way...

if you want to use classes that are defined in other projects/dlls/libs
you'll have to use any of the standard ways of doing this. eg create a
lib file and staticlly link to it, statically link to an dll or
dynamicly load a dll at runtime, use com, the .net stuff, whatever.

You'll find plenty of info on that via a websearch.

This is really what you're (perhaps unknowingly) doing all the time
already: For example, say you want to use the windows socket function
"WSASend": what you do is
1. include the appropiate header (Winsock2.h) and
2. link to the appropiate library (Ws2_32.lib)
If you don't do 1., you'll get compile time errors (function is not
declared), if you don't do 2. you'll get link time errors (function not
implemented)

Hope this makes things a bit clearer.

Thanks very much,
this does clear things up! :)
Nov 17 '05 #8

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

Similar topics

0
by: Russ | last post by:
I'm trying to use InteropServices in a web service, by following the examples and info in the article "Consuming Unmanaged DLL Functions" in the .NET Framework Developer's Guide. I am able to...
47
by: Bonj | last post by:
I downloaded the gzlib library from zlib in order to do compression. (http://www.gzip.org/zlib) The prototype of the compression function seems to be int compress (Bytef *dest, uLongf *destLen,...
3
by: mirek | last post by:
Hi, I've got problem building managed class library to wrap unmanaged code. I created managed class library using standard patten: #include "../Unmanaged/Class1.h" //Class1 unmanaged ...
0
by: Kristof Thys via .NET 247 | last post by:
Hello, I've been struggling for weeks with this problem, I hope I find some help here... To start, in our company, we have a large existing c++ project (native code, unmanaged c++) The...
0
by: Kristof Thys | last post by:
Hello, I am writing a webservice for some older c++ classes. I build these unmanaged classes as a dll, and in my webservice I add a reference to this dll. I include the necessary headerfiles,...
3
by: cipher | last post by:
I'm trying to use an MFC extension dll in my C++ ASP.NET Web Service project. I have changed my project settings to specify using MFC as a shared dll. However, when I try to compile, I get the...
0
by: Adam M. Rosenzweig | last post by:
Hello, I am having a problem getting a particular web service to work on a win 2003 server. This web service does work on my XP box. The web service is written in VB.NET, and uses a declare...
1
by: =?Utf-8?B?YXVzdGlyb2I=?= | last post by:
Hi, Any help with this problem would be greatly apprecicated as it is driving me insane. I have an ASP.NET 2.0 Webservice running on Windows server 2003. The
5
by: Jonathan Kay | last post by:
Hi, I'd like to my WCF webservice to work both on SSL and without. Unfortunately searching has led to dead ends, references to changes that only work on the old previous beta versions and I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.