Solved

LoadLibrary fails

Posted on 2000-05-09
13
1,436 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…

789 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