exporting class methods to library results in .lib and .exp

This is a discussion on exporting class methods to library results in .lib and .exp within the C++ Programming forums, part of the General Programming Boards category; I'm trying to export some class methods to dll and lib files, but instead of creating a dll it's creating ...

  1. #1
    Shadow12345
    Guest

    exporting class methods to library results in .lib and .exp

    I'm trying to export some class methods to dll and lib files, but instead of creating a dll it's creating a .exp file, is it supposed to be doing this? I haven't seen class methods being exported before so I wasn't entirely sure what to do, but in my header file i've got:
    __declspec(dllexport) return type Name(parameters);
    and then in the implementation file i've got:
    __declspec(dllexport) return type Name(parameters) {
    //implementation
    };

    Have I exported correctly? I don't know what I'm doing...

    EDIT: Well I made an app to test the library and it doens't work, gives me an error saying the application couldn't initialize successfully

    Hmmmm, I don't know what I did wrong!
    Last edited by Shadow12345; 01-05-2003 at 06:48 PM.

  2. #2
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    It should be creating a DLL and a .lib and a .exp

    EDIT: If you want loadtime linking then just link to the lib, put the DLL in the same directory, and make sure the headers are changed to dllimport instead of dllexport, usually just done with a macro (when using loadtime linking in msvc++ you are supposed to be able to completely eliminate the dllimports and dllexports when loadtime linking to the DLL by letting the .lib resolve everything, but if you work with classes it doesn't work properly so you need to explicitly use dllimport).
    Last edited by Polymorphic OOP; 01-05-2003 at 06:53 PM.

  3. #3
    Shadow12345
    Guest
    It should be creating a DLL and a .lib and a .exp

    EDIT: If you want loadtime linking then just link to the lib, put the DLL in the same directory, and make sure the headers are changed to dllimport instead of dllexport, usually just done with a macro (when using loadtime linking in msvc++ you are supposed to be able to completely eliminate the dllimports and dllexports when loadtime linking to the DLL by letting the .lib resolve everything, but if you work with classes it doesn't work properly so you need to explicitly use dllimport).
    I understand how it's supposed to work and how it's supposed to be used, I just don't understand why it's not creating the dll. I'm making a new project that just has the implementation, no other main.cpp or other files, this may take a while ill tell you when i get it working

  4. #4
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    a .lib and a .exp should not be created if a dll isn't created. are you absolutely positive that there isn't one?

  5. #5
    Shadow12345
    Guest
    nope, no dll

    EDIT:
    Is it okay to still have a main while creating the dll? Or should I just have header and implementation files that export the dlls, and no other files?
    Last edited by Shadow12345; 01-05-2003 at 07:20 PM.

  6. #6
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Originally posted by Shadow12345
    Is it okay to still have a main while creating the dll? Or should I just have header and implementation files that export the dlls, and no other files?
    You can have "main" but it won't be called when the dll is loaded. It will just be like a normal function called "main."

    DllMain is what is called at the start.

    You use __declspec(dllexport) on the declaration of whatever you wish to export from the dll project. Post the code, I have a feeling that you're not using __declspec properly.

  7. #7
    Shadow12345
    Guest
    Model.h
    Code:
    class Model {
    //structures
    
    __declspec(dllexport)	Model();	
    __declspec(dllexport)	~Model();
    __declspec(dllexport)   AUX_RGBImageRec	*LoadBMP(char*);
    __declspec(dllexport)	GLuint	LoadGLTextures(char*);
    __declspec(dllexport)	bool LoadModel(char *);
    __declspec(dllexport)	bool LoadTextures();	//LOAD THE TEXTURES, THE MATERIAL IS WHAT ACTUALLY GETS THE FILE NAME
    __declspec(dllexport)	void Draw();
    
    
    };
    model.cpp

    Code:
    #include "Main.h"
    #include "MS3D.h"
    #include "Model.h"
    
    typedef unsigned char byte;
    typedef unsigned short word;
    
    __declspec(dllexport) Model::Model(){
    
    
    }
    
    __declspec(dllexport) Model::~Model() {
    
    }
    __declspec(dllexport) AUX_RGBImageRec * Model::LoadBMP(char *FileName) {
    }
    
    __declspec(dllexport) GLuint	Model::LoadGLTextures(char *FileName) {
    	
    }
    
    __declspec(dllexport) bool Model::LoadModel(char *fileName) {
    
    }
    
    
    __declspec(dllexport) void Model::Draw() {
    
    
    }
    	
    __declspec(dllexport) bool Model::LoadTextures() {
    
    
    }

  8. #8
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Just do

    Model.h
    Code:
    class __declspec(dllexport) Model {
    //structures
    
        Model();	
        ~Model();
        AUX_RGBImageRec *LoadBMP(char*);
        GLuint LoadGLTextures(char*);
        bool LoadModel(char *);
        bool LoadTextures();	//LOAD THE TEXTURES, THE MATERIAL IS WHAT ACTUALLY GETS THE FILE NAME
        void Draw();
    };
    model.cpp

    Code:
    #include "Main.h"
    #include "MS3D.h"
    #include "Model.h"
    
    typedef unsigned char byte;
    typedef unsigned short word;
    
    Model::Model(){
    }
    
    Model::~Model() {
    }
    
    AUX_RGBImageRec * Model::LoadBMP(char *FileName) {
    }
    
    GLuint Model::LoadGLTextures(char *FileName) {
    	
    }
    
    bool Model::LoadModel(char *fileName) {
    }
    
    void Model::Draw() {
    }
    
    bool Model::LoadTextures() {
    }
    Last edited by Polymorphic OOP; 01-05-2003 at 07:42 PM.

  9. #9
    Shadow12345
    Guest
    if that works, I'm going offline and jumping out my window

    EDIT: What the heck, still no dll, I get this warning and I don't know what it means, I changed it so it's exactly like the way you told me. It still exports the .lib and .exp files.

    warning C4091: '__declspec(dllexport ) ' : ignored on left of 'class Model' when no variable is declared
    I dunno what that means
    Hmm my brain is too small
    Last edited by Shadow12345; 01-05-2003 at 07:43 PM.

  10. #10
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    It should

    ...well, minus that stupid smiley it put in there, ha

    EDIT: oh, and the __declspec(dllexport) goes between "class" and the class name. Messed that up in the original post.
    Last edited by Polymorphic OOP; 01-05-2003 at 07:42 PM.

  11. #11
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    See previous edit, you missed it.

  12. #12
    Shadow12345
    Guest
    Okay well I correct that error from your original post, and I'm just french because I am still not getting a dll. I have it showing all hidden files, so it can't be hiding it from me can it? Also it doesn't say that a dll was created, it says this when I build the project:

    originally posted by my ******* piece of **** compiler
    Creating library Debug/lesson1.lib and object Debug/lesson1.exp
    NO DLL, AHH

  13. #13
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    check your settings to see where it puts the DLL when it builds it. It might just be putting it in another directory for some reason.

  14. #14
    Shadow12345
    Guest
    how do I check that? I'm not seeing it. I'm under visual studio 6

  15. #15
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    project->settings->link->output filename

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21