Click here to Skip to main content
15,891,657 members
Home / Discussions / C#
   

C#

 
AnswerRe: DataGridView Size Pin
Dave Kreskowiak20-May-09 6:00
mveDave Kreskowiak20-May-09 6:00 
QuestionRelative file path referencing problem Pin
Jacobus0120-May-09 4:09
Jacobus0120-May-09 4:09 
AnswerRe: Relative file path referencing problem Pin
Dave Kreskowiak20-May-09 5:58
mveDave Kreskowiak20-May-09 5:58 
GeneralRe: Relative file path referencing problem Pin
Jacobus0120-May-09 21:17
Jacobus0120-May-09 21:17 
GeneralRe: Relative file path referencing problem Pin
Dave Kreskowiak21-May-09 1:49
mveDave Kreskowiak21-May-09 1:49 
GeneralRe: Relative file path referencing problem Pin
Jacobus0121-May-09 1:59
Jacobus0121-May-09 1:59 
GeneralRe: Relative file path referencing problem Pin
Dave Kreskowiak21-May-09 16:16
mveDave Kreskowiak21-May-09 16:16 
QuestionAccessViolationException when using the qapuiek.dll Pin
TheFoZ20-May-09 3:28
TheFoZ20-May-09 3:28 
Hi.

I've been trying to convert a function from an olf VBA project into C#. It uses the Quick Address API to check if a postcode as been recoded. I have managed to delcare the references to the API and managed to perform a search but when I try an retrieve the information it gives me an AccessViolationException. My class is.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace PostCodeRecodetest
{
    class QAProClass
    {
        //Declarations

        //Declare Sub QAInitialise Lib "QAPUIEK.DLL" (ByVal vi1 As Long)
        [DllImport("qapuiek.dll")]
        public static extern int QAInitialise(long vi1);

        //Declare Function QAPro_Open Lib "QAPUIEK.DLL" (ByVal vs1 As String, ByVal vs2 As String) As Long
        [DllImport("qapuiek.dll")]
        public static extern int QAPro_Open(string vs1, string vs2);

        //Declare Sub QAPro_Close Lib "QAPUIEK.DLL" ()
        [DllImport("qapuiek.dll")]
        public static extern void QAPro_Close(); 

        //Declare Function QAPro_Search Lib "QAPUIEK.DLL" (ByVal vs1 As String) As Long
        [DllImport("qapuiek.dll")]
        public static extern int QAPro_Search(string vs1);

        //Declare Function QAPro_AddrLine Lib "QAPUIEK.DLL" (ByVal vl1 As Long, ByVal vi2 As Long, ByVal vs3 As String, ByVal rs4 As String, ByVal vi5 As Long) As Long
        [DllImport("qapuiek.dll")]
        public static extern int QAPro_AddrLine(int vl1, int vi2, string vs3, ref string rs4, int vi5);

        public string PostCodeRecoded(string postcodeIn)
        {
            string rsBuffer = "";
            int lOpenReturn = 0;
            int lSearchReturn = 0;
            string sSearchString = "";
            string returnedPostcode = postcodeIn;
            string iniPath = "C:\\a_DEV\\Qapro.ini";

            // Close QA first
            QAPro_Close();

            // Initialise the dll for faster performance
            QAInitialise(1);

            // Open the DLL with the specific ini file.  Hard coded for the moment
            lOpenReturn = QAPro_Open(iniPath, "");

            if (lOpenReturn != 0) return "QAPro Failed";

            //Add validation later to insure that the postcode is the correct number of characters

            sSearchString = postcodeIn; 

            lSearchReturn = QAPro_Search(sSearchString);

            if (lSearchReturn == -9811)
            {
                lSearchReturn = QAPro_AddrLine(0, 11, "0",ref rsBuffer, 9); //This is the line that fails
                returnedPostcode = rsBuffer;
            }

            return returnedPostcode;
        }
    
    }

}


I have left the old VBA declaration in. I already had some trouble as the DLL is 32 bit and a long was too big for the return values. The QAPro_AddrLine function basically returns a part of the address into rsBuffer from what I can gather. I can't find any documentation on the DLL. What can cause this type of exception?

Any help will be appreciated.

The FoZ

AnswerRe: AccessViolationException when using the qapuiek.dll Pin
Luc Pattyn20-May-09 4:36
sitebuilderLuc Pattyn20-May-09 4:36 
GeneralRe: AccessViolationException when using the qapuiek.dll Pin
TheFoZ20-May-09 4:52
TheFoZ20-May-09 4:52 
GeneralRe: AccessViolationException when using the qapuiek.dll Pin
Luc Pattyn20-May-09 4:56
sitebuilderLuc Pattyn20-May-09 4:56 
GeneralRe: AccessViolationException when using the qapuiek.dll Pin
TheFoZ20-May-09 5:04
TheFoZ20-May-09 5:04 
GeneralRe: AccessViolationException when using the qapuiek.dll Pin
Luc Pattyn20-May-09 5:43
sitebuilderLuc Pattyn20-May-09 5:43 
GeneralRe: AccessViolationException when using the qapuiek.dll Pin
Dave Kreskowiak20-May-09 5:53
mveDave Kreskowiak20-May-09 5:53 
GeneralRe: AccessViolationException when using the qapuiek.dll Pin
Luc Pattyn20-May-09 6:05
sitebuilderLuc Pattyn20-May-09 6:05 
GeneralRe: AccessViolationException when using the qapuiek.dll Pin
Dave Kreskowiak20-May-09 6:28
mveDave Kreskowiak20-May-09 6:28 
GeneralRe: AccessViolationException when using the qapuiek.dll Pin
Luc Pattyn20-May-09 6:42
sitebuilderLuc Pattyn20-May-09 6:42 
QuestionWindows service apps Pin
saeidfarahi20-May-09 3:11
saeidfarahi20-May-09 3:11 
AnswerRe: Windows service apps Pin
PIEBALDconsult20-May-09 3:25
mvePIEBALDconsult20-May-09 3:25 
QuestionRemoving AutoIncrement from Access database column Pin
Eduard Keilholz20-May-09 2:51
Eduard Keilholz20-May-09 2:51 
Questionfroms in MDI Pin
sachees12320-May-09 2:42
sachees12320-May-09 2:42 
AnswerRe: froms in MDI Pin
musefan20-May-09 2:48
musefan20-May-09 2:48 
GeneralRe: froms in MDI Pin
sachees12320-May-09 3:17
sachees12320-May-09 3:17 
AnswerRe: froms in MDI [modified] Pin
musefan20-May-09 3:24
musefan20-May-09 3:24 
GeneralRe: froms in MDI Pin
sachees12320-May-09 23:45
sachees12320-May-09 23:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.