View previous topic :: View next topic |
Author |
Message |
KennyT
Joined: 02 Aug 2005 Posts: 318
|
Posted: Wed Aug 08, 2012 3:14 pm Post subject: Trying to link to a 3rd-party DLL... |
|
|
...and at run time, it insists that the DLL should be in the c:\ root folder, rather than searching in the "current" folder.
Anyone got any ideas where to start when trying to solve this?
K |
|
Back to top |
|
 |
ebarbero
Joined: 01 Aug 2012 Posts: 20
|
Posted: Wed Aug 08, 2012 8:15 pm Post subject: |
|
|
.NET or win32 project? do you use !dec$ attributes dllimport:: ??? _________________ http://www.cadec-online.com/ |
|
Back to top |
|
 |
KennyT
Joined: 02 Aug 2005 Posts: 318
|
Posted: Thu Aug 09, 2012 7:26 am Post subject: |
|
|
I'm working in Win32. The DLL is an "unmanaged" wrapper for a .NET project.
I don't use "!dec$ attributes dllimport::" (I can't see any help on it either?)
K |
|
Back to top |
|
 |
ebarbero
Joined: 01 Aug 2012 Posts: 20
|
|
Back to top |
|
 |
KennyT
Joined: 02 Aug 2005 Posts: 318
|
Posted: Fri Aug 10, 2012 8:14 am Post subject: |
|
|
Perhaps I didn't explain the problem clearly enough!
I am building my application using win32. The third party application is written in .NET. Their programmer has supplied an "un-managed" wrapper for some of their functionality such that I can use the STDCALL technique to call them via my own set of wrappers, e.g.
Code: |
!int ILogReadings_get_Index(ref long instance)
SUBROUTINE IP_ILogReadings_get_Index ( INSTANCE, RET)
INTEGER*4 :: RET
STDCALL IP_ILogReadings_get_Index_ 'ILogReadings_get_Index'(REF) : INTEGER*4
INTEGER*8 :: instance
RET = IP_ILogReadings_get_Index_ ( INSTANCE)
END SUBROUTINE
|
This all works, provided their DLL exists in the c:\ root folder at run time, which is not really a long term solution, when it comes to distributing to customers!
So, the bottom line is:
Why must their DLL be in the root folder for my application to run? Why can't the runtime load find it in the application folder?
K |
|
Back to top |
|
 |
ebarbero
Joined: 01 Aug 2012 Posts: 20
|
Posted: Fri Aug 10, 2012 5:37 pm Post subject: |
|
|
I am sorry I misinterpreted your question.
It is really odd to ask for the dll to be in c:, but perhaps you can modify the path variable to point in the directory you have the dll. Would that solve the problem? _________________ http://www.cadec-online.com/ |
|
Back to top |
|
 |
KennyT
Joined: 02 Aug 2005 Posts: 318
|
Posted: Sat Aug 11, 2012 8:57 am Post subject: |
|
|
Some more information about how the third party app calls the DLL functions...
It appears that the DLL exports are "resolved" at runtime, rather than link time. Some test source they sent me has the folllowing call:
HINSTANCE hinstLib = LoadLibrary(TEXT("API.NativeExports.dll"));
Do we have the equivalent ability in FTN95?
edit: This extract from the FTN95 help pages sounds "interesting"!
Quote: |
A Visual Basic program can use calls to the API functions LoadLibrary and FreeLibrary in order to ensure that the DLL does not unload whilst a Visual Basic form is loaded.
...
The FTN95 DLL is assumed to reside in the Windows system directory.
|
K |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8210 Location: Salford, UK
|
Posted: Sun Aug 12, 2012 8:14 am Post subject: |
|
|
I have never heard of anyone trying to access a .NET dll assembly from a Win32 executable before so I don't know if this can be done. Certainly, for me, you are working in uncharted waters.
The comment that you have picked up from the documentation about VB does not seem to be relevant.
DLL exports are always resolved at runtime. By default (for FTN95) they are resolved when the program is loaded but it is possible to to delay the resolving to the point when the function is called (depending on the commands used with SLINK). However, this does help with your initial problem.
Can you get the dll to work when you put it in the root folder as requested?
You can call LoadLibrary from FTN95 to see if the library is visible and loadable but there is no easy way to use the result of GetProcAddress but, again, this does not appear to be the issue here. |
|
Back to top |
|
 |
KennyT
Joined: 02 Aug 2005 Posts: 318
|
Posted: Sun Aug 12, 2012 9:12 am Post subject: |
|
|
Hi Paul,
Yes, the DLL works if placed in the root folder. If it's not there, I get the following message:
"The program can't start because \API.NativeExports.dll is missing from your computer. Try reinstalling the program to fix this problem".
"depends" also highlights the DLL as "not found".
I realise I'm a bit "out on a limb"!
As I understand it the 3rd party DLL is an "unmanaged" wrapper around "managed" functions but, as I don't use .NET, I don't really understand what that means!
Are there any other tools that can investigate whether the "\" is embedded in the DLL (ie their fault!) or somewhere that FTN95 or SLINK can have an effect on?
K
edit: I can call "LoadLibrary" and get a return value of 1661534208 (presumably just not being zero indicates success?) with just the local copy of the DLL being present.
2nd edit: Paul, you mention that the resolution of the externals depends on the slink commands used. Here's my link script for my DLL - what could I be doing different?
Code: |
dll
lo test_sub
lo sub1 !these contain my "wrappers"
lo API.NativeExports.dll
exportall
file test
|
K |
|
Back to top |
|
 |
KennyT
Joined: 02 Aug 2005 Posts: 318
|
Posted: Sun Aug 12, 2012 10:34 am Post subject: |
|
|
Did some more tests...
Code: | strings API.NativeExports.dll | grep -i native |
and got this output!
API.NativeExports.dll
API.NativeExports
\API.NativeExports.dll
Which, I think, puts the ball back in the court of the 3rd party! Something, somewhere, when they�re building their DLL, is specifying that the �name� of the DLL when passed to the runtime loader, is:
\API.NativeExports.dll
K |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8210 Location: Salford, UK
|
Posted: Sun Aug 12, 2012 2:19 pm Post subject: |
|
|
If you use
rlo API.NativeExports.dll
in your SLINK script then the program will start running but will probably fail when the program calls a function in the dll. |
|
Back to top |
|
 |
KennyT
Joined: 02 Aug 2005 Posts: 318
|
Posted: Tue Aug 14, 2012 1:16 pm Post subject: |
|
|
Hopefully resolved. The 3rd-party has relinked his DLL and got rid of the "\".
thanks
K |
|
Back to top |
|
 |
|