Partage
  • Partager sur Facebook
  • Partager sur Twitter

undefined reference to `GetOpenFileNameA@4'

Sujet résolu
    6 septembre 2020 à 15:51:22

    Bonjour,

    Je suis en train de suivre un cours de developpez sur l'API win32 mais quand je compile mon code le linker me renvoi une erreur "undefined reference to `GetOpenFileNameA@4'" à la ligne 102  puis "ld returned 1 exit status".

    pourtant j'ai trouve le .h dans lequel la fonction est definie et il est bien inclu.

    mon code:

    #if defined(UNICODE) && !defined(_UNICODE)
        #define _UNICODE
    #elif defined(_UNICODE) && !defined(UNICODE)
        #define UNICODE
    #endif
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <tchar.h>
    #include <windows.h>
    
    #define IDM_QUIT 1
    #define IDM_OPEN 2
    
    LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
    
    HINSTANCE hInst;
    
    WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
        HWND hwnd;
        WNDCLASS wc;
        MSG msg;
        HMENU hMenu, hSousMenu;
    
        hSousMenu = CreateMenu();
        AppendMenu(hSousMenu, MF_STRING, IDM_OPEN, "ouvrir quelque chose...");
        AppendMenu(hSousMenu, MF_SEPARATOR, 0, NULL);
        AppendMenu(hSousMenu, MF_STRING, IDM_QUIT, "partir loin et ne jamais revenir...");
        hMenu = CreateMenu();
        AppendMenu(hMenu, MF_POPUP, (UINT)hSousMenu, "options");
    
        hInst = hinstance;
    
        wc.style = 0;
        wc.lpfnWndProc = MainWndProc;
        wc.cbClsExtra = 0;
        wc.cbWndExtra = 0;
        wc.hInstance = hinstance;
        wc.hIcon = NULL;
        wc.hCursor = LoadCursor(NULL, IDC_ARROW);
        wc.hbrBackground = NULL;
        wc.lpszMenuName = NULL;
        wc.lpszClassName = "MaWinClass";
    
        if (!RegisterClass(&wc))
            return FALSE;
    
        hwnd = CreateWindow("MaWinClass",
                            "le titre",
                            WS_OVERLAPPEDWINDOW,
                            CW_USEDEFAULT,
                            CW_USEDEFAULT,
                            500,
                            500,
                            NULL,
                            hMenu,
                            hinstance,
                            NULL);
        if (!hwnd)
            return FALSE;
    
        ShowWindow(hwnd, nCmdShow);
    
        while (GetMessage(&msg, NULL, 0, 0))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        return 0;
    }
    
    LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
        static HWND hEdit;
        static BOOL textNChange = TRUE;
        switch(uMsg)
        {
            /********** COMMANDES ***********/
            case WM_COMMAND:
    
                if (LOWORD(wParam) == IDM_QUIT)
                {
                    PostMessage(hwnd, WM_CLOSE, 0, 0);
                }
    
                if (LOWORD(wParam) == IDM_OPEN)
                {
                    OPENFILENAME ofn;
                    char szFile[MAX_PATH]={0};
    
                    ZeroMemory(&ofn, sizeof(OPENFILENAME));
    
                    ofn.lStructSize = sizeof(OPENFILENAME);
                    ofn.hwndOwner = hwnd;
                    ofn.lpstrFile = szFile;
                    ofn.nMaxFile = MAX_PATH;
                    ofn.lpstrFilter = "Fichier source C\0* .c\0Header C\0* .h\0Fichier texte\0* .txt\0";
                    ofn.nFilterIndex = 1;
                    ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
    
                    if (GetOpenFileName(&ofn)/*c'est cette fonction qui pose problème*/)
                    {
                        HANDLE hf;
                        DWORD fileSize, nbCharRead;
                        char *buffer;
    
                        hf = CreateFile(szFile, GENERIC_READ, 0, NULL,
                                        OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
                                        NULL);
                        fileSize = GetFileSize(hf, NULL);
                        buffer = (PCHAR)LocalAlloc(LMEM_FIXED, fileSize + 1);
                        ReadFile(hf, buffer, fileSize, &nbCharRead, NULL);
                        buffer[fileSize] = '\0';
    
                        SendMessage(hEdit, WM_SETTEXT, 0, (LPARAM)buffer);
                        LocalFree(buffer);
                        CloseHandle(hf);
                    }
                }
    
                if (HIWORD(wParam) == EN_CHANGE)
                {
                    textNChange = FALSE;
                }
    
                return 0;
    
            /* ********************************** */
    
            case WM_CREATE:
                {
                    hEdit = CreateWindow("edit", "bonjour",
                                         WS_CHILD | WS_VISIBLE | ES_MULTILINE | ES_WANTRETURN | WS_VSCROLL,
                                         0, 0, 0, 0, hwnd, NULL, hInst, NULL);
    
                    return 0;
                }
    
            case WM_SIZE:
                MoveWindow(hEdit, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
                return 0;
    
            case WM_CLOSE:
                if (textNChange || MessageBox(hwnd, "Vous avez modifié le texte.\n Êtes vous sur de vouloir fermer la fenetre?", "s'en aller?", MB_YESNO | MB_ICONQUESTION) == IDYES)
                    DestroyWindow(hwnd);
                return 0;
    
            case WM_DESTROY:
                PostQuitMessage(0);
                return 0;
    
            default:
                return DefWindowProc(hwnd, uMsg, wParam, lParam);
        }
    }
    
    

    est-ce que quelqu'un pourrai m'explique ce qui se passe?

    merci d'avance

    edit: si quelqu’un sait ce que veut dire le @4 après 'GetOpenFileNameA' j'aimerais bien comprendre?

    -
    Edité par Choucroute_melba 6 septembre 2020 à 15:54:57

    • Partager sur Facebook
    • Partager sur Twitter

    Quand il n'y a pas de solution c'est qu'il n'y a pas de problème.

      6 septembre 2020 à 16:03:19

      Bonjour,

      Je pense qu'il faut ajouter dans le linker  libcomdlg32.a  

      • Partager sur Facebook
      • Partager sur Twitter
      Architecture SDL                     Multithreading         
        6 septembre 2020 à 16:10:47

        C'est bien ca c'est parfait merci beaucoup:soleil:
        • Partager sur Facebook
        • Partager sur Twitter

        Quand il n'y a pas de solution c'est qu'il n'y a pas de problème.

          7 septembre 2020 à 11:25:20

          Choucroute_melba a écrit:

          pourtant j'ai trouve le .h dans lequel la fonction est definie et il est bien inclu.

          Tu confonds définition et déclaration.

          Dans les fichier entête .h ce sont les déclarations qu'on y trouvent. Les définitions ce trouvent elles dans les fichiers objets .o ou .obj ou fichier de bibliothèque .a ou .lib  voire bibliothèque dynamique .dll, dans ce cas un .a ou .lib leur sert de bibliothèque d'importation (C'est le cas de ton code).

          • Partager sur Facebook
          • Partager sur Twitter

          undefined reference to `GetOpenFileNameA@4'

          × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
          × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
          • Editeur
          • Markdown