Click to See Complete Forum and Search --> : unmanaged struct in managed class


thegrinch
December 20th, 2005, 10:27 AM
Hi all!

I'm new to VC++.net. I want to use ansi c code with vc++.net. Now I created a Windows-Forms Application-Project (.NET). What I have to do is:
I have this struct:

struct scaled_image_set
{
long sx; /*Size in x-Direction*/
long sy; /*Size in y-Direction*/
float hx; /*horizontal Pixel-Size*/
float hy; /*vertival Pixel-Size*/
cimage f1; /*Image one*/
cimage f2; /*Image two*/
cimage fx; /*Image Derivative in x-Dir*/
cimage fy; /*Image Derivative in y-Dir*/
cimage fz; /*Image Derivative in z-Dir*/
float **u;
float **v;
float **utot;
float **vtot;
};

typedef struct scaled_image_set sis;

OK. To allocate storage, I wrote this Method:

void alloc_set(sis *set, long _sx, long _sy);

Ok.
now, in Form1.h I declared

private: sis * set

Up to this, all compiles and links fine.
but if I try to call

alloc_set(set, 10,10);

linking fails with message
"test fatal error LNK1284: metadata inconsistent with COFF symbol table: symbol '?alloc_set@@$$FYAXPAUscaled_image_set@@JJ@Z' (0A000045) mapped to '?alloc_set@@$$J0YAXPAUscaled_image_set@@JJ@Z' (06000001) in multiscale.obj"

Whats this? What am I doing wrong?
I dont need to have this code managed, I just wand to use it.

Best thanks for your help in advance!

kind regards
Oliver Demetz

NoHero
December 20th, 2005, 12:50 PM
And why not implementing the struct managed? Also show use your alloc() method... Unmanaged allocation should be made with __nogc new operator

sis * set = __nogc new sis;

dave2k
December 21st, 2005, 04:20 AM
i thought _nogc was optional.

NoHero
December 21st, 2005, 11:49 AM
i thought _nogc was optional.

Well... yes... although it helps to read the code: The reader knows explicity if it's unmanaged or managed... ;)

dave2k
December 21st, 2005, 12:39 PM
Just nitpicking ;)

thegrinch
December 23rd, 2005, 07:37 AM
Problem solved:
I just right-clicked the ansi-c source files and said "compile as c++.." under advanced tab...
Tanks for your help!

NoHero
December 23rd, 2005, 08:54 AM
Problem solved:
I just right-clicked the ansi-c source files and said "compile as c++.." under advanced tab...
Tanks for your help!

An extern "C" also would have done the trick...