Undefined object reference for an object instance when calling dll class

Asked

Viewed 45 times

-1

I am trying to call a function of a class that is in a DLL. But the error "Undefined object reference to an instance of an object" is showing, I don’t understand why because the IDE shows no error.

What am I doing wrong?

Follows code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Threading;
using System.Runtime.InteropServices;

namespace player
{
    public partial class frmPrincipal : Form
    {

        System.Media.SoundPlayer soundPlayer;
        RSPOggPlayer279a.RSPOggPlayClass playerRSP;

        public frmPrincipal()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void tocar()
        {

            playerRSP.UseEncryption(true, "988d90fsdhfnu943yrtherjh0qw9rifj");
            //playerRSP.PlayFile("C:\Users\kleber.santos\7b.ogg");





            //byte[] buffer = File.ReadAllBytes(@"C:\Users\kleber.santos\Downloads\africa-toto.wav");
            //System.IO.File.Delete(@"C:\Users\kleber.santos\Downloads\africa-toto.wav");
            //var memoryStream = new MemoryStream(buffer, true);
            //soundPlayer = new System.Media.SoundPlayer(memoryStream);
            //Play();
        }

        public void Play()
        {
            soundPlayer.Play();
        }

        private void BtnPlay_Click(object sender, EventArgs e)
        {
            tocar();
        }

        private void BtnVolume_Click(object sender, EventArgs e)
        {

        }
    }
}
  • It is some object that forgot to instantiate, in which line the error occurs?

  • in line 36 -> playerRSP.Useencryption(true, "988d90fsdhfnu943yrtherjh0qw9rifj");, in debug it says that playerRSP is null.

1 answer

0

Kleber, This message is typical for non instantiated objects. Checks the instance of the Rspoggplayer279a.RSPOggPlayClassobject. I believe it’s a class created by you.

  • is a class of an OCX, when I try to instantiate from that "Rspoggplayclass" does not contain a constructor that accepts 0 arguments. I’m doing like this: playerRSP = new Rspoggplayer279a.Rspoggplayclass(); playerRSP.Useencryption(true, "988d90fsdhfnu943yrtherjh0qw9rifj");

  • Checks if you do not have other constructs, with parameters, or a Getinstance method()

  • It has other functions but also do not answer, it does not have me Getinstance(), because the OCX is old 2005. In VB 5 is just call that way ai and it works.

  • These are different paradigms. I usually type, in this case Rspoggplayclass, parentheses, comma within the parentheses and click up and down arrow

Browser other questions tagged

You are not signed in. Login or sign up in order to post.