Thread: Getting Access Violation (Segmentation Fault)

  1. #1
    Registered User
    Join Date
    Feb 2006
    Ballincollig, co. cork, Eire

    Getting Access Violation (Segmentation Fault)


    I have written a program using Dev C++. The program needs to call on functions from a .dll to run, so I have loaded the corresponding .lib into the project and all of the headers and the .dll is in the same directory as the .cpp file I have created.

    When I go to run the program, it executes as expected until it comes to one of the functions I call from the .dll. At this point the program crashes and asks would I like to send the error of to microsoft. The usual thing.

    I ran the debugger in Dev and it stepped through the program until it reached one of the functions. At this point the following was displayed.

    An Access Violation (Segmentation Fault) raised in your program.

    A friend suggested that the problem could be because the .dll was created with Microsoft Visual Studio and is not compatible with mingw.

    Does anybody know if this is true and if so, any suggestions on what to do?



    P.S. The following is a segment of the code. The error is caused when the program tries to execute
    ETSocketLink(ipaddr, 16385)
    #include <cstdlib>
    #include <iostream>
    #include <stdio.h>
    #include <memory.h>
    #include "et1000.h"
    using namespace std;
    int main ()
        int iMachine;
        int iRet;
        int iRetVal;
        char ipaddr[16];
        cout << "1" << endl;
        iRetVal = ETGetLinkStatus();
        if (iRetVal < 1)
                    cout << "Not Linked" << endl;
        } else {
                    cout << "Linked" << endl;
        cout << "2" << endl;
        // prompt for IP and link to chassis
    	printf("Enter IP address of SmartBits chassis ==> ");
    	printf("Linking on %s \n", ipaddr);
    	cout << "3" << endl;
    // negative return value means command failed
    	iRet=ETSocketLink(ipaddr, 16385);
    	if (iRet < 0)
    		printf("Error linking to chassis: %d \n",iRet);
    		return iRet;
        cout << "4" << endl;

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    I beleive gcc can generate code that matches any of Visual Studio's calling conventions, so the code being compiled with a different compiler doesn't seem quite right, but I can't really say for sure withtout actually seeing the code in assembler.

    One scenario might be that you should call some form of initialization function before using these functions, but that's just a simple guess.

    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Visalia, CA, USA
    What matsp said. I have never had any issue with compiling between the two compilers. Sometimes I have found I needed to manually link to the DLL. There are ways of building the proper libraries to connect to a pre-existing DLL too. So chances are you just need to do something of that sort. Since you are not using any C++ code, I think just manually linking to the DLL would work just fine.

    [Edit]I should be less cryptic. You can use LoadLibraryEx()[/Edit]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. access violation segmentation fault raised in your program
    By dinamit875 in forum C++ Programming
    Replies: 8
    Last Post: 04-23-2009, 11:44 AM
  2. Replies: 3
    Last Post: 07-17-2008, 08:45 AM
  3. access violation (segmentation fault)
    By MarlonDean in forum C++ Programming
    Replies: 7
    Last Post: 05-16-2008, 05:02 AM
  4. Segmentation Fault - Trying to access parallel port
    By tvsinesperanto in forum C Programming
    Replies: 3
    Last Post: 05-24-2006, 03:28 AM
  5. Locating A Segmentation Fault
    By Stack Overflow in forum C Programming
    Replies: 12
    Last Post: 12-14-2004, 01:33 PM

Tags for this Thread