CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2014
    Location
    Austin, TX
    Posts
    9

    declaring member variables in a windows form app

    Hi All,

    You'll have to excuse me because I'm coming from a more traditional C/C++ background (like a WIN32 project with a standard WndProc), and I've just started learning about Windows Forms. I have created a windows form project in visual studio so that I can use a windows form to interact with the game class that I'm creating, but I'm running into some problems.

    For one thing, I would like to be able to call Image::FromFile() one time only during initialization, and store the result in a member variable (called mBGImage). From what I can tell, the variable needs to be of type String^ (this caret symbol is new to me, but I understand it is the "managed code" version of the standard pointer, which would look like String*). When I try to compile the following code (located in my header file) I get the error "error C3265: cannot declare a managed 'mBGImage' in an unmanaged 'BSG::BSGame'".

    What am I doing wrong and how can I store the result of Image::FromFile() permanently in my class?

    Oh, and also, when I try to declare a global variable of type "Image^", I get "error C3145: global or static variable may not have managed type System:rawing::Image ^"

    ----------------------------

    #include "stdafx.h"

    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System:ata;
    using namespace System:rawing;

    namespace BSG
    {
    const Point kGridSize(400, 400); //size of grid (width, height)
    const Point kGridTiles(10, 10); //total number of tiles (x,y)

    public class BSGame
    {
    public:
    BSGame(void); //constructor
    ~BSGame(void); //destructor

    void Init(void); //Initialize the game
    void DrawScreen(Graphics^ gfxObj, Rectangle rect);

    private:
    bool mInited; //is this object initialized?
    Image^ mBGImage;
    };
    }

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: declaring member variables in a windows form app

    This is c++/cli - or managed c++ - which is different to c++, so you should post your question on the managed c++ forum here http://forums.codeguru.com/forumdisp...ed-C-and-C-CLI
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  3. #3
    Join Date
    Sep 2014
    Location
    Austin, TX
    Posts
    9

    Re: declaring member variables in a windows form app

    thanks - I'd really just like to be using "regular" C++ instead...done

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured