Dllimport System AccessViolationExecption

P

paul f

Hi got an unhandled exception when I tried to call the dscDIOInputBit
function contained in a 3rd part dll file,
can you help???

here is the code....


using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace dllimport
{
class Program
{

[DllImport("C:\\dscud.dll", EntryPoint = "dscDIOInputBit")]
public static extern byte dscDIOInputBit(short board, byte
port, byte bit, byte digital_value);
static void Main(string[] args)
{
short board = 32767;
byte port =0, bit= 0, digital_value=00;

dscDIOInputBit(board, port, bit, digital_value);
}
}
}
 
P

paul f

Hi got an unhandled exception when I tried to call the dscDIOInputBit
function contained in a 3rd part dll file,
can you help???

here is the code....

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespacedllimport
{
    class Program
    {

        [DllImport("C:\\dscud.dll", EntryPoint = "dscDIOInputBit")]
        public static extern byte dscDIOInputBit(short board, byte
port, byte bit, byte digital_value);
        static void Main(string[] args)
        {
            short board = 32767;
            byte port =0, bit= 0, digital_value=00;

            dscDIOInputBit(board, port, bit, digital_value);
        }
    }



}- Hide quoted text -

- Show quoted text -

Exception is " attempted to read or write protected memory"
 
C

Charles Calvert

Hi got an unhandled exception when I tried to call the dscDIOInputBit
function contained in a 3rd part dll file,
can you help???

What's the signature of the exported function?
 
P

paul f

Function dscDIOInputBit is defined as:
============================
Receives a bit value from a given digital input port at a specified
bit location (0-7). If port exceeds the board's maximum number of
digital ports, the function returns DE_INVALID_PARM. If the board
contains only a single digital port, then this value is ignored.


Signature is:
=========
BYTE dscDIOInputBit(DSCB board, BYTE port, BYTE bit, BYTE*
digital_value);

DSCB is defined in the header file as type SWORD, and is used as a "C"
handle to function dscDIOInputBit() . Therefore how do I provide a
handle via dllimport?
My code is currently hardcoded above to Read Port 0 and Bit 0, but I
know that the board handle is not correct, can yee advise on this?
also it looks like digital_value is also defined as a pointer, can you
also advise on how to implement a pointer to?
 
P

paul f

Function dscDIOInputBit is defined as:
============================
Receives a bit value from a given digital input port at a specified
bit location (0-7). If port exceeds the board's maximum number of
digital ports, the function returns DE_INVALID_PARM. If the board
contains only a single digital port, then this value is ignored.

Signature is:
=========
BYTE dscDIOInputBit(DSCB board, BYTE port, BYTE bit, BYTE*
digital_value);

DSCB is defined in the header file as type SWORD, and is used as a "C"
handle to function dscDIOInputBit() . Therefore how do I provide a
handle via dllimport?
My code is currently hardcoded above to Read Port 0 and Bit 0, but I
know that the board handle is not correct, can yee advise on this?
also it looks like digital_value is also defined as a pointer, can you
also advise on how to implement a pointer to?

more info:
board The handle of the board to operate on ??? don't
know how to implement this in dllimport
port Selected input port (i have set this to port 0)
bit Bit location (0-7) to read on the selected input
port (I want to read bit 0)
digital_value Present value of the bit read; 1 or 0 ??? don't know
how to implement this in dllimport
 
P

paul f

more info:
board           The handle of the board to operate on    ??? don't
know how to implement this in dllimport
port             Selected input port   (i have set this to port 0)
bit               Bit location (0-7) to read on the selected input
port   (I want to read bit 0)
digital_value Present value of the bit read; 1 or 0    ??? don't know
how to implement this in dllimport- Hide quoted text -

- Show quoted text -

board is defined as a "signed short" type in header file.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top