?
Solved

LoadLibrary fails

Posted on 2000-05-09
13
Medium Priority
?
1,462 Views
Last Modified: 2013-12-03
I have a .EXE which depends on DLL A.  The .EXE uses LoadLibrary to load DLL B, which also depends on DLL A.  The LoadLibrary call on DLL B failes, reporting "invalid access to memory location" in its static initializer.  The static initializer for DLL B is using static data from DLL A, and fails whether trying to assign to that static data or invoke a method which likely also modifies the static data.

This application is *not* using MFC or MFC shared libs.

 How can I fix this?  What's causing the memory fault?
0
Comment
Question by:twall
  • 7
  • 6
13 Comments
 
LVL 15

Expert Comment

by:NickRepin
ID: 2794492
So you export the data, not functions only, from the A?
Could you show the code related to the static data?
0
 
LVL 1

Author Comment

by:twall
ID: 2794550
Yes, both data and functions are exported from A.

Here's the static declaration, from DLL A:

namespace NS { vector<CORBA::Narrow_proto> * BasicType::_narrow_helpers; };

Here's the access, from DLL B:

struct _global_init_MYPLUGIN_DerivedType {
  _global_init_MYPLUGIN_DerivedType()
  {
    vector<CORBA::Narrow_proto>* vec = ::NS::BasicType::_narrow_helpers;
    if( vec == NULL )
        vec = ::NS::BasicType::_narrow_helpers = new vector<CORBA::Narrow_proto>;
    vec->push_back( MYPLUGIN::DerivedType::_narrow_helper2 );
  }
} __global_init_MYPLUGIN_DerivedType;
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 2794593
Probably it would be easier to use the function thunks, but not to export the data directly.

Like this

A:
 
__declspec(dllexport) void SetNarrowHelpers(p)
{
   ::NS::BasicType::_narrow_helpers=p;
}

__declspec(dllexport) HelperType GetNarrowHelpers(p)
{
   return ::NS::BasicType::_narrow_helpers;
}
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 1

Author Comment

by:twall
ID: 2794609
Maybe, except that the code is auto-generated (by the CORBA IDL compiler).  Is there something inherently wrong with data access from DLL to DLL?  Obviously the data access works from .EXE to DLL.
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 2794705
Hard to say. Probably, the problem is as follows.

The .h file [may be] declares the static data differently for EXE (as imported) and DLL (as exported).

It is correct as long as you use this header in the EXE and in the DLL that exports the data (A).

But for B.DLL, the data must be declared as IMPORTED as well, but not as exported (the header file may detect that it is compiled in DLL mode and make the data exported).
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 2794716
BTW, do you think that it's twice easier to answer your question in this area than in the C++ one?
0
 
LVL 1

Author Comment

by:twall
ID: 2794733
Adjusted points from 100 to 200
0
 
LVL 1

Author Comment

by:twall
ID: 2794787
We are generating .DEF files that indicate all the exports. DLL B gets its class definitions from the original class header file, which has no declspecs in it.
0
 
LVL 1

Author Comment

by:twall
ID: 2794811
Wrapping the static data in static functions results in the same memory fault when trying to set the vector.
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 2795165
What is the .DEF file you use?
0
 
LVL 15

Accepted Solution

by:
NickRepin earned 600 total points
ID: 2795177
0
 
LVL 1

Author Comment

by:twall
ID: 2797181
And the answer is:

The .DEF file *does not* require "DATA" after all the data members being exported.

DLL B *does* require that the headers that it uses for DLL A use __declspec(dllimport) in order to access the data correctly.

Thanks, Nick.

0
 
LVL 1

Author Comment

by:twall
ID: 2797212
The second reference indicates part of what is necessary.

DATA is not required in the .DEF file.
__declspec(dllimport) *is* required in the headers from DLL A which are used by DLL B.

Thank you Nick.
0

Featured Post

Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question