Exe reste en mémoire (WIN32)

Résolu
cs_Urgo Messages postés 780 Date d'inscription lundi 16 décembre 2002 Statut Membre Dernière intervention 16 avril 2009 - 3 juil. 2005 à 22:00
cs_Urgo Messages postés 780 Date d'inscription lundi 16 décembre 2002 Statut Membre Dernière intervention 16 avril 2009 - 3 juil. 2005 à 22:10
Bonsoir à tous,

j'ai encore un soucis lié à la suppression de l'utilisation de la CRT, en indiquant un point d'entrée perso au linker.



Je travaille sous XP et VS 2003, et lorsque je ferme mon exe compilé
avec l'option /ENTRY, celui-ci reste en mémoire, je dois le fermer avec
Ctrl+Alt+Supp, or sans cette dite option, tout fonctionne...



Voici le code incriminé :



#define _WIN32_WINNT 0x0500

#include <windows.h>



#define IDM_OPEN 40001



HINSTANCE hInst;

HWND hMain, hOpen;

char szFile[MAX_PATH];

char *szAppName = "Test";



int dlgSelectBitmap(HWND hOwner)

{

OPENFILENAME ofn;

ofn.lStructSize = sizeof(OPENFILENAME);

ofn.hInstance 0; ofn.hwndOwner hOwner;

ofn.lpstrFilter = "BITMAP(*.bmp)\0*.bmp\0\0";

ofn.lpstrFile = szFile;

ofn.lpstrCustomFilter ofn.lpstrFileTitle 0;

ofn.nFileExtension ofn.nFileOffset 0;

ofn.lCustData ofn.dwReserved 0;

ofn.lpTemplateName ofn.lpstrInitialDir ofn.lpstrDefExt = 0;

ofn.lpfnHook 0; ofn.pvReserved 0;

ofn.nMaxCustFilter ofn.nMaxFileTitle 0;

ofn.FlagsEx = 0;

ofn.nFilterIndex 1; ofn.nMaxFile MAX_PATH;

ofn.lpstrTitle = "Ouvrir un bitmap";

ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_DONTADDTORECENT;

szFile[0] = 0;

return GetOpenFileName(&ofn);

}



LRESULT CALLBACK AppWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)

{

switch(uMsg) {

case WM_CREATE:

hOpen = CreateWindow("BUTTON", "Ouvrir", WS_CHILD | WS_VISIBLE,



8, 8,
100, 30, hWnd, (HMENU)IDM_OPEN, hInst, 0);

return 0;

case WM_COMMAND:

if(LOWORD(wParam) == IDM_OPEN)

dlgSelectBitmap(hWnd);

return 0;

case WM_DESTROY:

PostQuitMessage(0); return 0;

}

return DefWindowProc(hWnd, uMsg, wParam, lParam);

}



int InitInstance()

{

WNDCLASSEX wclsx;

wclsx.cbSize = sizeof(WNDCLASSEX);

wclsx.style = 0;

wclsx.lpfnWndProc = AppWndProc;

wclsx.cbClsExtra wclsx.cbWndExtra 0;

wclsx.hInstance = hInst;

wclsx.hIcon = LoadIcon(0, IDI_APPLICATION);

wclsx.hCursor = LoadCursor(0, IDC_ARROW);

wclsx.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);

wclsx.lpszMenuName = 0;

wclsx.lpszClassName = szAppName;

wclsx.hIconSm = 0;

if(!RegisterClassEx(&wclsx)) return 0;

hMain = CreateWindowEx(0, szAppName, szAppName, WS_OVERLAPPEDWINDOW | WS_VISIBLE,




CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,




0, 0, hInst,
0);

return (hMain != 0);

}



#pragma comment(linker, "/entry:myWinMain")

int __stdcall myWinMain()

//int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int lpCmdShow)

{

MSG msg;

hInst = GetModuleHandle(0);

if(!InitInstance()) return 0;

ShowWindow(hMain, SW_SHOW);

while(GetMessage(&msg, NULL, 0, 0)) {

TranslateMessage(&msg);

DispatchMessage(&msg);

}

return 0;

}



Cela fait quelque temps que je me casse la tête à résoudre ce problème sans succès...



Ciao
Urgo

3 réponses

BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019
3 juil. 2005 à 22:04
ExitProcess(0) au lieu de return 0, ça forcera le déchargement.

ciao...
BruNews, MVP VC++
3
cs_Urgo Messages postés 780 Date d'inscription lundi 16 décembre 2002 Statut Membre Dernière intervention 16 avril 2009 1
3 juil. 2005 à 22:02
J'oublais, d'après ce que j'ai pu constater, le problème viendrait de GetOpenFileName(&ofn)...

Urgo
0
cs_Urgo Messages postés 780 Date d'inscription lundi 16 décembre 2002 Statut Membre Dernière intervention 16 avril 2009 1
3 juil. 2005 à 22:10
En effet...

Merci encore une fois! :)

Urgo
0
Rejoignez-nous