473,322 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Access violation in unmanaged code: Linking managed with unmanaged static libs

Hi, Gurus,

I recently attempted to build a .Net forms application, that links
with old style unmanaged C++ static libs.
Of course I had to recompile the static lib projects to link properly
with the managed application.

My questions are two fold:

[1] The managed project uses /clr and /MDd (in debug) options. The
unmanaged project, when set to build with /clr, and /MDd, gives link
errors with the managed project:

1>Linking...
1>dcmdataD.lib(dcfilefo.obj) : error LNK2022: metadata operation
failed (8013118D) : Inconsistent layout information in duplicated
types (OFConsole): (0x0200007c).
1>dcmdataD.lib(dcfilefo.obj) : error LNK2022: metadata operation
failed (8013118D) : Inconsistent layout information in duplicated
types (OFGlobal<bool>): (0x020000bd).
1>dcmdataD.lib(dcsequen.obj) : error LNK2022: metadata operation
failed (8013118D) : Inconsistent layout information in duplicated
types (OFConsole): (0x0200007e).
......

Why?
[2] If I change the unmanaged project to build with no clr option, it
then links fine with the managed application module. However, this
time I get a run time access violation as soon as the first global
variable is declared inside the unmanaged code:

/* ---------- global condition constants ---------- */
>>exception here>const OFConditionConst ECC_Normal( 0, 0, OF_ok, "Normal");
Why?

I am very much exhausted with things to try.

Any input will be much appreciated.

Thanks.

Pixel.To.Life
[http://groups.google.com/group/medicalimagingscience]

Jul 20 '07 #1
3 2833
On Jul 20, 12:01 am, "Pixel.to.life" <pixel.to.l...@gmail.comwrote:
Hi, Gurus,

I recently attempted to build a .Net forms application, that links
with old style unmanaged C++ static libs.
Of course I had to recompile the static lib projects to link properly
with the managed application.

My questions are two fold:

[1] The managed project uses /clr and /MDd (in debug) options. The
unmanaged project, when set to build with /clr, and /MDd, gives link
errors with the managed project:

1>Linking...
1>dcmdataD.lib(dcfilefo.obj) : error LNK2022: metadata operation
failed (8013118D) : Inconsistent layout information in duplicated
types (OFConsole): (0x0200007c).
1>dcmdataD.lib(dcfilefo.obj) : error LNK2022: metadata operation
failed (8013118D) : Inconsistent layout information in duplicated
types (OFGlobal<bool>): (0x020000bd).
1>dcmdataD.lib(dcsequen.obj) : error LNK2022: metadata operation
failed (8013118D) : Inconsistent layout information in duplicated
types (OFConsole): (0x0200007e).
.....

Why?

[2] If I change the unmanaged project to build with no clr option, it
then links fine with the managed application module. However, this
time I get a run time access violation as soon as the first global
variable is declared inside the unmanaged code:

/* ---------- global condition constants ---------- */
>exception here>const OFConditionConst ECC_Normal( 0, 0, OF_ok, "Normal");

Why?

I am very much exhausted with things to try.

Any input will be much appreciated.

Thanks.

Pixel.To.Life
[http://groups.google.com/group/medicalimagingscience]
More information:

The application executes fine in a release build configuration. It
just doesnt let me debug in...

Jul 20 '07 #2

"Pixel.to.life" <pi***********@gmail.comwrote in message
news:11**********************@m37g2000prh.googlegr oups.com...
Hi, Gurus,

I recently attempted to build a .Net forms application, that links
with old style unmanaged C++ static libs.
Of course I had to recompile the static lib projects to link properly
with the managed application.

My questions are two fold:

[1] The managed project uses /clr and /MDd (in debug) options. The
unmanaged project, when set to build with /clr, and /MDd, gives link
errors with the managed project:

1>Linking...
1>dcmdataD.lib(dcfilefo.obj) : error LNK2022: metadata operation
failed (8013118D) : Inconsistent layout information in duplicated
types (OFConsole): (0x0200007c).
1>dcmdataD.lib(dcfilefo.obj) : error LNK2022: metadata operation
failed (8013118D) : Inconsistent layout information in duplicated
types (OFGlobal<bool>): (0x020000bd).
1>dcmdataD.lib(dcsequen.obj) : error LNK2022: metadata operation
failed (8013118D) : Inconsistent layout information in duplicated
types (OFConsole): (0x0200007e).
.....

Why?
I would guess that your structure packing settings aren't the same for all
source files.

Never use /Wp, use #pragma pack instead around only the headers/definitions
that require different packing.
>

[2] If I change the unmanaged project to build with no clr option, it
then links fine with the managed application module. However, this
time I get a run time access violation as soon as the first global
variable is declared inside the unmanaged code:

/* ---------- global condition constants ---------- */
>>>exception here>const OFConditionConst ECC_Normal( 0, 0, OF_ok,
"Normal");

Why?

I am very much exhausted with things to try.

Any input will be much appreciated.

Thanks.

Pixel.To.Life
[http://groups.google.com/group/medicalimagingscience]
Jul 21 '07 #3
On Jul 20, 8:10 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
"Pixel.to.life" <pixel.to.l...@gmail.comwrote in message

news:11**********************@m37g2000prh.googlegr oups.com...


Hi, Gurus,
I recently attempted to build a .Net forms application, that links
with old style unmanaged C++ static libs.
Of course I had to recompile the static lib projects to link properly
with the managed application.
My questions are two fold:
[1] The managed project uses /clr and /MDd (in debug) options. The
unmanaged project, when set to build with /clr, and /MDd, gives link
errors with the managed project:
1>Linking...
1>dcmdataD.lib(dcfilefo.obj) : error LNK2022: metadata operation
failed (8013118D) : Inconsistent layout information in duplicated
types (OFConsole): (0x0200007c).
1>dcmdataD.lib(dcfilefo.obj) : error LNK2022: metadata operation
failed (8013118D) : Inconsistent layout information in duplicated
types (OFGlobal<bool>): (0x020000bd).
1>dcmdataD.lib(dcsequen.obj) : error LNK2022: metadata operation
failed (8013118D) : Inconsistent layout information in duplicated
types (OFConsole): (0x0200007e).
.....
Why?

I would guess that your structure packing settings aren't the same for all
source files.

Never use /Wp, use #pragma pack instead around only the headers/definitions
that require different packing.


[2] If I change the unmanaged project to build with no clr option, it
then links fine with the managed application module. However, this
time I get a run time access violation as soon as the first global
variable is declared inside the unmanaged code:
/* ---------- global condition constants ---------- */
>>exception here>const OFConditionConst ECC_Normal( 0, 0, OF_ok,
"Normal");
Why?
I am very much exhausted with things to try.
Any input will be much appreciated.
Thanks.
Pixel.To.Life
[http://groups.google.com/group/medicalimagingscience]- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -
Thanks, ben, but that was not the issue.

I found the fix. Apparently this is a known issue in VC2005 express
edition, so when using a static constructor in unmanaged code with a
managed forms application, the entry point of the managed app should
not be 'main'. Here is the link to the angelic description (I tried,
works like magic:-)

http://www.thescripts.com/forum/thread642179.html

Thanks to all anyways, and special thanks to Jeffrey Tan (MSFT) who
made an effort.

Pixel.to.life.

Sorry, but another reason I dont like capitalist society- its markets
more than it perfects.

Jul 23 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: joye | last post by:
Hello, My question is how to use C# to call the existing libraries containing unmanaged C++ classes directly, but not use C# or managed C++ wrappers unmanaged C++ classes? Does anyone know how...
4
by: SteveK | last post by:
**Newbie with managed C++** I'm trying to wrap an unmanaged C++ class in a managed C++ class library. When I instantiate the wrapper class it's ctor calls the ctor on the unmanaged class and at...
7
by: Bonj | last post by:
Hi I have a mixed managed/unmanaged project which thanks to you guys I've managed to get rid of the linker errors of, so cheers for that. But now I'm experiencing an unknown access violation....
2
by: chuck rudolph | last post by:
The project that I am on is going to require me to mix managed and unmanaged code. I created a vc++ class library (.net) project bane TestLib. I inserted the following test code in testLib.h. The...
6
by: Aston Martin | last post by:
Hi All, ********************** My Situation ********************** I am working on project that involves passing a structure to unmanaged code from .Net world (well using C#). Perhaps an example...
12
by: DaTurk | last post by:
Hi, I have a rather interesting problem. I have a unmanged c++ class which needs to communicate information to managed c++ via callbacks, with a layer of c# on top of the managed c++ ultimatley...
5
by: Howard Swope | last post by:
I have a series of third party libraries for which we have licensed the source code. These are unmanaged libraries written in C++ which I am able to build without any trouble. I am trying to setup...
1
by: Art | last post by:
I have some Static libs which were intially implemented in VC6 and then converted to VC2005. When I try to use these in my managed C++ application, I am getting the following exception: An...
2
by: Jon Slaughter | last post by:
How difficult is it for one to integrate unmanaged C++ into C#? I know for functions one can use DLLimport but how does one go about doing it for classes? Do I have to completely reimplement the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.