Hello,
I'm trying to communicate with a TEC Controller Newport 350B using their
..dll and VB.NET. I was able to use their example code with VB6. However,
I've got following error when using VB.NET:
"Access Violation Exception was unhandled. Attempted to read or write
protected memory. This is often an indication that other memory is corrupt."
I have no problem when send commands to my TEC Controller (using
"SendAsciiA " - see below for the code). But, I always got error when trying
to query the TEC Controller using "GetAsciiA. " Thanks in advance!
Here is the declaration on my code:
Declare Function InitSystem _
Lib "M530DLL.dl l" () As Integer
Declare Function SendAsciiA _
Lib "M530DLL.dl l" Alias "SendAscii" _
(ByVal deviceID As Integer, _
ByVal command As String, _
ByVal length As Integer) As Integer
Declare Function GetAsciiA _
Lib "M530DLL.dl l" Alias "GetAscii" _
(ByVal deviceID As Integer, _
ByVal response As String, _
ByVal bytesRead As Integer) As Integer
Here is the code to call the function:
Public Function NPWriteRead(ByV al NPCommand As String, ByVal DeviceID As
Short) As String
Dim strRes As String = New String(" ", 64)
Dim bytesRead As Integer
Dim ret As Integer
Call NPWrite(NPComma nd, DeviceID) 'this procedure will send the
command to the instrument.
ret = GetAsciiA(Devic eID, strRes, bytesRead) -this is where the
error occurs
If ret = M530USBINVALIDA DDRESS Then
MsgBox("USB Address Invalid", vbOKOnly + vbCritical, "M530")
ElseIf ret = M530ERROR Then
MsgBox("USB Communication Error", vbOKOnly + vbCritical, "M530")
ElseIf ret = M530USBADDRESSN OTFOUND Then
MsgBox("USB Address not Found", vbOKOnly + vbCritical, "M530")
End If
Return Trim(strRes)
End Function
--
xblessing 3 9344
On Sep 18, 7:34 pm, xblessing <xbless...@disc ussions.microso ft.com>
wrote:
Hello,
I'm trying to communicate with a TEC Controller Newport 350B using their
.dll and VB.NET. I was able to use their example code with VB6. However,
I've got following error when using VB.NET:
"Access Violation Exception was unhandled. Attempted to read or write
protected memory. This is often an indication that other memory is corrupt."
I have no problem when send commands to my TEC Controller (using
"SendAsciiA " - see below for the code). But, I always got error when trying
to query the TEC Controller using "GetAsciiA. " Thanks in advance!
Here is the declaration on my code:
Declare Function InitSystem _
Lib "M530DLL.dl l" () As Integer
Declare Function SendAsciiA _
Lib "M530DLL.dl l" Alias "SendAscii" _
(ByVal deviceID As Integer, _
ByVal command As String, _
ByVal length As Integer) As Integer
Declare Function GetAsciiA _
Lib "M530DLL.dl l" Alias "GetAscii" _
(ByVal deviceID As Integer, _
ByVal response As String, _
ByVal bytesRead As Integer) As Integer
Here is the code to call the function:
Public Function NPWriteRead(ByV al NPCommand As String, ByVal DeviceID As
Short) As String
Dim strRes As String = New String(" ", 64)
Dim bytesRead As Integer
Dim ret As Integer
Call NPWrite(NPComma nd, DeviceID) 'this procedure will send the
command to the instrument.
ret = GetAsciiA(Devic eID, strRes, bytesRead) -this is where the
error occurs
If ret = M530USBINVALIDA DDRESS Then
MsgBox("USB Address Invalid", vbOKOnly + vbCritical, "M530")
ElseIf ret = M530ERROR Then
MsgBox("USB Communication Error", vbOKOnly + vbCritical, "M530")
ElseIf ret = M530USBADDRESSN OTFOUND Then
MsgBox("USB Address not Found", vbOKOnly + vbCritical, "M530")
End If
Return Trim(strRes)
End Function
--
xblessing
Could you post the VB6 sample... Most likely, there is a problem with
your delarations.
--
Tom Shelton
"xblessing" <xb*******@disc ussions.microso ft.comschrieb
Hello,
I'm trying to communicate with a TEC Controller Newport 350B using
their .dll and VB.NET. I was able to use their example code with
VB6. However, I've got following error when using VB.NET:
"Access Violation Exception was unhandled. Attempted to read or
write protected memory. This is often an indication that other
memory is corrupt." I have no problem when send commands to my TEC
Controller (using
"SendAsciiA " - see below for the code). But, I always got error
when trying to query the TEC Controller using "GetAsciiA. " Thanks
in advance!
[...]
Declare Function GetAsciiA _
Lib "M530DLL.dl l" Alias "GetAscii" _
(ByVal deviceID As Integer, _
ByVal response As String, _
ByVal bytesRead As Integer) As Integer
I guess it must be "ByRef bytesRead As Integer". Probably, in the VB6 code,
there is neither ByVal nor ByRef. Unspecified, it's ByRef by default. In
VB.Net, unspecified, it's auto-completed with ByVal.
Armin
Tom and Armin,
Thanks for the reply. I tried to change the last byVal to byRef. The code
is working well now. Thanks a lot for your help.
------
xblessing
"Armin Zingler" wrote:
"xblessing" <xb*******@disc ussions.microso ft.comschrieb
Hello,
I'm trying to communicate with a TEC Controller Newport 350B using
their .dll and VB.NET. I was able to use their example code with
VB6. However, I've got following error when using VB.NET:
"Access Violation Exception was unhandled. Attempted to read or
write protected memory. This is often an indication that other
memory is corrupt." I have no problem when send commands to my TEC
Controller (using
"SendAsciiA " - see below for the code). But, I always got error
when trying to query the TEC Controller using "GetAsciiA. " Thanks
in advance!
[...]
Declare Function GetAsciiA _
Lib "M530DLL.dl l" Alias "GetAscii" _
(ByVal deviceID As Integer, _
ByVal response As String, _
ByVal bytesRead As Integer) As Integer
I guess it must be "ByRef bytesRead As Integer". Probably, in the VB6 code,
there is neither ByVal nor ByRef. Unspecified, it's ByRef by default. In
VB.Net, unspecified, it's auto-completed with ByVal.
Armin
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: William Brogden |
last post by:
I am trying to use the php_java.dll and php5servlet.dll
- from pecl-5.1.4-win32.zip - dated 5/04/2006
to execute php in a Tomcat5.5.9 servlet environment. Java 1.5.0
I finally got a configuration that will start executing the single php tag:
<?php phpinfo(); ?>
This starts an HTML page and writes lots of configuration information but
does not finish the page. Java reports:
# An unexpected error has been detected by HotSpot Virtual...
|
by: Curten |
last post by:
Hi,
I want to read data from a txt-file that looks like this:
aaa 4 12.45
bbb 3 7.34
ccc 12 3.45
and store the data in an array of structures. The struct and array are defined like this
|
by: Lee |
last post by:
Hi all, been playing with some code overriding WndProc to get
information about mouse events.
So far I've tried to capture when the left mouse button is pressed
using the code below.
Sometimes the clicks will register fine, and other times it'll cause an
acess violation (Attempted to read or write protected memory. This is
often an indication that other memory is corrupt.)
So I'm wondering why this occurs and how I can prevent it from...
|
by: pbaldridge |
last post by:
I'm just starting my first C++ class and have a very basic question. We are to write a program that is going to be using the pow10(int m) function and we are not to use the pow10 function from the math library. I'm unfamiliar with the function so wrote a simple program to see it's output. I am receiving the following error however.
" An Access Violation (Segment Fault) raised in your program."
If anyone can explain what's causing this I...
|
by: Kirzak pascuale |
last post by:
ok I made this exercise, for a compiler design course. it is not urgent as the assignment was due 2 days ago. i got a 4 out of 10 for effort. mainly because i did not just rehash code examples from the deitel&deitel c++ books. now i get the program to compile, but when run, it throws an access violation exception.
So to summarize: the program asks the user for the filename of the source file, opens it with fopen for reading, then takes the...
| |
by: Johnex |
last post by:
Hi!
I am currently writing a tiny webserver that i can attach to all my applications to give them web functionality. I first started of making all the socket and helper classes to handle the requests, so i only had a socket output or some 100 bytes or so, just a small text saying that the server was running, sent to the browser in html. I later added the ability to open any file in the working directory of the compiled exe, but encountered a...
|
by: zubair1 |
last post by:
Hello,
I have a program which deletes files from cache
for exampe:-
Temporary Internet Cache
History Cache
Cookie Cache
and finally TEMP cache
|
by: amungen |
last post by:
I am getting the following error from my code:
Traceback (most recent call last):
File "<pyshell#309>", line 1, in <module>
get_handles('Python26')
File "C:\Python26\e__handle.py", line 19, in get_handles
ctypes.windll.user32.EnumWindows(ctypes.c_long(function),ctypes.byref(ctypes.c_char_p(arg)))
WindowsError: exception: access violation writing 0x0064BCF6
From some searching online I think it's because I'm not able to...
|
by: dantz |
last post by:
Hi Everyone,
Currently I am having this exception:
"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
I am still debugging which part of my code is the cause.
Is there a way not to let the exception show as of the moment? When it is about (which i dont know when) to show I will restart or close the application..
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |