Search code examples
c++assemblystatic-librariesmasm32

Using lib compiled in masm in c++


im trying to make a lib in masm32 (using radasm) for use in other projects...

the libs source code :

.386
.MODEL flat,stdcall
option casemap:none
.code
start:
PUBLIC HookProc
HookProc proc addy:DWORD

and for use in msvc :

extern "C" void* HookProc(void* ptr);
#pragma comment(lib, "TestHook.lib")

however this produces an error :

Win32Project1.obj : error LNK2019: unresolved external symbol _HookProc referenced in function _wmain

but i see in the lib there is

!<arch>
/               1368690603              0       20        `
®_HookProc@4/               1368690603              0       26        `

Why cant msvc see this proc in the lib ?? ;/ does this have something to do with the @4 ?

Edit : changed to .MODEL flat, c that got rid of @4 , but still _HookProc uresolved......


Solution

  • CPP:

    extern "C" int GetValue(void);
    
    int main(int argc, char*arg[])
    {
        char *p = "test";
        int v = GetValue();
    
        return 0;
    }
    

    ASM:

    .486
    .model flat, C
    option casemap :none
    
    .code
    
    GetValue PROC
        mov eax, 1234
        ret
    GetValue ENDP
    
    END