Link to home
Start Free TrialLog in
Avatar of mte01
mte01Flag for Lebanon

asked on

Unresolved token appname_mutex

Hey experts,

 I am using a C++ Win32 code in the Visual C++.NET environment; I was able to resolve all portability issues except for the following:
error LNK2020: unresolved token (0A00008A) appname_mutex

I am defining it as follows: extern HANDLE cname_mutex;

any help on how to solve the problem??
Avatar of AlexFM
AlexFM

extern HANDLE cname_mutex;

This line means: cname_mutex is variable of HANDLE type which is created somewhere else. You need to create this variable without extern keyword:
HANDLE cname_mutex;

Usually extern declaration is placed to h-file and actual variable is created in one source file.
Avatar of mte01

ASKER

>>AlexFM

Yes, this is done in a header file (assuming cname_mutex is defined internally somewhere); and the code works fine on Visual C++ 6.0 (it's a cnaiapi open source code)

I tried
HANDLE cname_mutex

but it gave the following error:

error LNK2005: "void * cname_mutex" (?cname_mutex@@3PAXA) already defined in Form1.obj

I searched through the whole project, and I didn't find anywhere where cname_mutex is defined other than this (I found places where it was used)
Is cname_mutex your own variable or it belongs to some third-party SDK? Right-click on this variable, select "References" and post here results.
BTW, according to this message, you are building managed C++ application. This is not exact copy of previous project compiled in VC++ 6.0. Is this your intention?
BTW, when you get LNK2005 error, where exactly do you add this variable? Notice that Form Designer places all code to form h-file, but this is still h-file - global variables should not be declared here.
Avatar of mte01

ASKER

>>AlexFM

Let me tell you what I am doing.....I have VC++ 6.0 project, I took its source & header files and added them manually to a clean C++ .NET project, and I tried to compile it (after removing unneeded stuff), and I got that error.

This variable is declared in a seperate header file (from the original code).....btw I am declaring global variables in a .cpp file
ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mte01

ASKER

>>AlexFM

Yes, that did the trick..(opening the .dsw file in VS 2005)...thanks for your help!!

One last thing...how can I convert the project to a manged project, so that I can add a Form (with a few buttons)??
Project - Settings - Configuration Properties - General - Common Language Runtime Support. Select /clr option.
This changes application type from native to CLR. Now you can use CLR types like String, create them using gcnew operator and use all resources available in .NET library.
But .NET UI Framework is not compatible with other UI Frameworks like MFC, WTL or Win32 API application. Every UI Framework type has it's own requirements for building application. For example, Win32 API application must have WinMain function and message loop, Console application must have main function, MFC application must have CWinApp object. .NET UI application must jave Application::Run call with Form or ApplicationContext reference. What is the type of existing application? What changes do you want to do in it? Answer depends on this information.
Avatar of mte01

ASKER

>>AlexFM

It's a console application. After converting it in VS 2005, I just want to add to it a single .net form (with a few buttons)
I suggest you to create new .NET Windows Forms application, make required form in designer, and then move part of existing code to this new application. You don't need main function because it belongs to Console type. But other functions which are called from main function, can be called from form buttons message handlers.
Avatar of mte01

ASKER

>>AlexFM

That's what I did in the beginning, and got the error message which made me open this question...:)
Anyway...I think I can handle it now better, now that I have a better understanding of how the problem is going...