Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.1
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 4th, 2004, 03:32 AM
Authorized User
 
Join Date: Mar 2004
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default Object reference not set ... of an object

I'm trying to create a VB wrapper for an exported DLL function. I believe I've set
up everything correctly, but I keep getting this error:

Server Error in '/' Application.
--------------------------------------------------------------------------------

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web
request. Please review the stack trace for more information about the error and where it
originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance
of an object.


My VB code for the compiled wrapper. For my purposes, test.dll has an exported
function called MyGetString that takes a pointer to a structure:


Imports System.Runtime.InteropServices

< StructLayout( LayoutKind.Sequential, CharSet := CharSet.Ansi )> _
Public Structure MYSTRUCT
   Public StrIn As System.String
   Public StrOut As System.String
End Structure

Public Class LibWrapper
   Declare Function MyGetString Lib "test.dll" _
   ( <[In], Out> ByVal InOutParams As MYSTRUCT ) As Integer
End Class


VBC Compiler:
vbc.exe /t:library /r:System.dll test.vb /out:test.dll


My VB script:

 Dim P as MYSTRUCT
 Dim Obj as LibWrapper

 P = new MYSTRUCT
 P.StrIn = "Test"

 Obj = new LibWrapper
 Obj.MyGetString(P)


The error is flagged on this line:
>>Obj.MyGetString(P)


Doesn't the new operator create an instance to an object? If so, why
isn't this working?


 
Old April 4th, 2004, 11:04 PM
Authorized User
 
Join Date: Mar 2004
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, I got rid of visual basic and aspx, and wrote it as a C# program.

And I'm getting the same error message!
"Object reference not set to an instance of an object."

What the heck is this error??


My source:

using System;
using System.Runtime.InteropServices;
using System.Text;

public class TestClass {

       [DllImport("test.dll")]
       public static extern void MyGetString(string s1, ref string s2);

       [STAThread]
       public static void Main(string[] args) {

          string s1 = "teststring1";
          string s2 = "teststring2";

          try {
             MyGetString( s1, ref s2 );

             Console.WriteLine(" s1: {0}", s1 );
             Console.WriteLine(" s2: {0}", s2 );
          }
          catch (Exception e) {
             Console.WriteLine("Exception Message: " + e.Message );
          }
      }
}


My compiler:
csc.exe /reference:System.dll /out:test.exe test.cs



 
Old April 5th, 2004, 03:00 AM
Authorized User
 
Join Date: Mar 2004
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Got it working! Woohoo!


 
Old May 3rd, 2004, 08:36 AM
Registered User
 
Join Date: May 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

so.....how did you fix it?






Similar Threads
Thread Thread Starter Forum Replies Last Post
object reference not set to instant of an object shahidrasul ASP.NET 2.0 Basics 1 September 5th, 2008 02:01 PM
Object reference not set flashmanTom BOOK: Beginning VB.NET Databases 1 February 19th, 2008 06:29 AM
Object Reference not set to an instance of object srinivas_chakka ASP.NET 1.0 and 1.1 Professional 0 February 8th, 2006 11:56 AM
Getting Error - "Object reference not set to an in peri C# 2 December 24th, 2004 11:20 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.