Thread: Help with Class Library .NET and Classes :0

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Master At Novice
    Join Date
    Oct 2005
    Location
    Cardassia & Canada, eh!
    Posts
    31

    Post Help with Class Library .NET and Classes :0

    Hey there, just wondering if anyone could tell me where I can go to learn about using classes in external files (how to link them) and if anyone has a link to download a sample Windows Forms project using dll's (nothing specific, just a basic idea of how it all works together).

    thanks,

    Rob

    ------> Below added November 27th

    Ok, here's what I'm playing around with:

    <<This is a VC++ Windows Forms .NET project>>

    My CMainDLL.cpp reads:

    Code:
    // This is the main DLL file.
    #include "stdafx.h"
    #include "CMainDLL.h"
    And my CMainDLL.h reads:

    Code:
    // CMainDLL.h
    
    #pragma once
    
    using namespace System;
    
    namespace CMainDLL
    {
    	public __gc class Class1
    	{
    		// TODO: Add your methods for this class here.
    	public:
    		double trouble;
    		double dare;
    	};
    }
    I'm just seeing if I can use (for now until I get better at it) these stupid little things:

    Form1.h reads:

    Code:
    #pragma once
    #using "CMainDLL.dll"
    namespace CMain
    {
    	
    	//using CMainDLL::Class1;
    	using namespace System;
    	using namespace System::ComponentModel;
    	using namespace System::Collections;
    	using namespace System::Windows::Forms;
    	using namespace System::Data;
    	using namespace System::Drawing;
    
    	/// <summary> 
    	/// Summary for Form1
    	///
    	/// WARNING: If you change the name of this class, you will need to change the 
    	///          'Resource File Name' property for the managed resource compiler tool 
    	///          associated with all .resx files this class depends on.  Otherwise,
    	///          the designers will not be able to interact properly with localized
    	///          resources associated with this form.
    	/// </summary>
    public __gc class Form1 : public System::Windows::Forms::Form
    	{	
    	public:
    		Form1(void)
    		{
    			InitializeComponent();
    		}
      
    	protected:
    		void Dispose(Boolean disposing)
    		{
    			if (disposing && components)
    			{
    				components->Dispose();
    			}
    			__super::Dispose(disposing);
    		}
    	private: System::Windows::Forms::Button *  button1;
    
    	private:
    		/// <summary>
    		/// Required designer variable.
    		/// </summary>
    		System::ComponentModel::Container * components;
    
    		/// <summary>
    		/// Required method for Designer support - do not modify
    		/// the contents of this method with the code editor.
    		/// </summary>
    		void InitializeComponent(void)
    		{
    			this->button1 = new System::Windows::Forms::Button();
    			this->SuspendLayout();
    			// 
    			// button1
    			// 
    			this->button1->Location = System::Drawing::Point(112, 216);
    			this->button1->Name = S"button1";
    			this->button1->TabIndex = 0;
    			this->button1->Text = S"button1";
    			this->button1->Click += new System::EventHandler(this, button1_Click);
    			// 
    			// Form1
    			// 
    			this->AutoScaleBaseSize = System::Drawing::Size(5, 13);
    			this->ClientSize = System::Drawing::Size(292, 266);
    			this->Controls->Add(this->button1);
    			this->Name = S"Form1";
    			this->Text = S"Form1";
    			this->ResumeLayout(false);
    
    		}	
    
    
    	private: System::Void button1_Click(System::Object *  sender, System::EventArgs *  e)
    			 {	
    //
    //Something like this, obviously it's not finished, just an example:
    //
    				 CMainDLL::Class1 Rob;
    				 Rob.dare = 23.3;
    
    			 }
    
    	};
    }
    and Form1.cpp reads:
    Code:
    #include "stdafx.h"
    #include "Form1.h"
    #include <windows.h>
    
    using namespace CMain;
    
    int APIENTRY _tWinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPTSTR    lpCmdLine,
                         int       nCmdShow)
    {
    	System::Threading::Thread::CurrentThread->ApartmentState = System::Threading::ApartmentState::STA;
    	Application::Run(new Form1());
    	return 0;
    }
    When I compile my error reads:
    error C2262: 'Rob': cannot be destroyed.

    Seems like a lot of code to go through above...

    Sure would be nice to be able to use the same code over and over instead of having to re-write it every time I add a new .cpp!

    Is there a link somewhere that can teach me how to do this?

    Thanks,

    Rob Sitter.
    Last edited by Robert_Sitter; 11-27-2005 at 10:54 AM. Reason: Not very specific

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ Library Design
    By CornedBee in forum C++ Programming
    Replies: 2
    Last Post: 09-30-2004, 10:40 AM
  2. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-23-2004, 11:22 PM
  3. Prime Number Generator... Help !?!!
    By Halo in forum C++ Programming
    Replies: 9
    Last Post: 10-20-2003, 07:26 PM
  4. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 03:49 AM
  5. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM