The MASM Forum

Projects => Poasm => Pelle's C compiler and tools => Topic started by: morgot on July 31, 2024, 12:49:35 AM

Title: How to set dllexport forward?
Post by: morgot on July 31, 2024, 12:49:35 AM
Hello
Please advise. I making DLL, and need to set an exportfunction that redirects to another function. In VC this is
LIBRARY dinput8
EXPORTS
DirectInput8Create = ProxyDirectInput8Create @1

But how to do it into Pelles? Its dont accept .def files, in code I only can set
__declspec(dllexport,naked) int ProxyDirectInput8Create()not redirect
Title: Re: How to set dllexport forward?
Post by: Vortex on July 31, 2024, 05:21:21 AM
Hello,

Not sure if this example is what you are looking for but it forwards functions to another DLL.

.386
.model flat,stdcall
option casemap:none

include    \masm32\include\windows.inc
include    \masm32\include\kernel32.inc
include    fwdfuncs.inc

includelib    \masm32\lib\kernel32.lib
includelib    fwdfuncs.lib

.data
message    db 'Hello from the forwarded function',0

.code

start:

    invoke  Cls                    ; forwarded to Console.ClearScreen
    invoke  szUpper,ADDR message
    invoke  ConOut,ADDR message    ; forwarded to Console.StdOut
    invoke  ExitProcess,0       

END start

Functions called from fwdfuncs.dll are forwarded to console.dll
Title: Re: How to set dllexport forward?
Post by: morgot on July 31, 2024, 06:35:47 AM
Thank you Vortex
Title: Re: How to set dllexport forward?
Post by: TimoVJL on August 01, 2024, 12:18:13 AM
With PEView you see this:
Title: Re: How to set dllexport forward?
Post by: morgot on August 01, 2024, 03:28:37 AM
TimoVJL
yes, but I don't build some secret soft. I want to build proxy-dll for DirectX
Title: Re: How to set dllexport forward?
Post by: TimoVJL on August 01, 2024, 06:09:16 AM
In a your first message you show an alias case, not forwanding.
Luckily Vortex helped you, as he had a crystal ball  :biggrin:
Title: Re: How to set dllexport forward?
Post by: morgot on August 01, 2024, 09:47:56 AM
Quoteshow an alias case, not forwanding.
Hrm... what difference?
Title: Re: How to set dllexport forward?
Post by: TimoVJL on August 01, 2024, 03:33:45 PM
alias make alias name for symbol in same module
forward make name for symbol to forward to other module
Title: Re: How to set dllexport forward?
Post by: morgot on August 03, 2024, 01:29:21 AM
Thank you Timo
But since you're here. How do I do this in Pelles C? VS knows .def files, PellesC not?
Title: Re: How to set dllexport forward?
Post by: Vortex on August 03, 2024, 04:35:16 AM
The aliases in module defintion files are problematic. Here is an example :

.def file :

LIBRARY ConsFuncs
EXPORTS

"_cls@0"=_ClearScreen@0
"_WriteConsole@4"=_StdOut@4
StrLen
locate

The new names are decorated in the DLL :

\PellesC\bin\podump.exe /exports ConsFuncs.dll
Dump of ConsFuncs.dll

        ordinal  hint  address   name
              1     0  1000100C  StrLen
              2     1  1000106D  _WriteConsole@4
              3     2  100010A3  _cls@0
              4     3  10001044  locate

Quick example calling the functions :

.386
.model flat, stdcall
option casemap :none

ExitProcess PROTO :DWORD

includelib \PellesC\lib\Win\kernel32.lib
includelib ConsFuncs.lib

cls PROTO
WriteConsole    PROTO :DWORD
StrLen          PROTO :DWORD
locate          PROTO :DWORD,:DWORD

.data

message         db 'Hello world!',13,10
                db 'This is a console application.',13,10,0

.code

start:

    invoke  StrLen,ADDR message ; just for testing
    invoke  cls
    invoke  WriteConsole,ADDR message                                               
    invoke  ExitProcess,0

END start
Title: Re: How to set dllexport forward?
Post by: Vortex on August 03, 2024, 05:04:33 AM
A better solution is to recreate the import library and avoid the mangled names in the DLL.

ConsFuncs.def :

LIBRARY ConsFuncs
EXPORTS

"cls"=_ClearScreen@0
"WriteConsole"=_StdOut@4
StrLen
locate

ConsFuncs2.def :

LIBRARY ConsFuncs
EXPORTS

"_cls@0"
"_WriteConsole@4"
"_StrLen@4"
"_locate@8"

Building the project :

\PellesC\bin\poasm /AIA32 ConsFuncs.asm
\PellesC\bin\polink /SUBSYSTEM:WINDOWS /DLL /DEF:ConsFuncs.def ConsFuncs.obj

\PellesC\bin\polib /MACHINE:x86 /DEF:ConsFuncs2.def /OUT:ConsFuncs.lib

\PellesC\bin\poasm /AIA32 Demo.asm
\PellesC\bin\polink /SUBSYSTEM:CONSOLE Demo.obj

\PellesC\bin\podump.exe /exports ConsFuncs.dll
Dump of ConsFuncs.dll

        ordinal  hint  address   name
              1     0  1000100C  StrLen
              2     1  1000106D  WriteConsole
              3     2  100010A3  cls
              4     3  10001044  locate
Title: Re: How to set dllexport forward?
Post by: Vortex on August 03, 2024, 05:58:55 AM
Hi morgot,

Reading the manual of Pelles C :

Quote/EXPORT option (POLINK)
 
Syntax:
/EXPORT:name [=internal-name] [,@ordinal [,NONAME]] [,DATA]

Description:
The /EXPORT option specifies a symbol to be exported from the linked executable. Symbols are normally exported from dynamic libraries, but programs may export symbols too.

The name argument specifies the name of the exported symbol. This is the externally visible name. The file exporting the symbol may optionally use a different internal name, specified by the internal-name argument. From version 5.0, a forward reference to another dynamic library may be created using the syntax libraryname.symbolname for internal-name. For example, mybeep=kernel32.Beep@8 will export the symbol mybeep, but point to the Beep function in kernel32.dll.
Title: Re: How to set dllexport forward?
Post by: morgot on August 03, 2024, 07:11:21 AM
Thank you Vortex! :thumbsup:  :azn: