The MASM Forum Archive 2004 to 2012

Project Support Forums => MASM32 => Topic started by: Hero on July 11, 2005, 05:36:26 AM

Title: A conflict between generated LIB files
Post by: Hero on July 11, 2005, 05:36:26 AM
Hi all
I want to ask a question about conflict between masm32 generated LIB files and VS ones.
I write a DLL using masm32.It generates an LIB files beside generated DLL files.When I use
that DLL in VS using LoadLibrary and GetProcAddr there is no problem.But When I try to use
LIB files and link it to program and use it(simillar to what I can do for VS genearted LIB files)
according to an unknown reason,the VS link error accures that say :"Unable to resolve external
symbol.....".
Why this happens?How I can solve this problem and use generated masm32 lib files in VS?

sincerely yours
Title: Re: A conflict between generated LIB files
Post by: hutch-- on July 11, 2005, 05:49:39 AM
Hero,

The only thing that can produce this effect is name conflicts for library module names. Another thing to keep in mind is you must prototype the procedures as EXTERN so the mangling does not occur.
Title: Re: A conflict between generated LIB files
Post by: Hero on July 11, 2005, 08:32:38 AM
Thanks for quick reply.
But I don't get what you mean by "you must prototype the procedures as EXTERN".
This is my sample:
(I only written required codes)
testdll.asm:

      .code

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

LibMain proc instance:DWORD,reason:DWORD,unused:DWORD

    .if reason == DLL_PROCESS_ATTACH
      push instance
      pop hInstance
      mov eax, TRUE

    .elseif reason == DLL_PROCESS_DETACH

    .elseif reason == DLL_THREAD_ATTACH

    .elseif reason == DLL_THREAD_DETACH

    .endif

    ret

LibMain endp

testfunc proc
invoke MessageBoxA,NULL,addr tester,addr tester,MB_OK
ret
testfunc endp

end LibMain

testdll.def:
LIBRARY testdll
EXPORTS testfunc

and my sample VS program:
//Declare header
extern "C" void testfunc();

void CTestDlg::OnBnClickedOk()
{
testfunc();
OnOK();
}


What is the problem with this code?

sincerely yours
Title: Re: A conflict between generated LIB files
Post by: hutch-- on July 11, 2005, 08:42:16 AM
Quick look says it should work. Make sure of this much that you match the calling conventions in both the assembler procedure and the C ptototype you write for your C source code. This is probably what the problem is.
Title: Re: A conflict between generated LIB files
Post by: Hero on July 12, 2005, 04:35:59 AM
Thanks for help! :U
I finnaly find out waht is the problem,I should export function with "C" calling mode:
LibMain endp

testfunc proc [color=Red]C[/color]
invoke MessageBoxA,NULL,addr tester,addr tester,MB_OK
ret
testfunc endp

end LibMain

But I want o know something else know.
The generated lib file,Is only something that reference to dll file.
Is there anyway that this lib file generated and there is no need for dll file existance?

sincerely yours
Title: Re: A conflict between generated LIB files
Post by: Vortex on July 12, 2005, 05:41:23 AM
If you are usink MS link to link your object files, you will need the import library created for your DLL. Jeremy Gordon's GoLink doesn't require import libraries.
Title: Re: A conflict between generated LIB files
Post by: hutch-- on July 12, 2005, 06:13:09 AM
Hero,

That cannot be done as the binary code exists in the DLL, not the import library. The import library basically holds data for the linker, not the actual binary code itself.