Re: problem using self built DLL



On Apr 22, 10:01 pm, Joseph M. Newcomer <newco...@xxxxxxxxxxxx> wrote:
You are confusing code loading strategy with compilation strategy; they are only vaguely
related. While it is true that the CODE that IMPLEMENTS the class is not loaded until
runtime, the compiler still has to know about the class and all its methods, members, its
size, etc., AT COMPILE TIME or it can't connect to that code.
joe

On 22 Apr 2007 15:22:53 -0700, wanwan <ericwa...@xxxxxxxxx> wrote:



On Apr 22, 1:03 pm, Joseph M. Newcomer <newco...@xxxxxxxxxxxx> wrote:
See below...
On 20 Apr 2007 11:47:16 -0700, wanwan <ericwa...@xxxxxxxxx> wrote:

I made an MFC extension DLL, but I couldn't get it working on the
client application. Can somebody please tell me what I did wrong in
the procedure:

1. I started an MFC extension DLL project called "MyDll". I added a
class called "MyClass" and added the keyword AFX_EXT_CLASS in the
class declaration in the header file.

2. I built the project and copied the files "MyDll.dll" and
"MyDll.lib" to the client project folder.

3. In the client project settings, I added the file MyDll.lib in the
linker - input section.

4. I made a MyDll.h file with the line: class AFX_EXT_CLASS MyClass;

*****
So right there, you have made a serious error. You have declared that there is a class
called MyClass, AND YOU HAVE SAID NOTHING MORE ABOUT IT! This is a "forward"
declaration, wherein you promise to say something later.
*****

5. I used #include "MyDll.h" in the cpp files where I need MyClass.

With the above steps, I expect MyClass to be defined. But when I use
the imported class it gave me the error:

error C2079: 'CClientApp::myobject' uses undefined class 'MyClass'

*****
You get this error because it IS an undefined class. You promised to say something about
it later, and never did, so there is no possible way for the compiler to know what the
class does. It does not know what size it is, what members it has, or anything other than
its name (of course, had you wanted to give a meaningful error message, you would have
shown the line that this erorr complains about. It would be obvious; it would be a
declaration of a MyClass variable, or an attempt to use any method or access any member of
the class).

Your .h file must contain the entire class declaration. If you do not want the
implementation visible, then the .h file declares the class, and your implementation will
declare a derived subclass of that class.
joe
*****
*****

Please advise.

Joseph M. Newcomer [MVP]
email: newco...@xxxxxxxxxxxx
Web:http://www.flounder.com
MVP Tips:http://www.flounder.com/mvp_tips.htm

My impression is that the class MyClass is loaded from the DLL after I
specify the library file in linker.
In my test program, MyClass has no member function or member
variable. I thought I would start to add them after I get the DLL
working.

If I'm supposed to give the details of MyClass in source code, what's
the point of building a DLL?

Joseph M. Newcomer [MVP]
email: newco...@xxxxxxxxxxxx
Web:http://www.flounder.com
MVP Tips:http://www.flounder.com/mvp_tips.htm

I understood that part. I'm not sure if you read me previous message.
The MyClass class that I put into the DLL has no member variable or
member function. I made it for the purpose of trying it on the client
application because I'm new to DLL programming. Since it's an "empty"
class , I'd think the only line needed in the header is:

class AFX_EXT_CLASS MyClass;
or
class __declspec(dllimport) MyClass;

After I code the client application with the DLL, I should be able to
instantiate a MyClass object. I may be still missing some steps which
cause the error (please read above for my procedure.

Is there a good DLL tutorial that I can read on the internet? I tried
my best to follow some tutorials, but still no success.

.



Relevant Pages

  • Re: problem using self built DLL
    ... runtime, the compiler still has to know about the class and all its methods, members, its ... called MyClass, AND YOU HAVE SAID NOTHING MORE ABOUT IT! ... declaration, wherein you promise to say something later. ... MyClass has no member function or member ...
    (microsoft.public.vc.mfc)
  • Re: Privacy and scope and love
    ... > class MyClass ... > struct MyStruct ... on "Access to Base Classes" states that "The members of a member class have ... I suppose that you could make a forward declaration of the MyStruct class ...
    (comp.lang.cpp)
  • Re: problem using self built DLL
    ... says to the compiler, "I will tell you about this class in detail before you need it". ... which says "This is a class with no member variables and no methods". ... class declaration in the header file. ... called MyClass, AND YOU HAVE SAID NOTHING MORE ABOUT IT! ...
    (microsoft.public.vc.mfc)
  • Re: problem using self built DLL
    ... called MyClass, AND YOU HAVE SAID NOTHING MORE ABOUT IT! ... declaration, wherein you promise to say something later. ... specify the library file in linker. ... MyClass has no member function or member ...
    (microsoft.public.vc.mfc)
  • Re: Which variable type?
    ... that it returns an object of type CommandBarControl.) ... It would be better to include a declaration like ... > The Item method syntax has the following object qualifier and part: ... An expression that specifies the position of a member ...
    (microsoft.public.word.vba.general)