الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

Error1error C2415: improper operand type [inline Assembly]

بدأه hakouabs في 27 يونيو 2016 · 2 رد · 2,735 مشاهدة · في لغة C و ++C
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ورحمة الله تعالى وبركاته 
 

#include<Windows.h> 
#include<iostream>
int main(){
	MessageBox(0, L"", L"", 0);
	char hello[] = "Hello";
	char world[] = "world";
	FARPROC Ms = GetProcAddress(GetModuleHandle(L"user32.dll"), "MessageBoxA");
	__asm {
		push 0
			mov  eax, offset world
			push eax
			mov  eax, offset hello
			push eax
			push 0
			call Ms
			pop  ebx
			pop  ebx
			pop  ebx
			pop  ebx
	}
}

الخطاء  Error    1    error C2415: improper operand type  
ممكن طريقة اصلاح هذا الخطاء    

1
#2

offset تستخدم إذا كان بإمكانك تحديد العنوان أثناء الترجمة كما في حالة المتغيرات العامة، لكن عندك world و hello متغيرات محلية، إما أن تجعلها متغيرات عامة:

#include<Windows.h>
char hello[] = "Hello";
char world[] = "world";
int main(){
    MessageBox(0, L"", L"", 0);
    FARPROC Ms = GetProcAddress(GetModuleHandle(L"user32.dll"), "MessageBoxA");
    __asm {
        push 0
        mov  eax, offset world
        push eax
        mov  eax, offset hello
        push eax
        push 0
        call Ms
    }
}

أو تستخدم lea إذا كنت تريد إبقاءهما محلية:

#include<Windows.h>
int main(){
    MessageBox(0, L"", L"", 0);
    FARPROC Ms = GetProcAddress(GetModuleHandle(L"user32.dll"), "MessageBoxA");
    char hello[] = "Hello";
    char world[] = "world";
    __asm {
        push 0
        lea  eax, world
        push eax
        lea  eax, hello
        push eax
        push 0
        call Ms
    }
}

أيضاً لابد من حذف تعلميات التنظيف pop لأن MessageBoxA تستخدم طريقة stdcall في الإستدعاء وهنا المستدعى عليه مسؤولية تنظيف المكدس وليس أنت المستدعي.

تم تعديل هذه المشاركة بواسطة Mr.B في 28 يونيو 2016 في 01:18

5▲ 2
#3

بارك الله فيك اخي 

Mr.B

مواضيع مشابهة