0

Есть решение, состоящее из двух проектов. Первый это статическая библиотека

.h

#pragma once
extern "C"
{
    char* _stdcall copystr(char*, char*);
    char* _stdcall sumstr(char*, char*);
    void _stdcall outstr(char*);
    void _stdcall outint(int);
    int _stdcall squareroot(int);
    char* _stdcall substr(char* s, char* ss);
}

.cpp

#include "stdafx.h"
#include "library.h"
#include <iostream>
#include <math.h>
#include <Windows.h>
#pragma warning(disable: 4996)
extern "C"
{
    char*  _stdcall copystr(char* str1, char* str2)
    {
        if (!str1 || !str2)
        {
            std::cout << "ERROR: Null string pointer in copystr function!!!" << std::endl;
            system("pause");
            ExitProcess(0);
        }
        else
            return strcpy(str1, str2);
    }
    char* _stdcall sumstr(char* str1, char* str2)
    {
        char* buf = new char[255];
        if (!str1 || !str2)
        {
            std::cout << "ERROR: Null string in sumstr function!!!" << std::endl;
            system("pause");
            ExitProcess(0);
        }
        strcpy(buf, str2);
        strcat(buf, str1);

        return  buf;

    }
    void _stdcall outstr(char* s)
    {
        if (s != nullptr)
            std::cout << s << std::endl;
        else
            std::cout << "Empty line!";
    }
    void _stdcall outint(int i)
    {
        std::cout << i << std::endl;
    }
    int _stdcall squareroot(int i)
    {
        return (int)std::pow(i, 2);
    }
}

Второй-проект ассемблера. Пытаюсь запустить данный код:

.586
.model flat, stdcall
includelib kernel32.lib
includelib libucrt.lib
includelib "D:/учёба/2 курс/ЯП/Курсовой/Debug/Lib.lib"

ExitProcess PROTO : DWORD
squareroot PROTO : DWORD
copystr PROTO : DWORD, : DWORD
sumstr PROTO : DWORD, : DWORD
outstr PROTO : DWORD
outint PROTO : SDWORD 
.stack 4096
.const
    overflow db 'ERROR: VARIABLE OVERFLOW', 0 
    null_division db 'ERROR: DIVISION BY ZERO', 0
    _Lit1 BYTE "as", 0
.data
.code

main PROC
    push offset _Lit1
    push offset _Lit1
    call sumstr
    push eax
    call outstr


    jmp EXIT
    EXIT_DIV_ON_NULL:
    push offset null_division
    call outstr
    push - 1
    call ExitProcess

    EXIT_OVERFLOW:
    push offset overflow
    call outstr
    push - 2
    call ExitProcess

    EXIT:

    push 0
    call ExitProcess

main ENDP
end main

При вызове функции sumstr на строке char* buf = new char[255]; выскакивает следующая ошибка в файле malloc_base.cpp:

Вызвано исключение по адресу 0x770CE066 (ntdll.dll) в ASM.exe: 0xC0000005: нарушение прав доступа при чтении по адресу 0x00000044

В чем может быть проблема?

1 ответ 1

0

Проблема в том, что не проинициализирован рантайм.
Не используйте фичи языка, которым нужен рантайм, например.

1
  • Можно подробнее? И это единственный выход?
    – Dikcha
    6 дек 2017 в 12:33

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.