Optional name mangling

Jonathan M Davis jmdavisProg at gmx.com
Sat Jul 21 13:06:45 PDT 2012


On Saturday, July 21, 2012 21:56:36 Alex Rønne Petersen wrote:
> On 21-07-2012 21:24, Stuart wrote:
> > Hi. Is there any way to instruct the D compiler not to use name mangling
> > when referencing an external C++ function?
> > 
> > For example:
> >     extern (System) bool PathRenameExtension(LPSTR pszPath, LPCSTR
> >     pszExt);
> > 
> > In this particular case, the exported function being referenced is not
> > called _PathRenameExtension at 8 - it's just called PathRenameExtension.
> > Now, it's great that D helpfully mangles the name for me when
> > appropriate, but we really need some way to disable it when necessary.
> > 
> > Is there any way to import this function without creating a .def file
> > with "_PathRenameExtension at 8 = PathRenameExtension"? And if not, why not?
> 
> Shouldn't you be using extern (Windows) ?

extern(System) should be fine in that it's the same as extern(Windows) on 
Windows, but since it's a Windows-specific function, it probably _should_  be 
using extern(Windows).

Of course, since PathRenameExtensions does what std.path.setExtension does, it 
would probably be better to just use that, but the OP's question _does_ apply 
to other functions which may not have D replacements, so the question is still 
relevant.

- Jonathan M Davis


More information about the Digitalmars-d mailing list