Export ASM function from DLL - Visual Studio C ++

I created a Dll project. I created a myasm.asm file that has one function:

 .486
.model flat, stdcall
.code
MyProc1 proc x: DWORD, y: DWORD
    xor eax,eax
//......//
    ret
MyProc1 endp
    end

There is my heade file:

#pragma once

#include <Windows.h>

#ifdef LAB1DLL_EXPORTS
#define LAB1DLL_API __declspec(dllexport)
#else
#define LAB1DLL_API __declspec(dllimport)
#endif

extern "C"
{
    LAB1DLL_API int _stdcall MyProc1(DWORD x, DWORD y);
}

And dllMain (begging) "

#define LAB1DLL_EXPORTS 1
#include "Lab1Dll.h"

I got my test application in which I want to use this DLL and exported the function that I have:

#include "Lab1Dll.h"

But my dll does not export my function MyProc1. If I add a β€œnormal” function to this DLL and exprot, it will be avilable in my Test application, and the compilation process of the DLL creates a lib file.

Without the "normal" functions, I do not get a .lib file. And I can not reference this library.

How to make this exported function work? Or how to do it first?

UPDATE: , .def . . . , __declspec (dllexport)?

LIBRARY

EXPORTS

MyProc1
+4
3

(DLL/EXE) , DLL. , , . __impl_SRFlushCache SRFlushCache, ​​ . , - __impl_, extern "C", - .

, (.def) , :

LIBRARY SRPlatform
EXPORTS
  SRFlushCache

:

:

#ifdef SRPLATFORM_EXPORTS
#define SRPLATFORM_API __declspec(dllexport)
#else
#define SRPLATFORM_API __declspec(dllimport)
#endif // SRPLATFORM_EXPORTS

SRPLATFORM_API void __fastcall SRFlushCache(const void *pFirstCl, const void *pLimCl, const size_t clSize);

.asm:

_DATA SEGMENT

_DATA ENDS

_TEXT SEGMENT

PUBLIC SRFlushCache

; RCX=pFirstCl
; RDX=pLimCl
; R8=clSize
SRFlushCache PROC

SRFlushCache_Loop:
  clflushopt byte ptr [RCX]
  add RCX, R8
  cmp RCX, RDX ; RCX-RDX
  jl SRFlushCache_Loop
  ret

SRFlushCache ENDP

_TEXT ENDS

END
+2

MASM __declspec(dllexport) EXPORT , proc

, .drectve *.obj, masm .

.386
.model flat, stdcall
.code
MyProc1 proc EXPORT x: DWORD, y: DWORD
    xor eax,eax
    ret
MyProc1 endp
end

, MyProc1 extern "C" ,

MyProc1 proc C EXPORT x: DWORD, y: DWORD

MyProc1 proc stdcall EXPORT x: DWORD, y: DWORD

+1

, :

  • __declspec (dllexport)

  • EXPORTS .def

  • /EXPORT LINK

  • Comment directive in source code of the form #pragma comment (linker, "/ export: definition").

Source

origin

0
source

Source: https://habr.com/ru/post/1528815/


All Articles