Assembler + WinApi
Формулировка задачи:
Не получается соединить два модуля(один - ассемблер, второй - winapi), ошибки LNK2019, LNK1120. Может у кого-то был уже подобный опыт?
//------------------------------------модуль на ассемблере-------------------------------------------
#include "stdafx.h" #include "assemANDwinapi.h" extern "C" void StrDel(char*a, int m); #define MAX_LOADSTRING 100 #define ID_EDIT 1001 #define ID_EDIT1 1003 #define ID_BUTTON 1002 // Global Variables: char *chint = new char[20]; char *chBuff; int n; static HDC hdc; HINSTANCE hInst; // current instance WCHAR szTitle[MAX_LOADSTRING]; // The title bar text WCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name // Forward declarations of functions included in this code module: ATOM MyRegisterClass(HINSTANCE hInstance); BOOL InitInstance(HINSTANCE, int); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM); int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); // TODO: Place code here. // Initialize global strings LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadStringW(hInstance, IDC_ASSEMANDWINAPI, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); // Perform application initialization: if (!InitInstance (hInstance, nCmdShow)) { return FALSE; } HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_ASSEMANDWINAPI)); MSG msg; // Main message loop: while (GetMessage(&msg, nullptr, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return (int) msg.wParam; } ATOM MyRegisterClass(HINSTANCE hInstance) { WNDCLASSEXW wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ASSEMANDWINAPI)); wcex.hCursor = LoadCursor(nullptr, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_ASSEMANDWINAPI); wcex.lpszClassName = szWindowClass; wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)); return RegisterClassExW(&wcex); } BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { hInst = hInstance; // Store instance handle in our global variable HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr); if (!hWnd) { return FALSE; } ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); return TRUE; } LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { static HWND hEdit, hEdit1, hButton; switch (message) { case WM_CREATE: //if(message==LOWORD(wParam)) hEdit = CreateWindow("edit", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT, 80, 10, 250, 20, hWnd, (HMENU)ID_EDIT, hInst, NULL); hEdit1 = CreateWindow("edit", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT, 400, 10, 420, 20, hWnd, (HMENU)ID_EDIT1, hInst, NULL); hButton = CreateWindow("button", "ENTER", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 87, 45, 237, 100, hWnd, (HMENU)ID_BUTTON, hInst, NULL); break; case WM_COMMAND: { int wmId = LOWORD(wParam); // Parse the menu selections: switch (wmId) { case ID_BUTTON: SendMessage(hEdit, EM_GETLINE, 0, (LPARAM)chint); n = atoi(chint); chBuff = new char[n]; SendMessage(hEdit, EM_GETLINE, 0, (LPARAM)chBuff); StrDel(chBuff,n); TextOut(hdc, 80, 152, (LPSTR)chBuff, n); break; case IDM_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } } break; case WM_PAINT: { PAINTSTRUCT ps; HDC hdc = BeginPaint(hWnd, &ps); TextOut(hdc, 10, 12, "ENTER: ", 7); TextOut(hdc, 10, 152,"OUTPUT: ", 8); // TODO: Add any drawing code that uses hdc here... EndPaint(hWnd, &ps); } break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; } // Message handler for about box. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { UNREFERENCED_PARAMETER(lParam); switch (message) { case WM_INITDIALOG: return (INT_PTR)TRUE; case WM_COMMAND: if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { EndDialog(hDlg, LOWORD(wParam)); return (INT_PTR)TRUE; } break; } return (INT_PTR)FALSE; }
.386 .model flat .data .code PUBLIC _StrDel _StrDel PROC push edi push ebx push esi mov edx, [esp+20] mov ecx, [esp+16] mov edi, [edp+20] xor eax, eax mov al, ' ' cld ;-----------------------------------------------// repe scasb jecxz c4 ;-----------------------------------------------// mov ebx, edi dec ebx repne scasb push ecx mov ecx, edi sub ecx, ebx push edi mov edi, edx mov esi, ebx rep movsb mov edx, edi pop edi pop ecx ;-----------------------------------------------// cmp ecx, 0 jnz c1 ;-----------------------------------------------// c1 : repe scasb jecxz c4 ;-----------------------------------------------// mov ebx, edi dec ebx cmp[ebx], ';' jne m1 dec edx ;-----------------------------------------------// m1 : repne scasb ;-----------------------------------------------// push ecx mov ecx, edi sub ecx, ebx push edi mov edi, edx mov esi, ebx rep movsb mov edx, edi pop edi pop ecx ;-----------------------------------------------// cmp ecx, 0 jnz c1 ;-----------------------------------------------// c4 : ;-----------------------------------------------// mov edi, [esp+20] add edi, [esp+16] cmp edx, edi je c5 cmp[edx - 1], ' ' jnz c2 dec edx ;-----------------------------------------------// c2 : mov[edx], 0 c5 : pop esi pop ebx pop edi ret _StrDel endp end
Решение задачи: «Assembler + WinApi»
textual
Листинг программы
mov edi, [edp+20]
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д