"Access violation reading location 0x0000000a." in C++

0

Im trying to call some nio functions from a DLL but keep getting the Access violation reading location error. This is the code that I have.

These are the functions that I want to call.

 typedef void ( *nio_read)(OUT IOSTAT  *pIoStat,
         IN OUT       IOVSPEC *pIov, 
               IN OUT       EGUREC  *pEgu, 
         IN OUT       IODATA  *pIoData );
 typedef void(*nio_paddr)(OUT IOSTAT *pIoStat, IN OUT IOVSPEC *pIov, 
        IN OUT EGUREC *pEgu, IN char *pszBuff);
 typedef void(*nio_tick_enable)(IOSTAT *pIoStat, IOVSPEC *pIov);
 typedef void(*nio_tick)(short int amount);

This is the main function

 int main(void)
 {
    nio_read _nio_read;
    nio_tick _nio_tick;
    nio_tick_enable _nio_tick_enable;
    nio_paddr _nio_paddr;
    IOSTAT  *pIoStat = (IOSTAT *)malloc(sizeof(IOSTAT));
    memset(pIoStat,0, sizeof(IOSTAT));

    IOVSPEC *pIov = (IOVSPEC *)malloc(sizeof(IOVSPEC));
    memset(pIov,0,sizeof(IOVSPEC));
    EGUREC  *pEgu =  (EGUREC *)malloc(sizeof(EGUREC));
    memset(pEgu,0,sizeof(EGUREC));
    IODATA  *pIoData = (IODATA *)malloc(sizeof(IODATA));
    memset(pIoData,0,sizeof(IODATA));;

          HINSTANCE hInstLibrary = LoadLibrary("J91STSR.dll");


   if( hInstLibrary ) {
    _nio_read=(nio_read)GetProcAddress(hInstLibrary,"nio_read");
    _nio_paddr=(nio_paddr)GetProcAddress(hInstLibrary,"nio_paddr");
    _nio_tick=(nio_tick)GetProcAddress(hInstLibrary,"nio_tick");
    _nio_tick_enable=(nio_tick_enable)GetProcAddress(hInstLibrary,"nio_tick_enable");
    printf("testttt \n");
    }


if(_nio_read){
    (_nio_read)(pIoStat, pIov,pEgu,pIoData);

  }

  if( hInstLibrary ) {
    FreeLibrary(hInstLibrary );
  }
 }

I get the error at this line

 (_nio_read)(pIoStat, pIov,pEgu,pIoData);

I'm still new to c++ and I can't seem to figure out what the problem is.

c++
visual-c++
dll
access-violation
unhandled-exception
asked on Stack Overflow May 22, 2014 by user3142048

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0