What can cause the error:

Attempting to read or write protected memory. This often indicates that the other memory is damaged.

A project is written in c # and dll in c ++, compiled separately without errors, but when you run the project, it reaches the second function (written in dll) and gives this error.

    1 answer 1

    This means that you are trying to write or read to a memory address that does not belong to your program. For example, you can write or read memory outside of a dynamically allocated array, or access memory using a null pointer.

    The fact that the program is compiled does not mean that it is correct.

    • "or access memory by null-pointer" - in most cases there will not be such an error. At least in sharpe. - Qwertiy
    • @Qwertiy As I understand it, the error occurs when you call the C ++ function from the dll. - Vlad from Moscow
    • But after all sharpe unwraps calls to addresses less than 65K in a NullReferenceException, and large ones spill out with access violation. Does the situation change if the corresponding treatment occurs in the code on the pluses? - Qwertiy
    • @Qwertiy How do you know what is being done in a C ++ function? Maybe there is an attempt to change the string literal, or there is a memory allocation, or a string is compared using a null pointer, or an incorrect Windows API call occurs. - Vlad from Moscow
    • I meant the situation: the code in C ++ refers to the zero pointer (well, somewhere near). Doesn't the calling code on Sharpe turn it into a NullReferenceException according to its rules? From where now appeared about an incorrect call or change readony - I did not argue with it. - Qwertiy