Thread: dlls are hard

  1. #1
    Wanabe Laser Engineer chico1st's Avatar
    Join Date
    Jul 2007
    Posts
    168

    dlls are hard

    Ok im having issues with dll's... I had this issue before and you guys knew the answer, so here's hoping.

    here is my declaration:
    Code:
    int __declspec(dllexport) StartUpPlot (char* TestFileA, char* TestFileB)
    {
    	int value;
    	value = TakeData(TestFileA, TestFileB);
    	return value;
    }
    and here is my error:
    Code:
    Compiling...
    StartUpPlot.cpp
    C:\AlazarTech\ATS-SDK\V5_2_0\ATS460-SDK\Development\Beta\StartUpPlot\StartUpPlot.cpp(186) : error C2065: 'malloc' : undeclared identifier
    C:\AlazarTech\ATS-SDK\V5_2_0\ATS460-SDK\Development\Beta\StartUpPlot\StartUpPlot.cpp(189) : error C2065: 'free' : undeclared identifier
    Error executing cl.exe.
    
    StartUpPlot.obj - 2 error(s), 0 warning(s)
    i tried to use:
    Code:
    #include <malloc.h>
    but it did nothing.

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    malloc() and free() are in cstdlib for C++ and stdlib.h for C.

    Use new and delete/delete[] instead of malloc() and free() when using C++.

  3. #3
    Wanabe Laser Engineer chico1st's Avatar
    Join Date
    Jul 2007
    Posts
    168
    Ooops... that was stupid... i have a C program.

    ok now i have this error.

    Code:
    c:\development\beta\startupplot\startupplot.c(5) : fatal error C1853: 
    'Debug/StartUpPlot.pch' is not a precompiled header file created with this compiler
    Here is my include list:

    Code:
    #include "stdafx.h"
    #include "Api.h"
    #include "Cmd.h"
    #include "windows.h"
    #include "stdio.h"
    #include "conio.h"
    My precompiled headers in Visual C++ 6 Settings are set to.
    Use precomipled header
    STDAFX.H
    Last edited by chico1st; 08-13-2007 at 03:00 PM.

  4. #4
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    stdio.h should be cstdio. conio.h.... lose it if you can.

    I think for MSVS, you might need to take all of the includes and put them in stdafx.h.... But otherwise, it sounds like you might be compiling StartUpPlot.h, and for whatever reason it's causing a problem.

    Make sure no .h files are added to your project as project files, but rather just as headers.

    Edit: This might prove useful: http://www.codeguru.com/forum/showthread.php?t=50596

  5. #5
    Wanabe Laser Engineer chico1st's Avatar
    Join Date
    Jul 2007
    Posts
    168
    i included conio because im using a _getch();

    should i still avoid it?

  6. #6
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    It's not portable, but it's up to you if you want to stick with it if it works for you.

  7. #7
    Wanabe Laser Engineer chico1st's Avatar
    Join Date
    Jul 2007
    Posts
    168
    I put the includes in my stdafx.h but I still have the same pch problem.

    EDIT: i changed somethign

  8. #8
    Wanabe Laser Engineer chico1st's Avatar
    Join Date
    Jul 2007
    Posts
    168
    Quote Originally Posted by MacGyver View Post
    It's not portable, but it's up to you if you want to stick with it if it works for you.
    can i use _getch without it.?

  9. #9
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Mmm, no. You can't. That was what I was referring to.

  10. #10
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    You cannot compile MSVS 6 files under any new .NET MSVS. What the compiler is telling you is that is cannot read the pre-compiled header file from a previous version of the compiler or perhaps from another compiler. The pre-compiled header file format was altered in .NET 2003 & 2005 so version 6.0 files will not work.

    The solution is to recreate the pre-compiled header files under your new compiler. Also if you have any old libraries created with MSVC 6 you will have to recreate them to use them under .NET 2003, 2005. 2003 and 2005 versions are also not compatible.

    As far as pure C/C++ source code goes the only problem you will have with your older files is that the newer 2005 compiler will tell you to use the 'safe' C libraries. These amount to a huge mess of redefined functions written by Microsoft and declared as 'safe'. You can turn this off quite easily. To do this just check the help file for your compiler. The standardized libraries are not in any way 'unsafe' and Microsoft made a big boo boo in doing this. They are essentially saying their way is the better way when they themselves have no authority when it comes to the standard. You will also get a huge new slew of warnings when you compile because MSVC .NET 2005 comes much closer to enforcing the standard (except for the unsafe library issue) and also checks your code much closer than version 6.0 ever did.

  11. #11
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    If this is your real code,
    Code:
    int __declspec(dllexport) StartUpPlot (char* TestFileA, char* TestFileB)
    {
    	int value;
    	value = TakeData(TestFileA, TestFileB);
    	return value;
    }
    why not just do away with value?
    Code:
    int __declspec(dllexport) StartUpPlot (char* TestFileA, char* TestFileB)
    {
    	return TakeData(TestFileA, TestFileB);
    }
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  12. #12
    Wanabe Laser Engineer chico1st's Avatar
    Join Date
    Jul 2007
    Posts
    168
    ok dkws ... i didnt think of that.

    I created a header as you told me to bubba but now i am having another issue.

    I have a C program. So i need to include cstdio.h (i think) but my compiler says.
    fatal error C1083: Cannot open include file: 'cstdio.h': No such file or directory
    Error executing cl.exe.

  13. #13
    Wanabe Laser Engineer chico1st's Avatar
    Join Date
    Jul 2007
    Posts
    168
    and i cant recompiler the library that im using because i didnt make it and i dont have the source code.. am i screwed?

  14. #14
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    If it's in C, include stdio.h. If it's a C++ program include cstdio.

  15. #15
    Registered User
    Join Date
    Feb 2006
    Posts
    312
    Quote Originally Posted by chico1st View Post
    ok dkws ... i didnt think of that.

    I created a header as you told me to bubba but now i am having another issue.

    I have a C program. So i need to include cstdio.h (i think) but my compiler says.
    Either use the 'C' header, stdio.h, if its a C program, or lose the .h for a C++ program. Standard library headers in C++ don't use a .h extension, so you just need <cstdio>

    (Only applies to standard library headers, and not 3rd party extensions like "windows.h" )

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extracting data from a laptop hard drive
    By DavidP in forum Tech Board
    Replies: 6
    Last Post: 06-13-2009, 07:02 AM
  2. Some doubts on DLLs
    By BrownB in forum Windows Programming
    Replies: 1
    Last Post: 05-30-2007, 02:25 AM
  3. standart dlls
    By keeper in forum C++ Programming
    Replies: 3
    Last Post: 07-05-2006, 07:32 PM
  4. Replies: 2
    Last Post: 07-06-2005, 07:11 PM
  5. question about DLL's and class functions
    By btq in forum Windows Programming
    Replies: 2
    Last Post: 02-25-2003, 06:08 AM