The MASM Forum Archive 2004 to 2012

Specialised Projects => Compiler Based Assembler => Pelle's C compiler and tools => Topic started by: Dav92 on April 07, 2012, 09:26:31 PM

Title: disable name mangling of imported functions
Post by: Dav92 on April 07, 2012, 09:26:31 PM
Hi,

I just got problems with a couple of functions, I need to use from an extern dll.
If I prototype the function as following: int xxxxy();
I can use it as I wish, but I won't get an error if I acidently call it with the wrong number of arguments.
If my protype looks like following: int xxxxy(DWORD*,DWORD,DWORD);
Then the linker complains since it looks for _xxxxy@12, but since I only have the lib and there the function is declared as _xxxxy the linker can't find it.

Is there a compiler-option for disabling this name mangling?


Thanks in advance
Title: Re: disable name mangling of imported functions
Post by: MichaelW on April 08, 2012, 02:30:13 AM
Have you tried the /Gm option?
Title: Re: disable name mangling of imported functions
Post by: Vortex on April 08, 2012, 07:46:31 AM
Hi Dav92,

You can recreate the import library without decorated names :

/NOUND             Don't add underscore to import names
Title: Re: disable name mangling of imported functions
Post by: Dav92 on April 08, 2012, 09:32:17 AM
QuoteHave you tried the /Gm option?

Thanks, that indeed solved the problem. But created another one. The windows api functions use the standard nameing conventions, so is there a way to use the /Gm only for specific functions?

QuoteYou can recreate the import library without decorated names

Thanks, but the underscores aren't the problem. The problem is the @.. The lib got created without knowing the number of args or the calling convention for the functions.
Title: Re: disable name mangling of imported functions
Post by: Vortex on April 08, 2012, 09:42:38 AM
Hi Dav92,

Another solution would be to recreate the same library with decorated symbols. (http://www.masm32.com/board/index.php?topic=6390.0) Could you post the exact list of functions with the number of parameters?
Title: Re: disable name mangling of imported functions
Post by: Dav92 on April 08, 2012, 10:41:59 AM
That's the problem. most of the functions I haven't used so far, so I don't know the parameters of them.

But since I wrote myself the def-file I can easily recreate the lib if I use a new function with the number of parameters.
I'll write a small batch-file for creating the lib and then just recreate it everytime I use a new function
Title: Re: disable name mangling of imported functions
Post by: Vortex on April 08, 2012, 11:19:17 AM
Hi Dav92,

The code below is not a perfect solution but it seems to work :


extern int MessageBoxA();

int __stdcall MessageBox(int x,char *y,char *w,int z)
{
    int temp;

__asm{
push  z
mov   eax,w
push  eax
mov   eax,y
push  eax
push  x
call  MessageBoxA
mov   temp,eax
}

    return temp;
}


int __stdcall WinMain(int hInstance, int hPrevInstance,char *lpCmdLine, int nCmdShow)
{
    MessageBox(0,"Undecorated function call","Hello",0);
    return 0;
}
Title: Re: disable name mangling of imported functions
Post by: Dav92 on April 08, 2012, 11:37:11 AM
Yes, that would work, but would be too much work^^

I think I'll just stick with recreating the lib every time I use a new function.