How can I acess member variables in an exported class? (C2039)

G

Guest

I have a class exported in a dll that has member variables I wish to access. When I do it I get an error C2039: 'myVar' : is not a member of myClass

Here is an example of what my code looks like
In the library

__gc class MyClass
public
int myVar


In the application project

#using "MyLibrary.Dll

void main()
int i
MyClass* myObject = new MyClass
i = myObject->myVar; /* error C2039 *
Console::WriteLine("{0}", __box(i))


Any idea how to get this to work? I don't want to use properties as it will break a lot of other code.
 
D

Doug Harrison [MVP]

mccoyn said:
I have a class exported in a dll that has member variables I wish to access. When I do it I get an error C2039: 'myVar' : is not a member of myClass'

Here is an example of what my code looks like:
In the library:

__gc class MyClass{
public:
int myVar;
}

In the application project:

#using "MyLibrary.Dll"

void main(){
int i;
MyClass* myObject = new MyClass;
i = myObject->myVar; /* error C2039 */
Console::WriteLine("{0}", __box(i));
}

Any idea how to get this to work? I don't want to use properties as it will break a lot of other code.

In your real code, are you sure you didn't make a spelling error? (Case
counts!)

Did you declare MyClass itself public? (If not, I would have expected you to
get other errors, but who knows?)
 
G

Guest

Thanks for the reply

I've been looking over this some more and I think I was looking in the wrong place for the problem. The MyVar in the example above is a pointer to a __nogc class in my real code. It seems the problem is the library doesn't export the full class, although it exports at least enough for me to have a pointer to it

Is it possible to export __nogc classes and __gc classes in the same library

In direct reply, I have rechecked the spelling and I'm sure its right. I also added public to whatever classes I have without any success. I'm using the option /NOASEMBLY in the libary so I don't think it matters one way or the other.
 
D

Doug Harrison [MVP]

mccoyn said:
Thanks for the reply.

I've been looking over this some more and I think I was looking in the wrong place for the problem. The MyVar in the example above is a pointer to a __nogc class in my real code. It seems the problem is the library doesn't export the full class, although it exports at least enough for me to have a pointer to it.

Is it possible to export __nogc classes and __gc classes in the same library?

I think you'll have to #include the declaration of the __nogc class.
 
G

Guest

I've tried that. I run into the same problem explained in another thread recently posted here with the following name

How can I avoid type redefinition w/ managed dll and other unmanaged code

Scott seems to have described my problem very well, so I'll just pay attention to that thread.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top