CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: Using own DLL

  1. #1
    Join Date
    May 2009
    Location
    Italy
    Posts
    5

    Question Using own DLL

    Hi,
    i have read the article in this site on how create ad using a custom DLL.
    I have tried to reproduce the example and it works.
    My problem now is that when i try to do the same thing for my need it doesn't works.

    I try to be brief. Suppose we have this structure:

    DLL project consists of this files.

    A.h (we can also suppose that this file does nothing, is empty)
    B.h
    B.cpp

    The file header B.h includes A.h.

    Then there is a Win32 console project that consists of a simple file Test.cpp that consists of this code:

    #pragma comment(lib, "MyDLL.lib")

    #include <iostream>
    #include "..\MyDLL\B.h"

    int main()
    {
    Function();
    std::cout << Add(32, 58) << "\n";
    return(1);
    }

    (Function and Add are function of my custom dll)

    If i try to compile it there's some problems. If B.h not includes A.h there isn't problems.

    Can someone tell me what is wrong? How can i solve this problem?

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Using own DLL

    Since the compiler essentially just expands any #include files inline, these dependency files need to be available at compile time. In other words, if A.h is #included into B.h and you include B.h into another project, then A.h must be available as well.

    To work around this you either make A.h available or reorganize your code to remove A.h as a dependency.

    Also, keep in mind that the include file that 'publish' for a dll is usually only the 'interface' to the functions in the dll. As long as the function declarations (or method declarations if you are exporting a class) don't have any dependencies that are contained within A.h, you can move the A.h #include statement out of b.h and into b.cpp.
    Last edited by Arjay; May 13th, 2009 at 12:41 PM.

  3. #3
    Join Date
    May 2009
    Location
    Italy
    Posts
    5

    Re: Using own DLL

    Thanks a lot for your suggestions

  4. #4
    Join Date
    May 2009
    Location
    Italy
    Posts
    5

    Another problem with the use of own DLL

    The situation is as follow:

    I have a pack of Classes that i'm using to realize an application that comunicates with some devices.
    My need now is that of realize my DLL that invokes some function of this pack of classes.
    Of this classes i have only the header file obviously and i want to #include this classes in my DLL.
    But it happens that when i try to #include this classes in my DLL starts some errors which do not appear if i #include the same classes in a simple win32 project.

    Suppose we have header file:

    <vhandtk/A.h> that #includes <vtdim/client.h>

    In my DLL i #include the header file <vhandtk/A.h> but when i try to compile it there are many errors which involve a header file <vtdim/socket.h> which is #included in <vtidm/client.h>

    This error doen't appear if i #include the same file in a Win32Project.

    Can you help me?

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Using own DLL

    It all boils down to this:

    Any files that are included in the the header file must be available for the compiler to find.

    You aren't listing the specific headers, but make the paths to the header files are correct and available. You can set up the project to look for header files in additional directories.

  6. #6
    Join Date
    May 2009
    Location
    Italy
    Posts
    5

    Unhappy Re: Using own DLL

    I understand what you say but the problem is always the same

    I show you the file so i can explain my problem better.

    Test.cpp

    #include <GL/glut.h>
    //
    /***** VHT library imports. *****/
    #include <vhandtk/vhtBase.h>
    #include <vhandtk/vhtCore.h>

    /***** Local definitions. *****/
    #include "Test.h"



    Test::Test()
    {

    }

    MyChannel.cpp
    #include <vhandtk/vhtCore.h>
    #include <vhandtk/vhtBase.h>


    ChannelType channelType;

    extern "C" __declspec( dllexport ) ChannelType* __cdecl GetType() {
    ZeroMemory(channelType.name, 80);
    StringCbCopy(channelType.name, 79, MYCHANNEL_NAME);
    channelType.version = MYCHANNEL_VERSION;
    channelType.guid = MYCHANNEL_GUID;
    channelType.baseguid = MYCHANNEL_GUID;
    channelType.minimumEdition = EDITION_LEVEL_ALL; // All Quest3D Editions

    return &channelType;
    }

    MYCHANNELDLL_EXPORTS

    MyChannel::MyChannel() {

    }

    MyChannel::~MyChannel()
    {
    //TODO:: Add destruction logic here
    }


    // Overlodaed save channel
    bool MyChannel::SaveChannel(A3dFileSaver& saver) {
    if(!A3d_Channel::SaveChannel(saver))
    return false;
    //TODO: Add your logic to save persistent data here
    return true;
    }

    bool MyChannel::LoadChannel(A3dFileLoader& loader, A3d_ChannelGroup *group) {
    if(!A3d_Channel::LoadChannel(loader, group))
    return false;
    //TODO: Add your logic to load persistent data here
    return true;
    }

    void MyChannel:oDependencyInit(A3d_List* currentDependList) {
    //TODO: Add eventual dependencies here

    }

    void MyChannel::CallChannel()
    {
    vhtIOConn *trackerConn = vhtIOConn::getDefault( vhtIOConn::tracker );
    vhtTracker *tracker;

    try {
    tracker = new vhtTracker(trackerConn);
    printf("Tracker Connesso");
    }
    catch (vhtBaseException *e){
    printf("Error with tracker: ");
    return ;
    }
    }

    Test.cpp and MyChannel.cpp are in the same DLLProject.
    When i #include <vhandtk/vhtBase.h> in the Test.cpp there aren't problem.
    If i #include <vhandtk/vhtBase.h> in the MyChannel.cpp it launch some errors involving <vtidm/socket.h> which is #included in <vhandtk/vhtBase.h>
    I should want to understand why in a normal class there aren't linking problem while in MyChannel.cpp there are.

    Compiler error are:
    error C2146: errore di sintassi: ';' mancante prima dell'identificatore 'sock'
    error C4430: identificatore di tipo mancante, verrÃ* utilizzato int. Nota: default-int non è più supportato in C++
    error C4430: identificatore di tipo mancante, verrÃ* utilizzato int. Nota: default-int non è più supportato in C++
    error C2079: '_client_socket_t::addr' utilizza struct 'sockaddr_in' non definito
    error C2146: errore di sintassi: ';' mancante prima dell'identificatore 'sock'
    error C4430: identificatore di tipo mancante, verrÃ* utilizzato int. Nota: default-int non è più supportato in C++
    error C4430: identificatore di tipo mancante, verrÃ* utilizzato int. Nota: default-int non è più supportato in C++
    error C2146: errore di sintassi: ';' mancante prima dell'identificatore 'afds'
    error C4430: identificatore di tipo mancante, verrÃ* utilizzato int. Nota: default-int non è più supportato in C++
    error C4430: identificatore di tipo mancante, verrÃ* utilizzato int. Nota: default-int non è più supportato in C++
    error C2146: errore di sintassi: ';' mancante prima dell'identificatore 'maxfd'
    error C4430: identificatore di tipo mancante, verrÃ* utilizzato int. Nota: default-int non è più supportato in C++
    error C4430: identificatore di tipo mancante, verrÃ* utilizzato int. Nota: default-int non è più supportato in C++
    error C2065: 'SOCKET': identificatore non dichiarato
    error C2146: errore di sintassi: ')' mancante prima dell'identificatore 's'
    error C2182: 'VT_SocketClose': utilizzo non valido del tipo 'void'
    error C2491: 'VT_SocketClose': definizione di dllimport dati non consentita
    error C2059: errore di sintassi: ')'

    I'm sorry for italian compiler error but i'm italian
    Errors are Syntax error, missing type specifier, definition of dllimport function not allowed

    I understand the difficulty of help me.
    Thank you in advance.

  7. #7
    Join Date
    May 2009
    Location
    Italy
    Posts
    5

    Re: Using own DLL

    :O:O: Oh my God!!! :O:O

    The previous order of #include in MyChannell.cpp was:

    #include "stdafx.h"
    #include "MyChannel.h"
    #include "stdlib.h"
    #include "A3d_EngineInterface.h"
    #include "Aco_String.h"
    #include "Aco_Float.h"

    #include <GL/glut.h>
    #include <vhandtk/vhtCore.h>
    #include <vhandtk/vhtBase.h>

    I have changed the order so:

    #include <GL/glut.h>
    #include <vhandtk/vhtCore.h>
    #include <vhandtk/vhtBase.h>

    #include "stdafx.h"
    #include "MyChannel.h"
    #include "stdlib.h"
    #include "A3d_EngineInterface.h"
    #include "Aco_String.h"
    #include "Aco_Float.h"

    and there aren't errors!!!
    I can't believe!

  8. #8
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Using own DLL

    Try changing the order one more time and put the stdafx.h file on top.

    Code:
    #include "stdafx.h"
    
    #include <GL/glut.h>
    #include <vhandtk/vhtCore.h>
    #include <vhandtk/vhtBase.h>
    
    #include "MyChannel.h"
    #include "stdlib.h"
    #include "A3d_EngineInterface.h"
    #include "Aco_String.h"
    #include "Aco_Float.h"
    That way, the pre-compiled header functionality will work as intended and you'll get faster compile times.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured