Run DLL error Loading External Libraries

381 views
Skip to first unread message

Hayden Fisher

unread,
Jun 5, 2007, 8:56:51 AM6/5/07
to mapi...@googlegroups.com

Hi All,

 

Have defined a sub as follows, it is located for testing purposes where the dll is being developed everything is on my local drive. When I run the MBX the DLL runs perfectly it creates a dialog like I wanted.

Declare Sub CCadtrialApp Lib "C:\Program Files\Microsoft Visual Studio\Proj\trial\Debug\trial.dll"()

 

However when I close the dialog I get the following error:

Unable to load library trial.dll. Unable to link to external library C:\Program Files\Microsoft Visual Studio\Proj\trial\Debug\trial.dll. Unable to read application file.

 

The funny thing is that everything is running just fine, however I now need to clean this piece up. This is a regular DLL using shared MFC DLL.

 

Regards,

Hayden Fisher

Development and Support

BizeAsset Pty Ltd

sup...@bizeasset.com.au

 

Peter Horsbøll Møller

unread,
Jun 5, 2007, 2:08:39 PM6/5/07
to mapi...@googlegroups.com
Hayden,
 
Have you tried copying the dll to the applicationfolder - the same folder as the MapBasic application, and then remove the path from the sourcecode ?
This would be one place to actually put the dll when you are going to distribute it

Peter Horsbøll Møller
GIS Developer, MTM
Geographical Information & IT
 
COWI A/S
Odensevej 95
DK-5260 Odense S.
Denmark
 
Tel     +45 6311 4900
Direct  +45 6311 4908
Mob     +45 5156 1045
Fax     +45 6311 4949
E-mail  p...@cowi.dk
http://www.cowi.dk/gis

 


From: mapi...@googlegroups.com [mailto:mapi...@googlegroups.com] On Behalf Of Hayden Fisher
Sent: Tuesday, June 05, 2007 2:57 PM
To: mapi...@googlegroups.com
Subject: [MI-L] Run DLL error Loading External Libraries

Hayden Fisher

unread,
Jun 5, 2007, 8:46:54 PM6/5/07
to mapi...@googlegroups.com

Hi, Peter, yes same deal and error unfortunately.

 

Hayden Fisher

Development and Support

BizeAsset Pty Ltd

<BR

Oz

unread,
Oct 14, 2008, 10:02:11 AM10/14/08
to mapi...@googlegroups.com
Hi All,

I'm trying to call a dll from Map Basic for the first time.
Encountering the same problem as Hayden mentioned some time ago under
this topic.

I have a very simple dll as a sample, which works with VB, but when I
try to access it via MapBasic, I get the following error:

"Unable to load library mydll.dll. Unable to link to external library
C:\lib\mydll.dll. Unable to read application file."

Tried putting it in the same folder as the script itself, still the
same error.

I specifically tried with a script as simple as pasted below.
Would anyone be able to tell what I'm doing wrong?

Include "mapbasic.def"
Declare Sub mysum Lib "mydll.dll"
Declare Sub Main
Sub Main
Call mysum
End Sub

What would be a potential problem on the dll side that would cause it
not to be found/loaded?

Cheers,
Ozlem


Hi All,

Regards,

Hayden Fisher

Development and Support

BizeAsset Pty Ltd

supp...@bizeasset.com.au

Bill Thoen

unread,
Oct 14, 2008, 10:59:13 AM10/14/08
to mapi...@googlegroups.com
If your DLL is not a stdcall type, it won't work in MapBasic. Often VB
DLLs are cdecl format.

Oz

unread,
Oct 14, 2008, 11:30:43 AM10/14/08
to MapInfo-L
Hi Bill,

My dll is written in C++ and is an stdcall, VB is only used as an
interface to see if it works there first.
It works when called from a VB script but not when called from MB
script.
Any other ideas?

Ozlem
> > supp...@bizeasset.com.au- Hide quoted text -
>
> - Show quoted text -

Uffe Kousgaard

unread,
Oct 14, 2008, 11:34:06 AM10/14/08
to mapi...@googlegroups.com
Post the VB and MB headers for the DLL. Then someone may be able to spot the
error.

Regards
Uffe Kousgaard

Warren Vick

unread,
Oct 14, 2008, 11:40:06 AM10/14/08
to mapi...@googlegroups.com
Hi Ozlem,

Have you put extern "C" { } around the functions you want to use so they do not get C++ name mangling? This plus the _cdecl is all that should be needed.

Regards,
Warren Vick
Europa Technologies Ltd.
http://www.europa.uk.com

Eric_Bl...@mapinfo.com

unread,
Oct 14, 2008, 6:01:09 PM10/14/08
to mapi...@googlegroups.com

I would recommend the dependency walker tool (at http://dependencywalker.com/). With this tool you can look at your DLL and see what dependencies it has (which you may not be aware of). Depending on which version of Professional you have, you may have to put the other DLL files in a place on the system path.

The other issues that are talked about (CDECL vs STDCALL and name mangling are all important but I believe you would receive a different error in that case. The error should, in that case be...

"External library does not contain (name that MBX was looking for). Unable to read application file"

So I believe your problem is that Professional cannot find everything that the DLL is dependent on.

Dependency walker will tell you the exact names inside the DLL as well. In addition, you can tell if the function was compiled with CDECL or STDCALL by the name, at least from the Microsoft Compiler.

For C functions that are exported from a DLL, a cdecl function will just have the original name from the source code, whereas a stdcall function will have a prefixed underscore and a suffix of an "@" sign and a number indicating the number of bytes in the parameter list. For example, if your function was called "foo" (everyone loves foo) and took a double float (a FLOAT in MapBasic) then your function would be named _foo@8.

For C++ functions things are more complicated and much more compiler specific. The Microsoft Compiler would emit the following for cdecl

?foo@@YANN@Z

and this for stdcall.

?foo@@YGNN@Z

The difference is the A versus the G.

The dependency walker program has a very nice unmangler so you can see what the C++ format looks like although it does not show you the cdecl/stdcall part.

Eric Blasenheim
Chief Product Architect
Pitney Bowes Business Insight [MapInfo]



Mail List:grbounce-yvy1equaaaajbprysysrydkk7vpghp_9=mail_list=mapin...@googlegroups.com
From: Oz <Ozlem...@gmail.com> on 10/14/2008 08:30 AM MST
To: MapInfo-L <mapi...@googlegroups.com>
cc:

Oz

unread,
Oct 15, 2008, 12:47:46 PM10/15/08
to MapInfo-L
Thanks for all your responses guys!

Here's a response from a C++ expert, not on this list, who helped me
try a few different DLLs:

"Okay, I've looked into this -- there's a problem with debug symbols
included in the DLL made by MSVC 2005 (at least, may affect other
versions too), but, bizarrely only for projects without MFC. Not sure
what's causing it -- it does mean that you won't be able to debug the
DLL when running it from MapInfo/MapBasic."

So it looks like we have a quite specific problem!

If anyone finds/knows a solution for this, please let me know.

Ozlem

On Oct 14, 11:01 pm, Eric_Blasenh...@mapinfo.com wrote:
> I would recommend the dependency walker tool (athttp://dependencywalker.com/). With this tool you can look at your DLL and
> grbounce-yvy1equaaaajbprysysrydkk7vpghp_9=mail_list=mapinfo.com@googlegroup­s.com
> From:
> Oz <OzlemTur...@gmail.com> on 10/14/2008 08:30 AM MST
> > - Show quoted text -- Hide quoted text -
Reply all
Reply to author
Forward
0 new messages