Results 1 to 9 of 9

Thread: DLL Problem Again!!! :(

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Posts
    843

    DLL Problem Again!!! :(

    I have been learning all the ways which you can create a DLL with VC++. The last time I learned how to do a DLL MFC. And when I tried to use it would send me an error. Somebody told me I had to copy the DLL to my debug folder of the VC++ test program. And it did work.

    Now I have created a NORMAL dll. Which is quite different. Well... I am done with it. I created it with 0 error or wanrnings. I have my test VC++ program to use it. I added the lib file and also added the .h of the main dll class. I put it in the debug folder of the test program. Well... it tells me it doesnt recoginze the functions, the functions from the dll.


    C:\Archivos de programa\Microsoft Visual Studio\MyProjects\p2\p2Doc.cpp(58) : error C2065: 'ModArtNewDrawing' : undeclared identifier

    What in the world can it be wrong?
    "The difference between mad and genius is the success"

  2. #2
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    Are you including the .h file (the file with the function prototypes) in your main program?
    Alcohol & calculus don't mix.
    Never drink & derive.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Posts
    843
    Yes I am!
    "The difference between mad and genius is the success"

  4. #4
    PowerPoster
    Join Date
    Aug 2001
    Location
    new jersey
    Posts
    2,904
    sounds like you could be having a problem with name mangling

  5. #5
    Zaei
    Guest
    Are you exporting your functions from the DLL? For instance, do your function definitions look like this:
    Code:
    _API void myFunc();
    
    or
    
    __declspec(dllexport) void myFunc();
    ? If not, that could be your problem.

    Are you using LoadLibrary()? If that is the case, you need a .def file. Lets say that you have a function, void X(). When compiling, this will become mangled, and GetProcAddress() wont find the function. You need to create a .def file with the name of your project, with the following lines in it:
    Code:
    LIBRARY MyLib
    EXPORTS
    X
    Assume that your DLL will be called MyLib. The EXPORTS line says to export the following functions from the Library, as the Name specified. So, our X function will export as X, and not as it's mangled form. When using GetProcAddress, you then just specify X as the function to find.

    Z.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Posts
    843
    this is an example of one of the dll functiona that i am exporting:

    Code:
           
    extern "C" void PASCAL EXPORT ModArtNewDrawing(CRect pRect, CObArray *poaLines)
    {
     AFX_MANAGE_STATE(AfxGetStaticModuleState());
    
      int lNumLines;
      int lCurLine;
       
      srand((unsigned)time(NULL));
    
      lNumLines=rand()%50;
      
      if (lNumLines>0)
      {
         for (lCurLine=0;lCurLine<lNumLines;lCurLine++)
    	 {
           NewLine(pRect, poaLines);
    	 }
      }
    }
    Then in the .def file I have this :

    Code:
       ; DllNorm.def : Declares the module parameters for the DLL.
    
    LIBRARY      "DllNorm"
    DESCRIPTION  'DllNorm Windows Dynamic Link Library'
    
    EXPORTS
        ; Explicit exports can go here
    	ModArtNewDrawing
    	ModArtSerialize
    	ModArtDraw
    	ModArtClearDrawing
    What do you think is wrong?
    "The difference between mad and genius is the success"

  7. #7
    Zaei
    Guest
    Originally posted by Andreex
    this is an example of one of the dll functiona that i am exporting:

    Code:
           
    extern "C" void PASCAL EXPORT ModArtNewDrawing(CRect pRect, CObArray *poaLines)
    {
     AFX_MANAGE_STATE(AfxGetStaticModuleState());
    
      int lNumLines;
      int lCurLine;
       
      srand((unsigned)time(NULL));
    
      lNumLines=rand()%50;
      
      if (lNumLines>0)
      {
         for (lCurLine=0;lCurLine<lNumLines;lCurLine++)
    	 {
           NewLine(pRect, poaLines);
    	 }
      }
    }
    Then in the .def file I have this :

    Code:
       ; DllNorm.def : Declares the module parameters for the DLL.
    
    LIBRARY      "DllNorm"
    DESCRIPTION  'DllNorm Windows Dynamic Link Library'
    
    EXPORTS
        ; Explicit exports can go here
    	ModArtNewDrawing
    	ModArtSerialize
    	ModArtDraw
    	ModArtClearDrawing
    What do you think is wrong?
    Change this:
    Code:
    extern "C" void PASCAL EXPORT ModArtNewDrawing(CRect pRect, CObArray *poaLines)
    to this:
    Code:
    __declspec(dllexport) void ModArtNewDrawing(CRect pRect, CObArray *poaLines)
    C++ makes DLL exporting easier. You also dont need the double quotes around your LIBRARY name.

    Z.

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Posts
    843
    Oh thank you! I am going to try that in a sec. Also... may ask what is the difference betweem how I had it and the way you are recommending me? THANKS A LOT!
    "The difference between mad and genius is the success"

  9. #9
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    EXPORT is a #define that probably becomes export, which is a keyword that is deprecated in VC++6 and replaced by __declspec(dllexport)
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

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