PC Review


Reply
Thread Tools Rate Thread

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

 
 
Pixel.to.life
Guest
Posts: n/a
 
      20th Jul 2007
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]

 
Reply With Quote
 
 
 
 
Pixel.to.life
Guest
Posts: n/a
 
      20th Jul 2007
On Jul 20, 12:01 am, "Pixel.to.life" <pixel.to.l...@gmail.com> wrote:
> 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...

 
Reply With Quote
 
Ben Voigt [C++ MVP]
Guest
Posts: n/a
 
      21st Jul 2007

"Pixel.to.life" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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]
>


 
Reply With Quote
 
Pixel.to.life
Guest
Posts: n/a
 
      23rd Jul 2007
On Jul 20, 8:10 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospam> wrote:
> "Pixel.to.life" <pixel.to.l...@gmail.com> wrote in message
>
> news:(E-Mail Removed)...
>
>
>
>
>
> > 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem using unmanaged static libs from managed C++ Windows Form Application in VC2005 Art Microsoft VC .NET 1 18th Jul 2007 07:21 AM
call managed/unmanaged classes from unmanaged code bonk Microsoft VC .NET 1 1st Oct 2005 04:10 PM
static managed member in unmanaged code =?Utf-8?B?S2x5bnRAbm9lbWFpbC5ub3NwYW0=?= Microsoft VC .NET 3 4th Mar 2005 08:58 AM
HOWTO call static managed function from unmanaged code. Ken Durden Microsoft VC .NET 0 10th Nov 2004 06:27 PM
Re: Access Violation when calling unmanaged C++ from managed C++ S. Han Microsoft VC .NET 6 30th Apr 2004 09:29 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:44 PM.