Solved

LoadLibrary fails

Posted on 2000-05-09
13
1,433 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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 200 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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
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…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

777 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