vcl und dll...
-
hi!
ich hab fleißig versucht das tut auf der seite über dll´s
http://bcb-tutorial.c-plusplus.net/DLL_Tutorial/index.html
durch zu machen... mit nur mäßigem erfolg... ich habe sowohl probleme bei der erstellung von dynamischen dlls als auch, worum es in diesem thread ja besonders gehen soll, mit der erstellung von dll´s die eine form besitzen.
zum ersten, ich gehe wie gesagt genau nach tutorial und bekomme das hier[C++ Fehler] DLLImp.cpp(16): E2451 Undefiniertes Symbol 'HINSTANCE'
für diese zeile
HINSTANCE h = LoadLibrary("Project2.dll");
dabei raus... was soll das???
und zum zweiten, ich habe es schon 20000000 mal (mindestens) versucht nach der anleitung im bcb diese dll mit form zu basteln... ohne erfolg! ich bekomm immer F1004 Interner Compiler-Fehler...
an der stelle__declspec(dllexport) void FormShow(TComponent* Owner) { TDLLForm* DLLForm = new TDLLForm(Owner); DLLForm->ShowModal(); }
und ich weiß nich warum...
-
fietek schrieb:
[C++ Fehler] DLLImp.cpp(16): E2451 Undefiniertes Symbol 'HINSTANCE'
für diese zeile
HINSTANCE h = LoadLibrary("Project2.dll");
dabei raus... was soll das???
windows.h eingebunden?
Falls nein: woher soll der Compiler den Typen denn kennen?fietek schrieb:
und zum zweiten, ich habe es schon 20000000 mal (mindestens) versucht nach der anleitung im bcb diese dll mit form zu basteln... ohne erfolg! ich bekomm immer F1004 Interner Compiler-Fehler...
an der stelle__declspec(dllexport) void FormShow(TComponent* Owner) { TDLLForm* DLLForm = new TDLLForm(Owner); DLLForm->ShowModal(); }
und ich weiß nich warum...
Welche C++Builder-Version? Wie sieht der vollständige Code aus?
-
hui, danke fürs antworten!
also, zu 1. ... ja, die <windows.h> hat nur gefehlt - danach gings einwandfrei.
und zu 2. ich verwende den bcb aus dem borland developer studio 2006 - da steht was von version 10 für den c++builder(kann das sein?) ich habe versucht dem tutorium (siehe hier: http://bcb-tutorial.c-plusplus.net/DLL_Tutorial/artikel11.html) zu folgen und habe auch die borlandhilfe (wenn du genauer hinschaustsiehstes auf jeden fall) "genutzt", da ich den ganzen spaß in einer dynamischen dll realisieren wollte... rein aus intersse heraus. mir fehlt definitiv noch in der DIIImp.h ein Funktionsaufruf... das hab ich nicht hin bekommen. und dann gibts da halt immer noch das problem mit den 2 zeilen
*TDLLForm DLLForm = new TDLLForm(Owner); DLLForm->ShowModal();
, die ich aus dem oben genannten tutorial habe und nicht genau weiß, was die nun wirklich machen... meines erachtens nach sollten die ja eigentlich die funktion zu formöffnen darstellen, oder?
naja, vielleicht kannst du mit dem wirrwar etwas anfangen... und mir helfen!?!? ich versuchs derweile weiter!
lg fiete!
hier mal der komplette code:[b]projekt1.exe: DLLImp.cpp:[/b] #include "DLLImp.h" #include <windows.h> #pragma hdrstop #pragma package(smart_init) void FormShow(void) { // Get a handle to the DLL module. HINSTANCE hinstLib = LoadLibrary("Project2.dll"); // If the handle is valid, try to get the function address. if (hinstLib != NULL) { MYPROC ProcAdd = (MYPROC) GetProcAddress(hinstLib, "FormShow"); // If the function address is valid, call the function. if (NULL != ProcAdd) { (ProcAdd) ("message via DLL function\n"); } // Free the DLL module. FreeLibrary(hinstLib); } }
[b]DLLImp.h:[/b] #ifndef DLLImpH #define DLLImpH #endif typedef void (*MYPROC)(LPTSTR);
[b]Unit1.cpp:[/b] #include <vcl.h> #pragma hdrstop #include "Unit1.h" #include "DLLImp.cpp" #pragma package(smart_init) #pragma resource "*.dfm" TForm3 *Form3; //--------------------------------------------------------------------------- __fastcall TForm3::TForm3(TComponent* Owner) void __fastcall TForm3::Button2Click(TObject *Sender) { FormShow(Application); }
[b]unit1.h:[/b] #include <Controls.hpp> #include <StdCtrls.hpp> #include <Forms.hpp> #include <ExtCtrls.hpp> //--------------------------------------------------------------------------- class TForm3 : public TForm { __published: // Von der IDE verwaltete Komponenten TEdit *Edit1; TEdit *Edit2; TRadioGroup *RadioGroup1; TButton *Button2; void __fastcall Button2Click(TObject *Sender); private: // Benutzer-Deklarationen public: // Benutzer-Deklarationen __fastcall TForm3(TComponent* Owner); }; //--------------------------------------------------------------------------- extern PACKAGE TForm3 *Form3; //--------------------------------------------------------------------------- #endif
[b]Projekt2.dll: Unit2.cpp:[/b] #include <vcl.h> #include <windows.h> #pragma hdrstop #pragma argsused int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved) { return 1; } //--------------------------------------------------------------------------- extern "C" __declspec (dllexport) void FormShow(TComponent* Owner) { *TDLLForm DLLForm = new TDLLForm(Owner); DLLForm->ShowModal(); }
und da fällt mir auch gleich nochwas auf...
der code hier aus der borlandhilfevoid FormShow(void) { // Get a handle to the DLL module. HINSTANCE hinstLib = LoadLibrary("Project2.dll"); // If the handle is valid, try to get the function address. if (hinstLib != NULL) { MYPROC ProcAdd = (MYPROC) GetProcAddress(hinstLib, "FormShow"); // If the function address is valid, call the function. if (NULL != ProcAdd) { :arrow: (ProcAdd) ("message via DLL function\n"); [b]//was macht das denn hier eigentlich???[/b] } // Free the DLL module. FreeLibrary(hinstLib); } }
ist doch nicht das selbe wie der code aus dem tutorial von der syntax her, oder???
int SubVals(int x, int y) { TSubVals* SubVals; int Erg; HINSTANCE h = LoadLibrary("Project2.dll"); if (h != 0) SubVals = (TSubVals*)GetProcAddress(h, "_SubVals"); if (SubVals != NULL) Erg = SubVals(x, y); else Erg = 0; FreeLibrary(h); return Erg; }
ich bin echt noch zu sehr noob in dem feld um das sofort zu checken...
aber mich interessierts leider sehr...
-
ich nochmal...
am besten, du schaust mal kurz über das tutorial drüber und sagst mir, ob das so überhaupt geht... ich verzweifel sogar schon an der vorlage für eine statische dll
http://bcb-tutorial.c-plusplus.net/DLL_Tutorial/artikel11.htmlmfg fiete