Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#include <sstream> #include <string> #include "functions.h" #include <vector> #include "Tutorial.h" //Mit diesem Präprozessorbefehl wird die Tutorial.lib mitgelinkt #pragma comment (lib, "Tutorial.lib") int main() { Message(); testmsg("FF"); std::cin.get(); return 0; } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 |
#include "Tutorial.h" #include <iostream> #include <string> void TUTORIAL_API testmsg(const std::string& any) { std::cout << any << std::endl; } |
C-/C++-Quelltext |
|
1 2 3 |
#pragma once void TUTORIAL_API testmsg(const std::string& any); |
Zitat
error C3861: "testmsg": Bezeichner wurde nicht gefunden.
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#ifdef WIN32 #include <windows.h> int WINAPI DllMain( HANDLE _HDllHandle, DWORD _Reason, LPVOID) { switch(_Reason) { case DLL_THREAD_ATTACH: case DLL_PROCESS_ATTACH: { return TRUE; } case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: { return TRUE; } } return TRUE; } #endif /* WIN32 */ |
Zitat von »"GR-PA"«
@Nicoo wie ich das sehe, ist main.cpp das Programm, dass die dll verwendet also war dort alles richtig.
Zitat von »"GR-PA"«
@XP^ Ist misc.h eingebunden? Eine DllMain solltest du auch definieren, vllt brauchst du sie ja später...
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
//Includeguard #pragma once //Header von außerhalb #include <windows.h> //Export Makro #ifdef TUTORIAL_EXPORTS #define TUTORIAL_API __declspec(dllexport) #else #define TUTORIAL_API __declspec(dllimport) #endif //Hier werden alle Header der Dll inkludiert, damit man später nicht //in der Anwendung die die Dll verwendet jede einzeln inkludieren muss #include "Message.h" #include "misc.h" //#include... |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
// tutorial.cpp : Definiert den Einstiegspunkt für die DLL-Anwendung. // #include "tutorial.h" //Die DllMain int WINAPI DllMain(HINSTANCE DllHandle, unsigned long ReasonForCall, void* Reserved) { switch (ReasonForCall) { case DLL_PROCESS_ATTACH: { //Der Referenzzähler wird um eins erhöht } break; case DLL_PROCESS_DETACH: { //Der Referenzzähler wird um eins reduziert } break; default: break; } return 1; } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 |
#pragma once extern "C" { void TUTORIAL_API testmsg(const std::string& any); } |
Zitat
1>c:\users\daniel\desktop\projekte\uebung\main\main.cpp(1 : error C3861: "testmsg": Bezeichner wurde nicht gefunden.
Zitat
Eine DLL hat keine normale main().
Denn sie wird ja nicht direkt ausgeführt, sondern eine Anwendung lädt den Code und führt Ihn aus. Unter Win32 gibts nur folgendes:
C-/C++-Quelltext
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 #ifdef WIN32 #include <windows.h> int WINAPI DllMain( HANDLE _HDllHandle, DWORD _Reason, LPVOID) { switch(_Reason) { case DLL_THREAD_ATTACH: case DLL_PROCESS_ATTACH: { return TRUE; } case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: { return TRUE; } } return TRUE; } #endif /* WIN32 */
Und zwecks der Fehlermeldung:
Du solltest die "misch.h" vllt auch in die "main.cpp" einbinden.
Bearbeitung
Vermeide "pragma once". C++ ist (solange man keine WinAPI verwendet) XPlatform. Diese Fähigkeit nimmst du deinem Code aber mit solchen Compiler-spez. Befehlen. Ein normaler include-guard tuts auch.
Zitat von »"[url=http://gcc.gnu.org/onlinedocs/gcc-2.95.3/cpp_1.html#SEC8«
GCC[/url]"]There is also an explicit directive to tell the preprocessor that it need not include a file more than once. This is called `#pragma once', and was used in addition to the `#ifndef' conditional around the contents of the header file. `#pragma once' is now obsolete and should not be used at all.
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 |
#if !defined(MYHEADER_H__INCLUDED) #define MYHEADER_H__INCLUDED #if (_MSC_VER >= 1300) #pragma once #endif // (_MSC_VER >= 1300) // ... #endif // MYHEADER_H__INCLUDED |
Werbeanzeige