DPLOTLIB.DLL with VB 2008

Q&A for Visual Basic, Visual Basic .NET, and PowerBasic developers using DPlot
Post Reply
Mao
Posts: 12
Joined: Tue Jan 16, 2007 2:25 pm

DPLOTLIB.DLL with VB 2008

Post by Mao »

David:

I successfully developed an application with VB 2005 that called DPLOTLIB.DLL using the example included with the software:

Code: Select all

Public Sub DPlot_FindDPLOTLIB() 
    ' Find DPLOTLIB.DLL. 
    Dim key As Microsoft.Win32.RegistryKey 
    Dim path As String 
    Dim hLib As IntPtr 

    hLib = LoadLibrary("dplotlib.dll") 
    If hLib <> 0 Then 
        ' If LoadLibrary finds the DLL, then so will VB.NET, so there's 
        ' no need to look in the registry or change the current 
        ' directory 
        FreeLibrary(hLib) 
        Exit Sub 
    End If 

    key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\DPLOT\\DPLOTLIB\\Folder") 
    path = key.GetValue("").ToString() 
    key.Close() 
    If Len(path) > 0 Then 
        System.Environment.CurrentDirectory = path 
    End If 
End Sub
Recently I migrated to VB 2008 but the code does not run anymore; it stops in the line:

Code: Select all

path = key.GetValue("").ToString()
and reports the following message:

Code: Select all

System.NullReferenceException was unhandled
  Message="Object reference not set to an instance of an object."
and recommends to:

Code: Select all

Use the "new" keyword to create an object instance.
Has somebody reported the same problem with VB 2008 ?

Thanks.

Mao
User avatar
DPlotAdmin
Posts: 2312
Joined: Tue Jun 24, 2003 9:34 pm
Location: Vicksburg, Mississippi
Contact:

Post by DPlotAdmin »

I'm not sure but it seems to me the error message means that the key doesn't exist, and you need to check against it being "Is Nothing" before using GetValue. But I may be wrong.

You'll likely have much better luck posting this question on any of the numerous VB boards, since it really has nothing to do with DPlot.
Visualize Your Data
support@dplot.com
BillGrissom
Posts: 4
Joined: Thu Feb 17, 2011 2:42 pm

Post by BillGrissom »

Mao,

I converted a VB6 program that calls Dplot to VB2008 over 1 year ago. I didn't changed anything in sub Dplot_FindDPLOTLIB and I don't see that the auto-converter changed anything.

Anyway, I copied your lines next to mine and see no difference.

I agree that most likely your dll became unregistered. Try typing the following in a CMD window:

regsvr32 /u dplotlib.dll
regsvr32 dplotlib.dll

The first unregisters the dll (if it finds it) and 2nd registers it.
Don't ask me how it knows where to put it in the Registry, that must be embedded within the dll. This has worked for me several times, even when basic Windows dll's get unregistered (maybe a mistaken script that my I.S. department ran).
User avatar
DPlotAdmin
Posts: 2312
Joined: Tue Jun 24, 2003 9:34 pm
Location: Vicksburg, Mississippi
Contact:

Post by DPlotAdmin »

I'm probably in over my head here, but to the best of my knowledge regsvr32 is only useful for COM objects, and dplotlib.dll does not use COM. If I go to the folder containing dplotlib.dll with a command prompt and type
regsvr32 dplotlib.dll
I get an error message about DLLRegisterServer and whether the DLL uses OCX (it doesn't).

Short version: whatever problem BillGrissom is having is almost certainly not due to using/not using regsvr32.
Visualize Your Data
support@dplot.com
BillGrissom
Posts: 4
Joined: Thu Feb 17, 2011 2:42 pm

Post by BillGrissom »

Old post. I just ran across this.

I didn't mean to imply that I ever used the regsvr32 commands on any Dplot files, and indeed never had the issues the OP is having. I have used that command to fix another app (Pacific Instruments), per their suggestions and works there. Perhaps they use COM. I just threw it out as a simple thing to try. Sounds like it isn't relevant to Dplot.
BillGrissom
Posts: 4
Joined: Thu Feb 17, 2011 2:42 pm

Post by BillGrissom »

Old post. I just ran across this.

I didn't mean to imply that I ever used the regsvr32 commands on any Dplot files, and indeed never had the issues the OP is having. I have used that command to fix another app (Pacific Instruments), per their suggestions and works there. Perhaps they use COM. I just threw it out as a simple thing to try. Sounds like it isn't relevant to Dplot.
Post Reply