übergabe hInstance
-
Hi Leuts,.. icke wieder
Wenn ich ein Childwindow so erstelle:
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { static RECT rect; static HWND hCheckBox; switch(message) { case WM_CREATE: { hCheckBox = CreateWindowEx(WS_EX_TRANSPARENT, "button", NULL, WS_CHILD | WS_VISIBLE |BS_AUTOCHECKBOX , 0, 0, 13, 13, hWnd, NULL, ((LPCREATESTRUCT) lParam) -> hInstance, NULL); ...wir das Instance Handle per
((LPCREATESTRUCT) lParam) -> hInstanceübergeben, nun da ich mehrere checkboxen brauche habe ich mir eine kleine klasse geschrieben, als ich das instance handle übergeben wollte á la
checkbox box1(120,120,((LPCREATESTRUCT) lParam) -> hInstance,wParam,lParam,hWnd);(bzw. im constructor aus lparam)
bekamm ich immer ne nette fehlermeldungIC.EXE hat ein Problem festgestellt und muss beendet werden.
AppName: ic.exe AppVer: 0.0.0.0 ModName: ic.exe
ModVer: 0.0.0.0 Offset: 000014c1Kopiere ich hingegen in der Winmain die winclass instance in eine globale variable und rufe
checkbox box1(120,120,hGlobalInst,wParam,lParam,hWnd);auf, funktioniert es einwandfrei.
Anscheinend habe ich da irgendetwas nicht richtig verstanden.
Kann mich mal jemand bitte aufklären!!
P.S.: bitte nicht folgendes zitieren:
Instance Handle*Every window class requires an instance handle to identify the application or .dll that registered the class. The system requires instance handles to keep track of all of modules. The system assigns a handle to each copy of a running executable or .dll.
The system passes an instance handle to the entry-point function of each executable (see WinMain) and .dll (see DllMain). The executable or .dll assigns this instance handle to the class by copying it to the hInstance member of the WNDCLASSEX structure.
Windows 95/Windows 98/Windows Me: Multiple instances of the same application or .dll use the same code segment, but each has its own data segment. The system uses an instance handle to identify the data segment that corresponds to a particular instance of an application or .dll.
*
-
ja lParam is nurn pointer auf CREATESTRUCT in WM_CREATE du scherznase. denn du ((LPCREATESTRUCT) 0) -> hInstance machst isses klar daß es kracht
-
ok,.
wie würde es richtig sein wenn ich die instance ohne globale variable an meinen constructor übergeben will?
gruß und dank
-
Was für ein Problem hast Du mit einer globalen Variable? Es ist korrekt den Wert zu übergeben, denn Du bei WinMain oder DLLMain mitbekommen hast.
-
Die globale variable ist böse

,... hm ok passt schon,.. danke für den hinweis !

-
Hi,
jetzt habe ich ein linker prob mit der globalen hGlobalInst,denn ich wollte ich die CALLBACK fkt's auslagern, und habe die global variable
so#ifndef GLOBAL_INSTANCE #define GLOBAL_INSTANCE HINSTANCE hGlobalInst; #endifeingebunden, damit der kompiler net meckert,
jetzt hat aber der linker ein problem und gibt aus:wndproc.o: In function
ZSt3minIjERKT\_S2\_S2_': .../wndproc.cpp:(.bss+0x0): multiple definition ofhGlobalInst'
main.o:C:/Dev-Cpp/include/c++/3.4.2/bits/locale_facets.tcc:2493: first defined here
settingsproc.o: In functionZSt3minIjERKT\_S2\_S2_': .../settingsproc.cpp:(.bss+0x0): multiple definition ofhGlobalInst'
main.o:C:/Dev-Cpp/include/c++/3.4.2/bits/locale_facets.tcc:2493: first defined here
collect2: ld returned 1 exit statusich habe jetzt gerade keine idee wie ich das umgehen kann,...
ich nutze mingw 3.4.2
seid gegrüßt
-
Ich kenne Mingw nicht, aber hast Du dasim Header definiert? Dann musst Du extern davor setzen. Und in einer CPP datei die Variable ohne xtern.
-
Ahh, siehste Martin ich hatte noch garnet geantwortet,
jo hat funktioniert, danke
