# dlls are hard

This is a discussion on dlls are hard within the C++ Programming forums, part of the General Programming Boards category; Ok im having issues with dll's... I had this issue before and you guys knew the answer, so here's hoping. ...

1. ## 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. 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. 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.
STDAFX.H

4. 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. i included conio because im using a _getch();

should i still avoid it?

6. It's not portable, but it's up to you if you want to stick with it if it works for you.

7. I put the includes in my stdafx.h but I still have the same pch problem.

EDIT: i changed somethign

8. Originally Posted by MacGyver
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. Mmm, no. You can't. That was what I was referring to.

10. 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. 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);
}

12. 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. 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. If it's in C, include stdio.h. If it's a C++ program include cstdio.

15. Originally Posted by chico1st
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" )

Page 1 of 2 12 Last