object reference not set to an instance of object (skype4com dll) RRS feed

  • Question

  • Hi

    Hope this is in the right place.

    I have recently started to play around with a Skype api, skype4com. Anyway there example code compiles fine, but it's for a console app.

    I works fine. Now the problem comes in when I tried to port it to a mfc app. I succsesfully imported the dll and set up namespace etc. It even builds fine, but when I run the app I get: "object reference not set to an instance of object" . It refers me to line 111 which is "Skype->Attach(6,true);" When I remove that line and compile it works perfect. No error.

    #include "objbase.h"
    #pragma once
    namespace skypeimo {
    	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 SKYPE4COMLib;
    	/// <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 ref class Form1 : public System::Windows::Forms::Form
    			//TODO: Add the constructor code here
    		/// <summary>
    		/// Clean up any resources being used.
    		/// </summary>
    			if (components)
    				delete components;
    	private: System::Windows::Forms::RichTextBox^ richTextBox1;
    	private: SKYPE4COMLib::ISkype^ Skype; //I think I made a mistake somewhere here.
    	private: SKYPE4COMLib::IClient^ client;
    	private: System::Windows::Forms::Button^ button1;
    		/// <summary>
    		/// Required designer variable.
    		/// </summary>
    		System::ComponentModel::Container ^components;
    #pragma region Windows Form Designer generated code
    		/// <summary>
    		/// Required method for Designer support - do not modify
    		/// the contents of this method with the code editor.
    		/// </summary>
    		void InitializeComponent(void)
    			this->richTextBox1 = (gcnew System::Windows::Forms::RichTextBox());
    			this->button1 = (gcnew System::Windows::Forms::Button());
    			// richTextBox1
    			this->richTextBox1->Location = System::Drawing::Point(57, 51);
    			this->richTextBox1->Name = L"richTextBox1";
    			this->richTextBox1->Size = System::Drawing::Size(174, 96);
    			this->richTextBox1->TabIndex = 0;
    			this->richTextBox1->Text = L"";
    			// button1
    			this->button1->Location = System::Drawing::Point(57, 180);
    			this->button1->Name = L"button1";
    			this->button1->Size = System::Drawing::Size(75, 23);
    			this->button1->TabIndex = 1;
    			this->button1->Text = L"button1";
    			this->button1->UseVisualStyleBackColor = true;
    			this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
    			// Form1
    			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
    			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    			this->ClientSize = System::Drawing::Size(292, 266);
    			this->Name = L"Form1";
    			this->Text = L"Form1";
    			this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
    #pragma endregion
    	private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
    	private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {

    Monday, May 3, 2010 6:40 PM

All replies

  •  Now the problem comes in when I tried to port it to a mfc app.

    That is not an MFC project. You have created a .NET WinForms application. I think you chose the wrong project template (or else you didn't want an MFC project after all).

    Correct me if I'm wrong.


    Monday, May 3, 2010 6:46 PM
  • Then it's my fault. Forgive me I'm still learning all these things. Basically I just want a app that generate a form and this seems to be it.  So then I didn't want a MFC project. 
    Monday, May 3, 2010 6:53 PM
  • This question belongs to the Windows Forms forum.

    Anyway, you dereferenced a null pointer. Generally you need to create an object and assign to the pointer before you dereference the pointer.

    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful.
    Visual C++ MVP
    Monday, May 3, 2010 7:12 PM