-
compile as .dll
If i have a program, in order to compile it as a dll there isnt just a .dll button?
im using microsoft visual c++, but i was reading a tutorial on how to do it and it sounds much harder than expected. is this true?
http://www.codeguru.com/forum/showthread.php?t=231254
-
Dll-handling on windows can be a pain in the ass in some cases compared to linux. But the description is only about the standard case and should work straight forward if you do what they tell. Post some code and mark what you find to hard, then one can help you out.
-
OK i cant get this to work here is my code:
Code:
#include "stdafx.h"
#include "AlazarApi.h"
#include "AlazarCmd.h"
#include "windows.h"
#include "stdio.h"
#include "conio.h"
int __declspec(dllexport) __stdcall TestDLL(const char FileNameA[1024],
const char FileNameB[1024]){
oldmain();
return 1;
}
Code:
int oldmain()
{
***
}
Here are my errors:
Code:
Compiling...
TestDLL.cpp
C:\AlazarTech\ATS-SDK\V5_2_0\ATS460-SDK\Development\Beta\Acq2DiskDLL\TestDLL\TestDLL.cpp(13) : error C2065: 'oldmain' : undeclared identifier
C:\AlazarTech\ATS-SDK\V5_2_0\ATS460-SDK\Development\Beta\Acq2DiskDLL\TestDLL\TestDLL.cpp(115) : error C2373: 'oldmain' : redefinition; different type modifiers
C:\AlazarTech\ATS-SDK\V5_2_0\ATS460-SDK\Development\Beta\Acq2DiskDLL\TestDLL\TestDLL.cpp(189) : error C2065: 'malloc' : undeclared identifier
C:\AlazarTech\ATS-SDK\V5_2_0\ATS460-SDK\Development\Beta\Acq2DiskDLL\TestDLL\TestDLL.cpp(192) : error C2065: 'free' : undeclared identifier
Error executing cl.exe.
TestDLL.obj - 4 error(s), 0 warning(s)
this looks like it is probably a simple answer. Any help is much appreciated.
Where can I learn how to do this .dll stuff properly? the website didnt really explain anything.
-
You probably need to include <stdlib.h> for malloc() and free(). And prototype oldmain(). And oldmain() takes argc and argv, why aren't you passing it anything?
You should use <> for "standard" header files like this.
Code:
#include "windows.h"
->
Code:
#include <windows.h>
-
prototype? how do i do that?
-
If you have a function like this:
Code:
int add(int x, int y)
{
return x + y;
}
The prototype could be either of these:
Code:
int add(int x, int y);
The prototype needs to appear before a function is used.
Incidentally, don't try to prototype standard functions (specifically don't try to write a prototype for main()!). Header files provide all the prototypes you need for standard functions that aren't built into the compiler (like main()).
-
http://www.codeproject.com/dll/XDllPt1.asp?print=true
Took me 15 minutes to understand it. It's much easier than what I learned before with COM, of course, if you have VC++ 07 and up.
-
Please.cpp
c:\...\please\please.cpp(4) : fatal error C1083: Cannot open precompiled header file: 'Debug/Please.pch': No such file or directory
Error executing cl.exe.
does anyone know what causes this?
-
The compiler has a setting for which file "generates" the precompiled header.
If you use visual studion and go to
project->properties->C/C++->Precompiled Headers
you will see that is says
"Create/Use Precompiled Headers"
"Create/Use precompiled header through"
Now, you need to compile the file that is set to "Create precompiled headers" - this is "stdafx.cpp" in a default project.
A complete rebuild of your project should do the trick.
--
Mats
-
Ok i cant compile StdAfx.cpp I get this error
Code:
--------------------Configuration: StdAfx - Win32 Debug--------------------
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/StdAfx.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
StdAfx.exe - 2 error(s), 0 warning(s)
all that is in StdAfx.cpp is
Code:
#include "stdafx.h"
Thats is if i give it its own workspace.. if it put it in the project with please.cpp it cant compile either.
the precompiled headers screen looks like for my please.cpp
Attachment 7441
^pretend giveup = please.. i went through all the steps again
... my brain hurts
-
The "easy" solution is to just turn off precompiled headers. This is NOT a good idea on a slow machine/hard-disk if you include things like <windows.h>, but to get you going, that should be fine.
By the way, I meant that you need to compile stdafx.cpp INSIDE YOUR PROJECT. If you try to build an executable from that on it's, as you've seen, it won't find a "main" - naturally, since that's elsewhere (or in your case, probably "nowhere", since you're trying to build a DLL).
--
Mats
-
ok nice it compiled, i will test it to see if it works tomorrow. :D
thanks for all your help but one question
shouldnt this give me a "Please.h" file.. i didnt get one.. dont i need it?
-
Not sure what steps you went through to create please.cpp, but it's not NECESSARY to have a .h file for every .cpp file - it's common to have one for MOST .cpp files, but you don't HAVE to have one.
--
Mats
-
when I run the .exe version of this code I print messages to screen and I can see them but when i call the .dll version of this code I dont see those messages.
Is this normal?
Is there anyway to make these messages display?
Im curious because the .dll doesnt seem to work but the .exe does, so im trying to figure out where it is going wrong. Any ideas?
Once again thank you very much.
*EDIT*
Ok it works now, i just redid the steps, but still can i make it show the print to screen stuff?
-
I don't see any reason why a DLL wouldn't be able to use for example printf - what exactly are you doing, and what happens if you set a breakpoint around the printf in your DLL and single-step it?
--
Mats