473,395 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

VB6 to VB.NET conversion issues, .dll function returns an error

I recently converted a VB6 program to VB.NET. This program is used to communicate with the Superlogics PCM Series DAQ card that the company no more produces and has no support for VB.NET. My program was running fine in VB6 but has problems in VB.net due to the the functions in the external .dll file (I am not sure)

I read many forums and did some changes with respect to the marshaling attributes. So guys please give me your ideas to solving this -

Error

'I am getting an error with intStatus = 350
referring to "Invalid Request Handle", please refer Line 73 in the program

'The superlogics manual asks me to check the PCMDigitalInputVB function and nothing more

Please guide me to the cause, Thanks in advance



Expand|Select|Wrap|Line Numbers
  1.  
  2. Public Function singleDigitalInput(ByVal LogicalDevice As Short, ByVal Channel As Short, ByRef InputValue As Byte) As Long
  3.  
  4.         Dim intStatus As Short
  5.         Dim intRequestHandle As Short
  6.         Dim udtDigioRequest As New DigioRequest
  7.         udtDigioRequest.Initialize()
  8.         Dim udtDataBuffer As New PCMDriveBuffer
  9.         Dim udtAllocateRequest As New allocate_request
  10.  
  11.         Dim lngRetChannelAdd As Integer
  12.         Dim lngRetBufferAdd As Integer
  13.  
  14.         Dim blnCompleteStatus As Boolean
  15.         Dim lngEventMask As Integer
  16.         Dim ErrorCode As Short
  17.  
  18.         On Error GoTo errUnknown
  19.  
  20.  
  21.  
  22.         intRequestHandle = 0
  23.         blnCompleteStatus = False
  24.  
  25.         '-------------------------------------------------------------------
  26.         'Allocate and lock memory for the Digital Input
  27.         '-------------------------------------------------------------------
  28.  
  29.         With udtAllocateRequest
  30.             .request_type = DIGIN_TYPE_REQUEST
  31.             .channel_array_length = 1
  32.             .number_of_buffers = 1
  33.             .buffer_size = 1
  34.             .buffer_attributes = RING_BUFFER
  35.         End With
  36.  
  37.         intStatus = PCMAllocateRequestVB(LogicalDevice, udtAllocateRequest)
  38.  
  39.         If intStatus <> 0 Then
  40.             singleDigitalInput = intStatus
  41.             Exit Function
  42.         End If
  43.  
  44.         'Debug.Print "Allocate Request Status = " & intStatus
  45.  
  46.         '-------------------------------------------------------------------
  47.         'Prepare the Digital Input Request Structure
  48.         '-------------------------------------------------------------------
  49.  
  50.         lngRetChannelAdd = PCMGetAddressOfVB(Channel)
  51.         'UPGRADE_WARNING: Couldn't resolve default property of object udtDataBuffer. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
  52.         lngRetBufferAdd = PCMGetAddressOfVB(udtDataBuffer)
  53.  
  54.         With udtDigioRequest
  55.             .ChannelArrayPtr = lngRetChannelAdd
  56.             .ArrayLength = 1
  57.             .DigioBufferptr = lngRetBufferAdd
  58.             .NumberOfScans = 1
  59.             .IOMode = ForegroundCPU
  60.             .TriggerSource = InternalTrigger
  61.             .ScanEventLevel = 0
  62.             .RequestStatus = NoEvents
  63.         End With
  64.  
  65.         '-------------------------------------------------------------------
  66.         'Send a digital input request to the PCMDrive
  67.  
  68. 'I am getting an error saying that "Invalid Request Handle" with intStatus = 350
  69.  
  70. 'The superlogics manual asks me to check the PCMDigitalInputVB function and nothing more
  71.         '-------------------------------------------------------------------
  72.  
  73.         intStatus = PCMDigitalInputVB(LogicalDevice, udtDigioRequest, intRequestHandle)
  74.  
  75. End Function
  76.  
  77.  
  78.  
  79. '-------------------------------------------------------------------
  80.         Function declaration
  81.         '-------------------------------------------------------------------
  82.  
  83.  
  84.  
  85.     Declare Function PCMDigitalInputVB Lib "PCMDrvVB.DLL" (ByVal logical_device As Short, ByRef Request As DigioRequest, ByRef handle As Short) As Short
  86.  
  87.  
  88. '-------------------------------------------------------------------
  89.         Structure declaration
  90.         '-------------------------------------------------------------------
  91.  <StructLayout(LayoutKind.Sequential, Pack:=1)> Structure DigioRequest
  92.         Dim ChannelArrayPtr As Integer ' address of channel scan list
  93.         <MarshalAs(UnmanagedType.ByValArray, SizeConst:=3)> Dim ReservedArray0 As Short() ' reserved for future expansion
  94.         Dim ArrayLength As Short ' length of chan & gain arrays
  95.         Dim DigioBufferptr As Integer ' address of PCMDRIVE_buffer
  96.         <MarshalAs(UnmanagedType.ByValArray, SizeConst:=3)> Dim ReservedArray1 As Short() ' reserved for future expansion
  97.         Dim TriggerSource As Short ' trigger source
  98.         Dim TriggerMode As Short ' continuous / one-shot trigger
  99.         Dim TriggerSlope As Short ' rising / falling edge trigger
  100.         Dim TriggerChannel As Short ' trigger channel number
  101.         '   (analog or digital trigger)
  102.         Dim TriggerVoltage As Double ' trigger voltage (analog trigger)
  103.         Dim TriggerValue As Integer ' value for trigger (digital trigger)
  104.         <MarshalAs(UnmanagedType.ByValArray, SizeConst:=3)> Dim ReservedArray2 As Short() ' reserved for future expansion
  105.         Dim IOMode As Short ' input mode
  106.         '    = 0 poll
  107.         '    = 1 IRQ
  108.         '    = 2 DMA with CPU status
  109.         '    = 3 DMA with IRQ status
  110.         Dim ClockSource As Short ' clock source (0 = internal)
  111.         Dim ClockRate As Double ' clock rate (if not internal)
  112.         Dim SampleRate As Double ' input sampling rate (Hz)
  113.         <MarshalAs(UnmanagedType.ByValArray, SizeConst:=3)> Dim ReservedArray3 As Short() ' reserved for future expansion
  114.         Dim NumberOfScans As Integer ' number of channel scans
  115.         Dim ScanEventLevel As Integer ' generate event each scan_event_level
  116.         '    scans ( 0 = disable )
  117.         <MarshalAs(UnmanagedType.ByValArray, SizeConst:=7)> Dim ReservedArray4 As Short() ' reserved for future expansion
  118.         Dim TimeoutInterval As Short ' timeout interval (in sec)
  119.         Dim RequestStatus As Integer ' request event status
  120.  
  121.         'UPGRADE_TODO: "Initialize" must be called to initialize instances of this structure. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="B4BFF9E0-8631-45CF-910E-62AB3970F27B"'
  122.         Public Sub Initialize()
  123.             ReDim ReservedArray0(3)
  124.             ReDim ReservedArray1(3)
  125.             ReDim ReservedArray2(3)
  126.             ReDim ReservedArray3(3)
  127.             ReDim ReservedArray4(7)
  128.         End Sub
  129. End Structure
  130.  
  131.  
  132.  
Oct 20 '10 #1
8 1712
!NoItAll
297 100+
Just guessing here but you might try changing InRequestHandle from SHORT to either Integer or IntPtr...
Oct 20 '10 #2
Thanks for your reply. I checked with both of the data types but no luck so far.
Oct 20 '10 #3
!NoItAll
297 100+
Ok - are you passing IntRequestHandle as a parameter to get the return value in that variable - or are you supposed to be passing in a valid handle? Looking at your code it looks like IntRequestHandle is set to 0 when you pass it in - and I imagine that would be an invalid handle if the function is looking for an existing handle. It would appear that you have to provide a valid handle to the process for which you are checking status rather then passing in 0.
Maybe, however IntRequestHandle returns a handle you use later on - it's not clear to me.
Oct 20 '10 #4
I crosschecked with the DAQ card manual and here is the explanation-
PCMDigitalInput performs the configuration portion of a digital input request. For a new configuration,
the application program sets request_handle to 0 before calling PCMDigitalInput. PCMDigitalInput
then analyzes the data structure specified by user_request to determine if all of the parameters are valid and if the requested operation can be performed by the device specified by logical_device. If the
requested operation is valid, PCMDigitalInput assigns request_handle a unique non-zero value. This
request handle is used to identify this request in all future operations.


And about the error code 150 -

150 Invalid request handle.
A request could not be found with the specified request handle. Make sure the configuration procedure (PCMAnalogInput, PCMAnalogOutput, PCMDigitalInput, or PCMDigitalOutput) executed successfully and that the request handle matches the value returned by the configuration procedure
Oct 20 '10 #5
!NoItAll
297 100+
Well, That all seems confusing. The error (150) is indicating it got a handle it didn't like for a call that is supposed to return a handle.
Ok - another tack...
Your instantiation of the function looks too VB6ish to me...
Expand|Select|Wrap|Line Numbers
  1. Declare Function PCMDigitalInputVB Lib "PCMDrvVB.DLL" (ByVal logical_device As Short, ByRef Request As DigioRequest, ByRef handle As Short) As Short
seems like it needs proper decoration.

Try:
Expand|Select|Wrap|Line Numbers
  1. <DLLImport("PCMDrvVB.DLL", SetLastError:=True, CharSet:=CharSet.Auto)> _
  2. Private Function PCMDigitalInputVB(ByVal logical_device As IntPtr, ByRef Request As DigioRequest, ByRef handle As IntPtr) As IntPtr
  3. End Function
  4.  
I changed your Shorts to IntPtr - but you might try Integer, Long, Short - it's never clear how data types are handled and returned in external DLLs.
Oct 21 '10 #6
Thank you!...I will try and keep you updated
Oct 21 '10 #7
I tried all the data types and no luck still....
But I would like to point you to this specific function through which I get the address of the variable, that I pass to "PCMDigitalInputVB" function

Expand|Select|Wrap|Line Numbers
  1. lngRetBufferAdd = PCMGetAddressOfVB(channel)
**************Declaration**********
Expand|Select|Wrap|Line Numbers
  1. Declare Function PCMGetAddressOfVB Lib "PCMDrvVB.DLL" (ByRef pointer As Integer) As Integer

Do you think, the returned addresses are right? How do I check? This is the only thing I want to clarify.

I think you are right, its never clear how data types are handled in external Dll. I am breaking my head on this for the past 3 days. Now, I should probably start coding in C, this DAQ card also supports "C". Do you have any more suggestions?

I appreciate all your help.
Oct 21 '10 #8
!NoItAll
297 100+
I don't see the value in getting the address since the DLL appears to have named entry points you are supposed to be able to use.
I guess I'm out of ideas now too. Have you tried contacting the company to see if they have any knowledge of how to use their libs in vb.net?
Also - is their c lib also a dll? You actually may have more luck marshaling the functions from that dll in vb.net then trying to use the lib made for vb6. I would think it would be much the same as using win32 APIs.
Oct 21 '10 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: varois83 | last post by:
Hi I am a newbie and struggling with my guestbook validation process. I have found the following function online to check the length of a form field. <?php function checkLength($string,...
11
by: eddie wang | last post by:
The following code with formatnumber function returns me the following code. Why? Thanks. <td align="right"><Font class=content4><%=formatNumber(ars.Fields("SOLD_AMOUNT"),2)%></td> Microsoft...
6
by: Owen | last post by:
Hi, can somebody help me please... I'm trying to set up a very simple asp page that sends me an email when it runs. This is just to try and get CDOSYS working so I can send out emails from my...
4
by: octavio | last post by:
Hello members of the comp.lang.c newsgroup. Please I need you help on the following one. Compiling the simple code I'm getting this error message. Why ? Please what's the correct type of the fb...
18
by: ben.carbery | last post by:
Hi, I have just written a simple program to get me started in C that calculates the number of days since your birthdate. One thing that confuses me about the program (even though it works) is...
4
by: Michael Yanowitz | last post by:
I am still new to Python but have used it for the last 2+ months. One thing I'm still not used to is that functions parameters can't change as expected. For example in C, I can have status =...
5
by: Travis | last post by:
I am using a function that returns a const char * that is usually a word, etc. How can I check to see if what it returns is empty? I tried if (function() == "") and (function() == NULL) and...
1
TheMan1
by: TheMan1 | last post by:
Hi, I'm making a simple program in C++. I have an object named TextReader, with a function GetString(), and I also have another object, TextWriter. Now when *TextWriter is called, it needs to...
2
by: davidj411 | last post by:
if you run execfile function to run a python script and that script has variables and functions, should't those variable change in the interactive prompt too? script snippet that calls the...
3
by: Ananthu | last post by:
Hi, I use BulkSMSGateway - ATSMS.dll for sending SMS from ASP.NET. When I click Connect button, I am able to connect to the mobile using bluetooth successfully from my WebPage. But when i...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.