Global variable error :error LNK2001

Dear all,

    I have defined a global variable in CTestApp like :

        class CTestApp : public CWinApp
        {
            public:
                static DWORD dwPos2;
                ......
        }

    When I recompile the project, it always turn out the error like the 
following :

    Test error LNK2001: unresolved external symbol symbol "public: static 
unsigned long CTestApp::dwPos2" (?dwPos2@CTestApp@@2KA)

        Could anybody tell me why? Any helpful ideas would be highly 
appreciated!

-ja



0
josndrsn (41)
9/22/2006 8:10:58 AM
vc.mfc 33608 articles. 0 followers. Follow

3 Replies
604 Views

Similar Articles

[PageSpeed] 53

Well, could you tell me how to define a variale in MFC project,so and I can 
use it anywhere i need ,thanks a lot! I have tried to define the global 
varible in stdafx.h file, but when I another error turned out like the 
following :

    dwPos2 was redefined in xxx.obj  or sth like that!


Could any body tell me how to avoid such exceptions during define a global 
varible,thanks a lot!


-ja

"Heinz Ozwirk" <SPAMhozwirk@arcor.de> д����Ϣ����:4513b730$0$18485$9b4e6d93@newsspool3.arcor-online.net...
> "ja" <josndrsn@yahoo.com> schrieb im Newsbeitrag 
> news:enLIp6h3GHA.600@TK2MSFTNGP05.phx.gbl...
>> Dear all,
>>
>>    I have defined a global variable in CTestApp like :
>>
>>        class CTestApp : public CWinApp
>>        {
>>            public:
>>                static DWORD dwPos2;
>>                ......
>>        }
>>
>>    When I recompile the project, it always turn out the error like the 
>> following :
>>
>>    Test error LNK2001: unresolved external symbol symbol "public: static 
>> unsigned long CTestApp::dwPos2" (?dwPos2@CTestApp@@2KA)
>>
>>        Could anybody tell me why? Any helpful ideas would be highly 
>> appreciated!
>
> You didn't "define" a global variable, at least not in the piece of code 
> you posted. You only declared a static member variable in CTestApp. And 
> like member functions, static member variables must be defined somewhere. 
> You have to add a definition for CTestApp::dwPos2 in one (and only one) of 
> your CPP files, like
>
>    DWORD CTestApp::dwPos2 = 0;
>
> HTH
>    Heinz
> 


0
josndrsn (41)
9/21/2006 3:28:52 PM
"ja" <josndrsn@yahoo.com> schrieb im Newsbeitrag 
news:enLIp6h3GHA.600@TK2MSFTNGP05.phx.gbl...
> Dear all,
>
>    I have defined a global variable in CTestApp like :
>
>        class CTestApp : public CWinApp
>        {
>            public:
>                static DWORD dwPos2;
>                ......
>        }
>
>    When I recompile the project, it always turn out the error like the 
> following :
>
>    Test error LNK2001: unresolved external symbol symbol "public: static 
> unsigned long CTestApp::dwPos2" (?dwPos2@CTestApp@@2KA)
>
>        Could anybody tell me why? Any helpful ideas would be highly 
> appreciated!

You didn't "define" a global variable, at least not in the piece of code you 
posted. You only declared a static member variable in CTestApp. And like 
member functions, static member variables must be defined somewhere. You 
have to add a definition for CTestApp::dwPos2 in one (and only one) of your 
CPP files, like

    DWORD CTestApp::dwPos2 = 0;

HTH
    Heinz 


0
9/22/2006 10:13:00 AM
This has nothing to do with MFC but rather some basics in C/C++.  If you 
want C++ approach then read up on static class members.  Heinz already 
described how to do that.  If you want C approach then declare the variable 
in one file and use 'extern' keyword in other files.

"ja" <josndrsn@yahoo.com> wrote in message 
news:uQTBRvl3GHA.4648@TK2MSFTNGP04.phx.gbl...
> Well, could you tell me how to define a variale in MFC project,so and I 
> can use it anywhere i need ,thanks a lot! I have tried to define the 
> global varible in stdafx.h file, but when I another error turned out like 
> the following :
>
>    dwPos2 was redefined in xxx.obj  or sth like that!
>
>
> Could any body tell me how to avoid such exceptions during define a global 
> varible,thanks a lot!
>
>
> -ja
>
> "Heinz Ozwirk" <SPAMhozwirk@arcor.de> 
> д����Ϣ����:4513b730$0$18485$9b4e6d93@newsspool3.arcor-online.net...
>> "ja" <josndrsn@yahoo.com> schrieb im Newsbeitrag 
>> news:enLIp6h3GHA.600@TK2MSFTNGP05.phx.gbl...
>>> Dear all,
>>>
>>>    I have defined a global variable in CTestApp like :
>>>
>>>        class CTestApp : public CWinApp
>>>        {
>>>            public:
>>>                static DWORD dwPos2;
>>>                ......
>>>        }
>>>
>>>    When I recompile the project, it always turn out the error like the 
>>> following :
>>>
>>>    Test error LNK2001: unresolved external symbol symbol "public: static 
>>> unsigned long CTestApp::dwPos2" (?dwPos2@CTestApp@@2KA)
>>>
>>>        Could anybody tell me why? Any helpful ideas would be highly 
>>> appreciated!
>>
>> You didn't "define" a global variable, at least not in the piece of code 
>> you posted. You only declared a static member variable in CTestApp. And 
>> like member functions, static member variables must be defined somewhere. 
>> You have to add a definition for CTestApp::dwPos2 in one (and only one) 
>> of your CPP files, like
>>
>>    DWORD CTestApp::dwPos2 = 0;
>>
>> HTH
>>    Heinz
>>
>
> 


0
nobody2044 (52)
9/22/2006 3:54:43 PM
Reply:

Similar Artilces:

fatal error in outlook
Since this netsky virus has been rearing its ugly head, my outlook express won't stay open. After a minute or so i receive a window which says that 'microsoft has encountered a problem and has to close now'. Also i receive a fatal error at times. My computer is virus free and yet i think i may still have a virus. Can anybody help?? Thank you, Christine This newsgroup is for support of Outlook 97, 98, 2000 & 2002 from the Office family for Windows PCs. For Outlook Express (OE) support try posting in one of these newsgroups: microsoft.public.inetexplorer.ie4.outlookexp...

"Operation cannot be performed" error
Hello, I have recently started getting an "Operation cannot be performed" error when doing various Money activities in Money 2004 Small Business. When I click on More Info, this is the message I get: "Details Product: Money ID: 34 Source: mnyob99 Version: 12.0 Symbolic Name: errUnknown Message: This operation cannot be performed. Explanation Usually caused by a corupt file. User Action Run the Money File Repair tool to fix the problem." I've run the Repair Tool, and even re-installed Money (did not uninstall it, just re-installed). Has anyone...

READ ONLY ERROR 03-15-07
Hello, Does anyone know how I can fix this.....It means that the control is set to read only (Enabled = No); that theForm is read only (Allow Edits = No); or that the subform is based ona Query which is not updateable.I have a subform on my main form and when i go to select a drop down from that subform...the read only error comes up....the information is stored, however the error still comes up????helpRW If you open the main form with Allow Edits set to No, the subform will be locked.The subform also as its own AllowEdits property.Also make sure the subform's RecordSourceType property is ...

error C2440: 'type cast' : cannot convert from 'overloaded-function' to 'LPHANDLER_FUNCTION'
I wrote a VC program for service...In VC 6 it working fine...But In Visual Studio 2005 it got errorrs... My code is give below.... void CRRMService::ServiceMain() { int error; //MEMORYSTATUS memory; int result; ServiceStatus.dwServiceType = SERVICE_WIN32; ServiceStatus.dwCurrentState = SERVICE_START_PENDING; ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN; ServiceStatus.dwWin32ExitCode = 0; ServiceStatus.dwServiceSpecificExitCode = 0; ServiceStatus.dwCheckPoint = 0; ServiceStatus.dwWaitHint ...

Inconsistency between global catalog in root and global catalog in child domains
Hi, I have a very strange problem in my AD. It seems that there is an inconsistence between global catalog in the root domain and global catalog in the child domains. Global catalog on all root domain controllers are identical. Global catalog on all child domain controllers are identical. However (at least) one orphaned object exist in the global catalog on the child DC's, but not in global catalog on the root DC's. The object is not accessible through adsiedit, ldp, etc. and thus we cannot delete it. Does anybody have a good idea on how to get this object deleted. How the inco...

Catching global keystrokes
Hello. I need my program to react to some key combination no matter if the program's window is active or not. How can this be done? Depends on the details of the key combinations as to what you have to do, precisely, but a WH_GETMESSAGE hook looking for WM_KEYDOWN, WM_SYSKEYDOWN or WM_CHAR is a start. Note if the key combination is Ctrl+Alt+Del, then it will never be possible. In Vista, you will not be able to get ALL keystrokes unless you are running as administrator. See my essay on hooks on my MVP Tips site. joe On Fri, 07 Nov 2008 09:42:52 +0300, Vladimir <thamiorsinister@...

DS_E_INSUFFICIENT_ACCESS_RIGHTS error
Hi all , I got the problem the error is DS_E_INSUFFICIENT_ACCESS_RIGHTS , due to my service admin account is unknown account now , how can i remove this account , thx Stanley I also have the same error when i try using the Exchange Administrator from a Windows XP Pro (SP2) workstation, and it seems that it happened when a domain was added that used a Windows Server 2003 DC (mixed mode), and we also have this error when modifying admin rights to the 'Adminnistrator'!!!!!!!!!! any help on this would help Jason "Stanley" wrote: > Hi all , > > I got the pr...

global rule
I have a program that tags the subject line of all emails that it thinks is spam. Instead of delivering that message to the recipient I would like to create a rule to deliver it to one large spam mailbox. Is there a way to do this? I am running exchange 2003. ...

No global address list when trying to send email through excel
In excel, you can send the spreadsheet as an attachment through emai (Outlook). When I try to do this, the global address list on th server doesn't show up, therefore the person I'm trying to send it t doesn't show up. The global address list is available because I ca save the spreadsheet and create a new email and insert it as a attachment...I would like to send the spreadsheet in an email throug excel (File, Send to, mail recipient (as attachment) because it' easier...How do I change the settings to look for the GAL on th server. There was some sort of wizard that walked ...

Error: A program is trying to access email addresses you have stored in outlook.
Getting the above error when attempting to sync with palm vx. 'Use to work' okay. Recently restored laptop (Dell) from Dell cd, windows 2000 pro, outlook 2000. Reinstalled Palm hot sync software, but now getting the above message. Choosing YES, handheld sync's okay. Complete message is: __________________________________________ A program is trying to access e-mail address you have stored in Outlook. Do you want to allow this? If this is unexpected, it may be a virus and you should choose "no". ________________________________________________________ Machine i...

error #2
i have a inhandled script exception with exception_class_script_out_of_range This would probably be better handled by logging a support case via eSupport. However, to assist you they would need to know the exact message that you were receiving and any details or more info the dialog might provide. They would also need to know what products you have installed (by providing a copy of the DYNAMICS.SET file) and exactly what are the steps to reproduce the error. David Musgrave [MSFT] Senior Development Consultant Escalation Engineer MBS Support - Asia Pacific Microsoft Business Solutions h...

Global Footer Options?
Hi there: Does anyone know if there is a global default option in Excel to ALWAY create footers with the pathname and docname for ALL worksheets? I.E. know there is the solution to create the pathname in eac footer/worksheet, but I want to set this feature as a global defaul for any worksheet I work on. Hope springs eternal : -- Message posted from http://www.ExcelForum.com Hi you can create a new template (*.xlt) file including this option. Place this in your template folder and choose this template for your new workbooks -- Regards Frank Kabel Frankfurt, Germany > Hi there: > D...

Global Function
I'm using the following code to set the Datasheet Font on a Split Form using AC 2007. Private Sub Form_Open(Cancel As Integer) Me.DatasheetFontName = "Arial" End Sub I would like to use a global function so I might call the same function from all my forms, but I haven't had much luck. I tried the following: Public Function SetDataSheetFont() Dim frm As Form Set frm = Screen.ActiveForm frm.DatasheetFontName = "Arial" End Function I get no errors but nothing happens when calling this in the OnOpen of a form. Any help will be appreciated, Ja...

Performed an Illegal Operation Error Message
I am getting this message when ever i try to open up Microsoft Outlook. I have tried repairing and even deleting and reinstalling Microsoft Office. But still no luck. The details on the Illegal operation message are: utlook caused an invalid page fault in module MSVCRT.DLL at 017f:7800707. Any suggestions Thanks Gabe I do am having similar problems. I have W98 & Outlook 2000. All of a sudden I'm having problems. I get an error message: MSVCRT.DLL at 017f:7800d6al message. I tried nfclean.exe and have reinstalled MS Office twice, Any suggestions would be appreciated. Thanks....

Error during Redeployment Wizard
Hello folks, i have a problem while using the Redeployment Wizard. I get the error message: ERROR: attempt to reuse name CN=NAWSV009,OU=Standard,OU=Server,DC=netatwork,DC=de This is what i did: Until today i used the Licence from MSDN and so i had the organisation MSDN Subscriber. Now i want to use a new Licence File and i have to use our company name. I already exported the DBs and imported them again in the new DBs as described in the Redeploying Guide. I want to use the origin Hardware. I think that the Wizard checks an Attribute or something like that. But i can't find the r...

Type mismatch error
The following statement gives an error of type mismatch in a macro ActiveSheet.Cells(j, colcount) = (data(j, i)) / 587 where array data in a variant type tried changing through CVar but failed Could anyone solve this is data(j,i) numeric? What are j, colcount, and i equal to (as well)? Gautam wrote: > > The following statement gives an error of type mismatch in a macro > ActiveSheet.Cells(j, colcount) = (data(j, i)) / 587 > > where array data in a variant type > > tried changing through CVar but failed > > Could anyone solve this -- Dave Peterson...

global object dependent on CWinApp global object
hi I have a global object which depends on the CWinApp global object i.e. it assumes that the CWinApp global object is created. After migrating to VS 2005, my global object is getting created before the CWinApp global object. Is there any way I can force the CWinApp object to be created first? I know one of the solution is to avoid a global object and wrap it in a fuction, however a lot of files use this object directly, so I am trying to figure out if there is another way. Regards Chimanrao Chimanrao wrote: > hi > > I have a global object which depends on the CWinApp global...

Email Time Out Errors
receiving this error from CRM only. Could not deliver the message in the time limit specified. Please retry or contact your administrator. <folders.com #4.4.7> Need some help please. ...

Runtime error #7
Every once in a while when I start Outlook I get an error. MS Visual C++ Runtime Library Runtime error Program ....Outlook.exe has requested the runtime to terminate it in an unusual way. I click ok and Outlook closes then I restart Outlook and it works ok. ...

MS Outlook error
When I try to open ANY attachment fromwithin Outlook (Office 2K, SP-3) I get the following error message: the system could not find the specified file outlook. I can save the file and open it from anywhere else, but just not within the app. Any help is greatly appreciated, Joey R. ...

Date formats, culture and globalization
Hi, ASP.NET 3.5 We are creating a 3-tier ASP.NET Web Application that needs just to understand dates as UK shortdate format (dd/MM/yyyy). It will only be used in the UK on intranet. I often come across web server and client machine that are incorrectly set up so I want to protect the app from these incorrectly set up hosts. I understand the safe date formats for passing through to the database. SQLParameters pass through a non-ambiguous format and also that 'yyyyMMdd' is also a safe format. So ignore the database side of things - I get that. At the moment all the bou...

prf question and global address list....
When i fire off my Oulook 2003 and manually create my profile to connect to our exchange server i get to see my GAL and my outlook address book with my contacts folder when i go to create a new message and click TO: to look at my contacts. When i start outlook 2003 using my PRF file it auto creates the profile and connects me to the server but for some reason i can only see my GAL and not my outlook address book or contacts when creating a new message. I have found this line in my PRF file under MSMail DisplayGalOnly=PT_BOOLEAN,0x6625 Im not sure if this is related but the docs say ...

VBA Function
Hello- I am somewhat of a nb so forgive my ignorance. I have developed some code that utilizes a function. The code works (i.e. the query loads), but is throwing an error. Here is the error message: "Error in procedure cmdRunQuery_Click...Error 0:" The code looks like this (this is only snippet of the code): If TypeName = "pt_query" Then results = PT(FilesName, 100) End If Here is the function: Function PT(q As String, n As Integer): On Error GoTo ProcError Dim db As DAO.Database Dim qdf As DAO.QueryDef Set db = CurrentDb() Set qdf = db.QueryDefs("1-1_de...

retrun blank if error
I am trying to create a dual entry system, a1=b1, and b1=a1; if I enter a value in either a1 or b1 it is copied to the other. Can I program both to return a blank with the circular ref error. This returns 0 not blank:for a1 =if(iserror(b1),"",b1) and for b1 =if(iserror(a1),"",a1) I am confused.........easily done<g> How do you enter a value in a cell that contains a formula? Gord Dibben MS Excel MVP On Thu, 22 Nov 2007 12:11:18 -0800 (PST), chegel <chegel@gmail.com> wrote: >I am trying to create a dual entry system, a1=b1, and b1=a1; if I >ent...

Using Custom button to add variable item code
I need to use custom button to add item code to transaction screen but my Item code not always same Item, it can change Itemlookupcode depend on condition including Price or Quantity so that I cannot use Internal command 'PerformAddItem' , I write dll to use qsrules but it's not working , my code like these: Public Function Process(session as Qsrules.Sessionclass) as Boolean dim Entry as TransactionEntry Entry = Session.Transaction.Entries.Add(1,"11200",1,False,1,,,False) Entry.SetPrice(300) end function ****It's not working including c...