• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 454
  • Last Modified:

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??
0
mte01
Asked:
mte01
  • 6
  • 5
1 Solution
 
AlexFMCommented:
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.
0
 
mte01Author Commented:
>>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)
0
 
AlexFMCommented:
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?
0
Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

 
AlexFMCommented:
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.
0
 
mte01Author Commented:
>>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
0
 
AlexFMCommented:
What type of C++ .NET project? LNK2020 is shown in managed projects. Form1 is also typical name of managed project.
If you want to build existing project in .NET, open C++ 6.0 .dsw is VS 2005 directly and build it - this is all. If you build new managed application, you must build all UI stuff in .NET and call from it existing SDK functions.
0
 
mte01Author Commented:
>>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)??
0
 
AlexFMCommented:
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.
0
 
mte01Author Commented:
>>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)
0
 
AlexFMCommented:
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.
0
 
mte01Author Commented:
>>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...
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now