473,563 Members | 2,856 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem linking managed DLL to native DLL

I have the following situation:

There are two dlls in question: a c++ dll (native) and a c++/cli dll
(managed) with /clr option enabled.

Managed dll links with native dll.

Native dll exports a class ClientSession with a method GetJob.

Managed dll references this method and compiles just fine.

Managed dll does NOT link however and gives this error:

error LNK2028: unresolved token (0A000168) "public: class
Rimage::Simple: :Api::Job * __thiscall
Rimage::Simple: :Api::ClientSes sion::GetJobW(w char_t const *)"
(?GetJobW@Clien tSession@Api@Si mple@Rimage@@$$ FQAEPAVJob@234@ PB_W@Z)
referenced in function "public: class Rimage::Simple: :Dotnet::Api::J ob ^
__clrcall Rimage::Simple: :Dotnet::Api::C lientSession::G etJobW(class
System::String ^)"
(?GetJobW@Clien tSession@Api@Do tnet@Simple@Rim age@@$$FQ$AAMP$ AAVJob@2345@P$A AVString@System @@@Z)

Notice that the linker is complaining about GetJobW, NOT GetJob.

When I right click on GetJob and select "Go to Definition" it takes me to
winspool.h where the following block exists:

#ifdef UNICODE
#define GetJob GetJobW
#else
#define GetJob GetJobA
#endif // !UNICODE

Just for kicks I deleted this block and all of a sudden the linker worked!

BTW, when I link a native application (exe) with the same native dll and
call GetJob on my class it compiles and links just fine. So it seems to have
something to do with the fact that I am linking a managed dll with a native
dll.

Any help would be greatly appreciated

Thanks, Dave


Jun 29 '06 #1
2 2149
"Dave Burns" <db********@aol .com> wrote in message
news:OB******** *****@TK2MSFTNG P04.phx.gbl...
I have the following situation:
When I right click on GetJob and select "Go to Definition" it takes me to
winspool.h where the following block exists:

#ifdef UNICODE
#define GetJob GetJobW
#else
#define GetJob GetJobA
#endif // !UNICODE

Just for kicks I deleted this block and all of a sudden the linker worked!


That's a drastic solution. :-)

Immediately after including the Windows header files try adding an

#undef GetJob

line.

In case you don't know, to support both ASCII and UNICODE projects,
virtually all of the functions of the Windows API on NT/2K/XP/2K+3/Vista
that use strings come in two versions. In one version the name of the
function ends in A and takes or returns ANSI characters. The other ends in W
and is for UNICODE.

Macro trickery is used to hide the fact that there are two ostensibly
identical functions with the same name. That trickery, and the fact that one
of your member functions has the same name is biting you.

Regards,
Will
Jun 29 '06 #2
> Native dll exports a class ClientSession with a method GetJob.

Managed dll references this method and compiles just fine.

Managed dll does NOT link however and gives this error:

error LNK2028: unresolved token (0A000168) "public: class
Rimage::Simple: :Api::Job * __thiscall
Rimage::Simple: :Api::ClientSes sion::GetJobW(w char_t const *)"
(?GetJobW@Clien tSession@Api@Si mple@Rimage@@$$ FQAEPAVJob@234@ PB_W@Z)
referenced in function "public: class Rimage::Simple: :Dotnet::Api::J ob ^
__clrcall Rimage::Simple: :Dotnet::Api::C lientSession::G etJobW(class
System::String ^)"
(?GetJobW@Clien tSession@Api@Do tnet@Simple@Rim age@@$$FQ$AAMP$ AAVJob@2345@P$A AVString@System @@@Z)

Notice that the linker is complaining about GetJobW, NOT GetJob.

When I right click on GetJob and select "Go to Definition" it takes me to
winspool.h where the following block exists:

#ifdef UNICODE
#define GetJob GetJobW
#else
#define GetJob GetJobA
#endif // !UNICODE

Just for kicks I deleted this block and all of a sudden the linker worked!

BTW, when I link a native application (exe) with the same native dll and
call GetJob on my class it compiles and links just fine. So it seems to have
something to do with the fact that I am linking a managed dll with a native
dll.


I have had the same problem before with other function names.
basically, the problem is that GetJob is a macro like most win32 functions.

during preprocessing, the preprocessor will bluntly replace all instances of
'GetJob' with another
function name, depending on whether your build is for unicode or ascii.

if you wouldn't include windows.h somewhere, you would not have this problem.
this has nothing to do with managed or unmanaged.

there are 3 workarounds that I know of.
- use a different method name instead of GetJob
- bluntly #undef GetJob in the header file of your unmanaged class.
this could have the side effect for anyone using your header that they have
to explicitly use GetJobW or GetJobA because the GetJob macro is not
working anymore.
- everywhere you call GetJob, use pragma push_macro, undef and pragma
pop_macro to locally
change the meaning of GetJob. this is tedious, and all users of the GetJob
function have to do it.

maybe there is a smarter workaround, but I just used a different name and
moved on.

--

Kind regards,
Bruno.
br************* *********@hotma il.com
Remove only "_nos_pam"
Jun 29 '06 #3

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

Similar topics

2
7566
by: Jacob Cohen | last post by:
Under VC7.1, I am trying to wrap a native-C++ DLL that contains C++ objects in a Managed-C++ class library for use in a C# project. I created and compiled the native DLL under VC7.1 as a Win32 DLL C++ (unmanaged) project. I found the decorated names of the symbols I wanted to export and created a .def file, so that it generated an import...
0
1056
by: Drew | last post by:
I am attempting to clean up some code by breaking a large mixed-mode Managed C++ library into two. I cannot get the darn thing to compile or link (depending on what I do). I have two libraries (projects). One called "core" and the other called "server". If I use #include's (not using references in VS 2003) from the "server"
0
767
by: Wildspirit | last post by:
I have simple problem, i have written program in pure C++ and builded a library. Now i wanna connect program which is wrotten in Managed C++(GUI) with native code. And my cl compiler is crashing down when it starts linking. It not return a error. I don't know where is the problem. -- Przemek Biernat ( "Kicek", "Wildspirit" ),...
9
2058
by: Herby | last post by:
Is possible to have a managed method within a Native(un-managed) class within a \clr project? E.g. class myClass { public: #pragma managed void myMethod(void);
4
1720
by: quortex | last post by:
Hey all, I have been working on a project which consists of Native C++ code and managed C# code. In order for the managed C# code to be able to access the native layer I wrap some objects using Managed C++ Mixed Mode. I also unit test the Native C++ code using Managed C++ using the VSTS test tools. Everything works fine apart from one...
3
2761
by: Mali Guven | last post by:
Hello, I have a native DLL (written in C) which is supposed to call a managed DLL (was written in C#, and an entry point was injected modifying the ildasm'd code). The exectuable calls the native DLL but the native DLL fails to load the managed DLL. The paper that addresses the 'mixed DLL problem' below does not offer any understandable...
6
2687
by: John | last post by:
I have 5 native static libraries that are being compiled in Visual Studio 2005 with the /MDd C Runtime option. I have 2 CLR DLLs (all managed code) in Visual Studio 2005 and the /MDd C Runtime setting. They are in the same solution, and compile/link without problems (Debug configuration). I also have 1 mixed-mode CLR DLL that consumes both...
1
1365
by: Scott McFadden | last post by:
I have a managed C++ DLL (VC8) that I would like to statically link with MFC (it consumes both native and managed resources). What project settings must i specify to produce a managed C++ DLL that is statically linked with MFC? Is this even possible? thanks ScottM
11
2325
by: =?Utf-8?B?aWduaGVucnk=?= | last post by:
I have a managed C++ project and two C# projects. All are class library projects. The C++ project links with native C++ static libraries and references to one C# project. The projects structure goes something like this. Proj2_MCPP --(references)--Proj1_CSharp Proj3_CSharp --(references)--Proj2_MCPP and Proj1_CSharp My objective is to link...
0
7665
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
1
7642
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6255
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1200
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.