"Overwriting" external Functions

Discussion forum about all things Team Developer 5.x and 6.x
maxdirndorfer
Germany
Posts: 4
Joined: 13 Jun 2018, 09:14
Location: Germany

"Overwriting" external Functions

Post by maxdirndorfer » 26 Nov 2018, 14:36

Hi,

I have a library (apl) which is loading an External Function from GDI32.DLL. The library is doing it wrong, but I cannot change the library. I would like to load the External Function with the correct parameters, but I get a Duplicate symbol error.
Is there a way to "overwrite" the external Function without changing the library?

Thanks in advance Max

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 2928
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

Re: "Overwriting" external Functions

Post by Dave Rabelink » 26 Nov 2018, 19:58

maxdirndorfer wrote:
26 Nov 2018, 14:36
The library is doing it wrong, but I cannot change the library.
Hi Max,

Why can the library function not be changed? If the function is wrong, I would expect that fixing it would be best.

As for your question:

Exported Functions can be defined two ways:

1) Function name exactly matches the name as defined by the DLL. The ordinal number must be 0 (zero)
2) Any function name is allowed but the ordinal number must match.

The easiest and IMHO the most "safe" way is option 1. Here, when you compile your project, TD will load the DLL at compile time and check whether the function name you provided is present in the DLL.
This makes you sure that the function you call is actually present.

The second option is to use the ordinal number and choose your function name as you like.
TD will not check the function name at compile time and "assumes" the function having the declared parameters etc is present.
Danger is that if you provide the wrong ordinal number, you will get crashes at runtime.

(so I opt for option 1).

Below a screenshot of the same function (gdi32.dll, LineTo) defined using ordinal 0 (exact function name) and 2 custom names.

ExportOrdinal.png

I recommend to use a tool to find out the ordinal number to choose: DLL Export Viewer

http://www.nirsoft.net/utils/dll_export_viewer.html
You do not have the required permissions to view the files attached to this post.
Regards,
Dave Rabelink

Image
Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel

maxdirndorfer
Germany
Posts: 4
Joined: 13 Jun 2018, 09:14
Location: Germany

Re: "Overwriting" external Functions

Post by maxdirndorfer » 27 Nov 2018, 07:35

Thank you for your very detailed answer! It helps a lot, so I have a solution with the ordinal number but as u recommended I try to get the library redone as well.

Many thanks!
Max

Return to “General Discussion”

Who is online

Users browsing this forum: [Ccbot] and 0 guests