From: leq_82 on
Hello,
 
A exception occured when I calling the dll created inLabVIEW8.2 from  my VB.NET 2005 application.
The compiled DLL exports the follwing  function prototype:
void __stdcall Snap(LStrHandle *Path, LStrHandle *CameraName);
 
And my application program as following:
 
Imports SystemImports System.Runtime.InteropServicesImports System.Windows.FormsImports NationalInstrumentsImports System.Threading
Public Class Form1
    Private StopAcquire As Boolean = True
    'This function definition was found from the header file of     'SnapImage.dll, which is built in LabVIEW
    Private Declare Sub Snap Lib "E:\builds\Snap\SnapImage\SnapImage.dll" Alias "Snap" (ByVal Path As String, ByVal cameraName As String)
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load        MsgBox("Welcome to use VS2005 and LabVIEW?", MsgBoxStyle.OkOnly + MsgBoxStyle.Information, "NI")    End Sub
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click        Dim Picture_Addr As String = "E:\MyPicture"        Dim caremaName As String = ""        StopAcquire = False        While StopAcquire = False            Snap(Picture_Addr, caremaName)        'Exception Occurred! Exception Information:Try to read or write the protected memory,this usually indicate  other  memories have 'been damaged.            PictureBox1.Load(Picture_Addr)            Label1.Text = caremaName            Thread.Sleep(10)        End While    End Sub
 
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click        StopAcquire = True    End SubEnd Class
 
Can anyone know what  the problem is?
Thanks in advance!
 
EnquanLi
China
From: Ravens Fan on
Could it be that you misspelled some of your variables?
In here you have "camera" spelled properly.
Private Declare Sub Snap Lib "E:\builds\Snap\SnapImage\SnapImage.dll" Alias "Snap" (ByVal Path As String, ByVal cameraName As String)
Elsewhere, you spelled it "carema" which is obviously wrong.
Snap(Picture_Addr, caremaName)        'Exception Occurred! Exception Information:Try to read or write the protected memory,this usually indicate  other  memories have 'been damaged
Should you have given the variable CameraName a value besides an empty string in order to get it to work?
Dim caremaName As String = ""
From: Ravens Fan on
You may be correct that it is not the cause.  But sometimes it is the little things like a misspelled variable that can trip you up.  And you should correct the spelling anyway for proffesionalism.  If the variable was consistently spelled wrong, I would agree that it would have not effect.  But in your posted code,  you had spelled it wrong inconsistently, which could have an effect on the program.
 
I don't have any experience or knowledge about the specific .dll and functions you are using.  I am just looking at things in the code that jump out at me as possibly being an issue.  I would still check on the definition of the cameraname string as an empty string.  Is that acceptable according to the documentation of the .dll?  It seems to me that logically you would have to tell the .dll what camera you are trying to use.  Or is that argument there as a spot for the .dll function call to return the name of the camera that it is using?Message Edited by Ravens Fan on 06-11-2007 09:27 AM
From: leq_82 on
Hi,
Thank you for your suggestion,I extremely aggre with you .Misspelled is assuredly not a good custom.I'll be careful later.
actually,cameraname string is return value,may be you'll very amazed.In LabVIEW,cameraname is a indicator's name,it
is a output connector,I don't know why cameraname in the function protype in .dll created by LabVIEW is a input parameter.
Do you know the cause?
I really appreciate your reply,Thanks again!Pls excuse me my English is poor .
EnquanLi
China