CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Nov 2003
    Posts
    27

    Help: about Access Violation

    I have a DLL to be used under Visual Basic, and the DLL was done in C(using Visual C++). When I compile the project in Visual Basic, it works. But after I made a .EXE file in VB and ran it. The system said: "Unhandled exception in *.exe(*.Dll): 0xC0000005: Access Violation. " And it was the same when I debugged it in Visual C++(6.0) environment. Do you have any idea?
    Thank you.

  2. #2
    Join Date
    May 2002
    Location
    Romania
    Posts
    929
    Just see what causes that crash. It may be an uninitialized pointer.

    Snakekaa
    Move like a snake, think like a snake, be a snake !!!

  3. #3
    Join Date
    Feb 2002
    Posts
    5,757
    I work mainly with C++. Under Visual C++, a project must support dynamic linking for the application to use DLL.

    Kuphryn

  4. #4
    Join Date
    Jul 2003
    Posts
    147
    Run VB under the C++ debugger. If you are running your VB application against the debug version of you dll then you can trace right into the access violation.

    GL

  5. #5
    Join Date
    Nov 2003
    Posts
    27
    I execute the EXE file, the application loads, and then I klick a button on the interface(Dialogbox), and it should do something(implemented in DLL), but at this moment, the error occurs.
    What's more, I work under Windows 98.
    Thank you.

  6. #6
    Join Date
    Oct 2002
    Location
    St. Louis
    Posts
    27
    What do you mean when you say "it was the same when I debugged it in Visual C++(6.0) environment". If The access Violation happened in debug mode, you can pinpoint exactly what goes wrong. If it only happened in release version, use the following step to turn on debug for release, and debug into it see what went wrong:

    How to turn debug on for Release version:
    a) For the release build, go to "Project | settings | C/C++" and make sure theat the "General" Category is selected.
    b) For "debug info", choose "Program Database" instead of "None".
    c) Turn off the optimizations for now.
    d) Go to the "Link" tab and check "Generate Debug Info".
    e) Rebuil the release mode app.



    -Ray

  7. #7
    Join Date
    Nov 2003
    Posts
    27
    Well, when I debug the DLL in VC++, it stops with the error report I mentioned when the programm runs into the line: "100090E6 call @ILT+195(checkparam_4_Margin) (100010c8)", and when I click 'OK' to close the error dialog box, the arrow points to the line: "10004B51 mov byte ptr [ecx+eax],0FFh", and can not run further.
    *The 'checkparam_4_Margin' is a function in the DLL, but not an exported one.
    *I have tried to leave the 'checkparam_4_Margin' out, but it still stops somewhere like: '
    1000908D call @ILT+195(psResult) (100010c8)' . The 'psResult' is also a function in the DLL, but an exported one and called in VB.
    *Then I left the 'psResult' out of the code, the error still happed in somewhere else.
    I don't know how to understand the lines in the debug environment. And I don't know what to do next.
    Thank you for your help.

  8. #8
    Join Date
    Sep 2003
    Location
    Forever Gone... For Now...
    Posts
    1,515
    I suggest you try tmecham's suggestion:
    Originally posted by tmecham
    Run VB under the C++ debugger. If you are running your VB application against the debug version of you dll then you can trace right into the access violation.

    GL
    Thought for the day/week/month/year:
    Windows System Error 4006:
    Replication with a nonconfigured partner is not allowed.

  9. #9
    Join Date
    Nov 2003
    Posts
    27
    I have found the problem!
    The reason is: The VB calls one function in DLL, and the parameters are defined as integer in DLL, of course I defined these parameters as Integer in VB too. But this is the case. When I change them into Long(Integer), the error never occours.

    But I still confused with the problem: The integer has 2 bytes, and a range from -32,768 to 32,767. The values I assign to the parameters are 640 in maxinum, it should have no overflow. And the Long in VB has 4 bytes, of course.
    Does anyone know why?

  10. #10
    Join Date
    Sep 2003
    Location
    Forever Gone... For Now...
    Posts
    1,515
    Originally posted by wind0965
    I have found the problem!
    The reason is: The VB calls one function in DLL, and the parameters are defined as integer in DLL, of course I defined these parameters as Integer in VB too. But this is the case. When I change them into Long(Integer), the error never occours.

    But I still confused with the problem: The integer has 2 bytes, and a range from -32,768 to 32,767. The values I assign to the parameters are 640 in maxinum, it should have no overflow. And the Long in VB has 4 bytes, of course.
    Does anyone know why?
    In VC++, an int is 4 bytes. In VB6, an int is 2 bytes. Regardless of the values held by a variable of type int, those are the memory requirements of that type. VB interpreted the int as 2 bytes, and VC++ was "reading" 4 bytes, to get the value. Change your VB function declaration to indicate that the param is a Long (4 bytes), or change your VC++ function to take a short (2 bytes).
    Thought for the day/week/month/year:
    Windows System Error 4006:
    Replication with a nonconfigured partner is not allowed.

  11. #11
    Join Date
    May 2004
    Posts
    2

    Unhappy Access violation

    I am supposed to migrate a second-party code written in C++(using VC++) from Windows NT server to Windows 2003 server.

    The migration procedure is standard and there doesn't seem to be any problem in the migration part. In fact the program runs fine with one set of parameters.

    However, when i run the program with another parameter, it crashes giving the followng error:

    The instruction at "0x00336777" referenced memory at "0x0000000c". The memory could not be "read".

    Click on OK to terminate the program
    Click on CANCEL to debug the program.

    When i cancel to debug it, debugging instantly stops giving the following error:

    Unhandled Exception in MYPROGRAM.exe(third_party_dll.dll):0x00000005. Access Violation.

    I have examined and found that when i give this particular parameter, this code tries to execute a certain function which is written inside a dll(and declared in the corresponding header) . As soon as it tries to execute this function, the program crashes with the above mentioned errors. I do not have access to read the dll since it has been provided by a third party.

    I can only read the declaration of this function in the header file. This function was executing fine before the migration with its older version of dll. I have not made any changes in the code during migration.

    What can be the reasons and solution to this problem?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured