Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6693285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:57:55+00:00 2026-05-26T05:57:55+00:00

I’ve been looking for ways of solving this problem for quite some time now.

  • 0

I’ve been looking for ways of solving this problem for quite some time now. What I have is a standard Form1.h with some global variables declared in it. I want to access the properties of this form from a function in a separate .cpp file. So here is how I try to accomplish this:

//Form1.h

#pragma once

#include "stdafx.h"
#include "test.h"


unsigned char vMAC1;
unsigned char vMAC2;
unsigned char vMAC3;
unsigned char vMAC4;
unsigned char vMAC5;
unsigned char vMAC6;


extern long pNum;

//ARP Variables

unsigned char gMAC1;
unsigned char gMAC2;
unsigned char gMAC3;
unsigned char gMAC4;
unsigned char gMAC5;
unsigned char gMAC6;

extern unsigned char mMAC1;
extern unsigned char mMAC2;
extern unsigned char mMAC3;
extern unsigned char mMAC4;
extern unsigned char mMAC5;
extern unsigned char mMAC6;

namespace Artemis_v {
    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;
    using namespace System::Runtime::InteropServices;
    using namespace System::Threading;
    using System::IntPtr;
    /// <summary>
    /// Summary for Form1
    /// </summary>

    public ref class Form1 : public System::Windows::Forms::Form
    {
    public:
        Form1(void)
        {
            InitializeComponent();
            //
            //TODO: Add the constructor code here
            //
        }

    protected:
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        ~Form1()
        {
            if (components)
            {
                delete components;
            }
        }

    protected: 

    ///// And so on just standard compiler-created statements..

    private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
        ChangeText(this);
    }


// test.h

#ifndef TEST_H
#define TEST_H

namespace Artemis_v
{
    ref class Form1;
    void ChangeText(Form1 ^frm);
}

#endif


// test.cpp

#include "StdAfx.h"
#include "test.h"
#include "Form1.h"

namespace Artemis_v
{
    void ChangeFormText(Form1 ^frm)
    {
        frm->Text="Hello!";
    }
}

This code gives me LNK2005 Already defined errors and I know it’s because of my variables being redeclared when I include Form1.h in test.cpp. Can I find any workarounds to this problem or should I remove the variables?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:57:55+00:00Added an answer on May 26, 2026 at 5:57 am

    One of your .cpp files should declare the variables without “extern” and your .h file should declare them with “extern”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have some data like this: 1 2 3 4 5 9 2 6
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.