Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. HINSTANCE question

HINSTANCE question

Scheduled Pinned Locked Moved C / C++ / MFC
question
16 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C color Aljechin

    I found it myself. AfxGetInstanceHandle() will get the HINSTANCE of the app. But now LoadStringW(HINSTANCE hInstance, UINT nID, WORD wLanguageID); is returning zero. Why is this function failing? I am passing the correct language ID (1097).

    :rose:

    P Offline
    P Offline
    prasad_som
    wrote on last edited by
    #5

    Aljechin wrote:

    But now LoadStringW(HINSTANCE hInstance, UINT nID, WORD wLanguageID); is returning zero.

    You need to pass value returned by AfxGetResourceHandle as first parameter.

    Prasad Notifier using ATL | Operator new[],delete[][^]

    C 1 Reply Last reply
    0
    • P prasad_som

      Aljechin wrote:

      But now LoadStringW(HINSTANCE hInstance, UINT nID, WORD wLanguageID); is returning zero.

      You need to pass value returned by AfxGetResourceHandle as first parameter.

      Prasad Notifier using ATL | Operator new[],delete[][^]

      C Offline
      C Offline
      color Aljechin
      wrote on last edited by
      #6

      That also didn't work. Here's what I am doing. CString str; int ret; ret = str.LoadStringW((HINSTANCE)AfxGetInstanceHandle(),IDS_STRING102,(WORD)1097); if(ret) MessageBox(str,L"Welcome",MB_ICONINFORMATION); else { DWORD dwErr= GetLastError(); } GetLastError is returning 1815. But i can't find such an error in msdn. Why is this resource loading failing? IDS_STRING102 is an entry in a string table resource. It has the unicode value that must be loaded. If i directly use the unicode string in c++ file, it gets loaded.

      :rose:

      P M 3 Replies Last reply
      0
      • C color Aljechin

        That also didn't work. Here's what I am doing. CString str; int ret; ret = str.LoadStringW((HINSTANCE)AfxGetInstanceHandle(),IDS_STRING102,(WORD)1097); if(ret) MessageBox(str,L"Welcome",MB_ICONINFORMATION); else { DWORD dwErr= GetLastError(); } GetLastError is returning 1815. But i can't find such an error in msdn. Why is this resource loading failing? IDS_STRING102 is an entry in a string table resource. It has the unicode value that must be loaded. If i directly use the unicode string in c++ file, it gets loaded.

        :rose:

        P Offline
        P Offline
        prasad_som
        wrote on last edited by
        #7

        dear, dear. I mentioned AfxGetResourceHandle in my previous post. Update you code like this,

        CString str;
        int ret;
        ret = str.LoadStringW((HINSTANCE)AfxGetResourceHandle(),IDS_STRING102,(WORD)1097);
        if(ret)
        MessageBox(str,L"Welcome",MB_ICONINFORMATION);
        else
        {
        DWORD dwErr= GetLastError();
        }

        And dont know why I was voted 1 for my previous post.

        Prasad Notifier using ATL | Operator new[],delete[][^]

        C 1 Reply Last reply
        0
        • P prasad_som

          dear, dear. I mentioned AfxGetResourceHandle in my previous post. Update you code like this,

          CString str;
          int ret;
          ret = str.LoadStringW((HINSTANCE)AfxGetResourceHandle(),IDS_STRING102,(WORD)1097);
          if(ret)
          MessageBox(str,L"Welcome",MB_ICONINFORMATION);
          else
          {
          DWORD dwErr= GetLastError();
          }

          And dont know why I was voted 1 for my previous post.

          Prasad Notifier using ATL | Operator new[],delete[][^]

          C Offline
          C Offline
          color Aljechin
          wrote on last edited by
          #8

          prasad_som wrote:

          AfxGetResourceHandle

          Yes, in my previous post I told that also didn't work. Actually I edited it two minutes after posting. What could be the problem?

          :rose:

          1 Reply Last reply
          0
          • C color Aljechin

            That also didn't work. Here's what I am doing. CString str; int ret; ret = str.LoadStringW((HINSTANCE)AfxGetInstanceHandle(),IDS_STRING102,(WORD)1097); if(ret) MessageBox(str,L"Welcome",MB_ICONINFORMATION); else { DWORD dwErr= GetLastError(); } GetLastError is returning 1815. But i can't find such an error in msdn. Why is this resource loading failing? IDS_STRING102 is an entry in a string table resource. It has the unicode value that must be loaded. If i directly use the unicode string in c++ file, it gets loaded.

            :rose:

            P Offline
            P Offline
            prasad_som
            wrote on last edited by
            #9

            Aljechin wrote:

            GetLastError is returning 1815

            This error code states, "The specified resource language ID cannot be found in the image file." See if you are going wrong there.

            Prasad Notifier using ATL | Operator new[],delete[][^]

            C 1 Reply Last reply
            0
            • P prasad_som

              Aljechin wrote:

              GetLastError is returning 1815

              This error code states, "The specified resource language ID cannot be found in the image file." See if you are going wrong there.

              Prasad Notifier using ATL | Operator new[],delete[][^]

              C Offline
              C Offline
              color Aljechin
              wrote on last edited by
              #10

              Actually this is the first time I am using Unicode in a string table. It works fine with non unicode strings. There is no error. Is there some special setting that I need to do in that string table or my project for loading the string successfully in runtime? I thank you very much for your time.

              :rose:

              P 1 Reply Last reply
              0
              • C color Aljechin

                Actually this is the first time I am using Unicode in a string table. It works fine with non unicode strings. There is no error. Is there some special setting that I need to do in that string table or my project for loading the string successfully in runtime? I thank you very much for your time.

                :rose:

                P Offline
                P Offline
                prasad_som
                wrote on last edited by
                #11

                I'm not sure. How you are sending last parameter ? i.e. language Id. From error it seems, its not defined in resource file. Is it different from English ? If yes, is it defined in .rc?

                Prasad Notifier using ATL | Operator new[],delete[][^]

                C 2 Replies Last reply
                0
                • C color Aljechin

                  That also didn't work. Here's what I am doing. CString str; int ret; ret = str.LoadStringW((HINSTANCE)AfxGetInstanceHandle(),IDS_STRING102,(WORD)1097); if(ret) MessageBox(str,L"Welcome",MB_ICONINFORMATION); else { DWORD dwErr= GetLastError(); } GetLastError is returning 1815. But i can't find such an error in msdn. Why is this resource loading failing? IDS_STRING102 is an entry in a string table resource. It has the unicode value that must be loaded. If i directly use the unicode string in c++ file, it gets loaded.

                  :rose:

                  M Offline
                  M Offline
                  Mark Salsbery
                  wrote on last edited by
                  #12

                  Are you sure a stringtable entry exists for id "IDS_STRING102" in the language section "1097"? The error indicates it doesn't exist.

                  C 1 Reply Last reply
                  0
                  • P prasad_som

                    I'm not sure. How you are sending last parameter ? i.e. language Id. From error it seems, its not defined in resource file. Is it different from English ? If yes, is it defined in .rc?

                    Prasad Notifier using ATL | Operator new[],delete[][^]

                    C Offline
                    C Offline
                    color Aljechin
                    wrote on last edited by
                    #13

                    prasad_som wrote:

                    How you are sending last parameter ? i.e. language Id.

                    ret = str.LoadStringW((HINSTANCE)AfxGetInstanceHandle(),IDS_STRING102,(WORD)1097); It is unicode and of course different from english. I don't know if its defined in .rc file. How do I do that?

                    :rose:

                    1 Reply Last reply
                    0
                    • P prasad_som

                      I'm not sure. How you are sending last parameter ? i.e. language Id. From error it seems, its not defined in resource file. Is it different from English ? If yes, is it defined in .rc?

                      Prasad Notifier using ATL | Operator new[],delete[][^]

                      C Offline
                      C Offline
                      color Aljechin
                      wrote on last edited by
                      #14

                      prasad_som wrote:

                      How you are sending last parameter ? i.e. language Id.

                      ret = str.LoadStringW((HINSTANCE)AfxGetInstanceHandle(),IDS_STRING102,(WORD)1097); It's of course not english. I don't know if its defined in .rc. How do I do that?

                      :rose:

                      1 Reply Last reply
                      0
                      • M Mark Salsbery

                        Are you sure a stringtable entry exists for id "IDS_STRING102" in the language section "1097"? The error indicates it doesn't exist.

                        C Offline
                        C Offline
                        color Aljechin
                        wrote on last edited by
                        #15

                        Mark Salsbery wrote:

                        in the language section "1097"?

                        I think I need to check out that. What is the language section? the string IDS_STRING102 does exist in stringtable and the value of that is a unicode string. If i put a non unicode string, it gets loaded.

                        :rose:

                        M 1 Reply Last reply
                        0
                        • C color Aljechin

                          Mark Salsbery wrote:

                          in the language section "1097"?

                          I think I need to check out that. What is the language section? the string IDS_STRING102 does exist in stringtable and the value of that is a unicode string. If i put a non unicode string, it gets loaded.

                          :rose:

                          M Offline
                          M Offline
                          Mark Salsbery
                          wrote on last edited by
                          #16

                          The STRINGTABLE resource has a LANGUAGE option but apparently tha's not the problem if it works for a non-unicode string table entry.

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups