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. Typecasting

Typecasting

Scheduled Pinned Locked Moved C / C++ / MFC
helpcsharpvisual-studio
6 Posts 6 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.
  • S Offline
    S Offline
    siddharthsan
    wrote on last edited by
    #1

    :((Hi, I am using Visual studio 2005 for my application. In my application,Loadlibrary is used, LoadLibrary("library.dll"); If i simply give like this, it's showing error as "cannot convert parameter 1 from const char to LPCWSTR",so i typecasted it as, LoadLibrary(_T("library.dll")) or LoadLibrary((LPCWSTR)"library.dll")) if i give like this it is not taking or recognizing the library gives error as No such lib found. Please I need help... Siddharth

    N N M D S 5 Replies Last reply
    0
    • S siddharthsan

      :((Hi, I am using Visual studio 2005 for my application. In my application,Loadlibrary is used, LoadLibrary("library.dll"); If i simply give like this, it's showing error as "cannot convert parameter 1 from const char to LPCWSTR",so i typecasted it as, LoadLibrary(_T("library.dll")) or LoadLibrary((LPCWSTR)"library.dll")) if i give like this it is not taking or recognizing the library gives error as No such lib found. Please I need help... Siddharth

      N Offline
      N Offline
      Naveen
      wrote on last edited by
      #2

      siddharthsan wrote:

      "cannot convert parameter 1 from const char to LPCWSTR",

      This is because in your project setting the _UNICODE is defined. So you must specify unicode string like LoadLibrary(_T("library.dll")) or LoadLibrary(L"library.dll").

      siddharthsan wrote:

      LoadLibrary((LPCWSTR)"library.dll"))

      This is not the corrcect way. This casting dosent make the string unicode.

      siddharthsan wrote:

      library gives error as No such lib found.

      This error may be because the dll is not in the path. try 1.Give full path of the dll in that function. 2.Add the path of the dll into the "PATH" environment variable. Restart msdev after this and try

      nave

      1 Reply Last reply
      0
      • S siddharthsan

        :((Hi, I am using Visual studio 2005 for my application. In my application,Loadlibrary is used, LoadLibrary("library.dll"); If i simply give like this, it's showing error as "cannot convert parameter 1 from const char to LPCWSTR",so i typecasted it as, LoadLibrary(_T("library.dll")) or LoadLibrary((LPCWSTR)"library.dll")) if i give like this it is not taking or recognizing the library gives error as No such lib found. Please I need help... Siddharth

        N Offline
        N Offline
        Nibu babu thomas
        wrote on last edited by
        #3

        siddharthsan wrote:

        If i simply give like this, it's showing error as "cannot convert parameter 1 from const char to LPCWSTR",so i typecasted it as, LoadLibrary(_T("library.dll")) or LoadLibrary((LPCWSTR)"library.dll"))

        So the compiler is wrong and and you are making it listen by casting, right!! :|


        Nibu thomas A Developer Code must be written to be read, not by the compiler, but by another human being. http:\\nibuthomas.wordpress.com

        1 Reply Last reply
        0
        • S siddharthsan

          :((Hi, I am using Visual studio 2005 for my application. In my application,Loadlibrary is used, LoadLibrary("library.dll"); If i simply give like this, it's showing error as "cannot convert parameter 1 from const char to LPCWSTR",so i typecasted it as, LoadLibrary(_T("library.dll")) or LoadLibrary((LPCWSTR)"library.dll")) if i give like this it is not taking or recognizing the library gives error as No such lib found. Please I need help... Siddharth

          M Offline
          M Offline
          Matthew Faithfull
          wrote on last edited by
          #4

          Siddharth, Have you tried using LoadLibraryA("library.dll")? Your project is clearly set to use UNICODE by default and the API headers are defining LoadLibrary as LoadLibraryW. This is a bit of a strange one, I've never been quite sure what happens if you try to load a dll with the name in UNICODE (wide characters).:confused: Note: ((LPCWSTR)"library.dll") will never work as this just casts the pointer to narrow string to a pointer to wide string but doesn't change the string:wtf: If LoadLibraryA does not work then I guess it just can't find your dll. Is it in the normal search path, i.e. same dir as exe or Windows\System32 or somewhere mentioned in the PATH environemnt variable?

          Nothing is exactly what it seems but everything with seems can be unpicked.

          1 Reply Last reply
          0
          • S siddharthsan

            :((Hi, I am using Visual studio 2005 for my application. In my application,Loadlibrary is used, LoadLibrary("library.dll"); If i simply give like this, it's showing error as "cannot convert parameter 1 from const char to LPCWSTR",so i typecasted it as, LoadLibrary(_T("library.dll")) or LoadLibrary((LPCWSTR)"library.dll")) if i give like this it is not taking or recognizing the library gives error as No such lib found. Please I need help... Siddharth

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            siddharthsan wrote:

            LoadLibrary((LPCWSTR)"library.dll")) if i give like this it is not taking or recognizing the library gives error as No such lib found.

            Try a fully-qualified path.


            "A good athlete is the result of a good and worthy opponent." - David Crow

            "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

            1 Reply Last reply
            0
            • S siddharthsan

              :((Hi, I am using Visual studio 2005 for my application. In my application,Loadlibrary is used, LoadLibrary("library.dll"); If i simply give like this, it's showing error as "cannot convert parameter 1 from const char to LPCWSTR",so i typecasted it as, LoadLibrary(_T("library.dll")) or LoadLibrary((LPCWSTR)"library.dll")) if i give like this it is not taking or recognizing the library gives error as No such lib found. Please I need help... Siddharth

              S Offline
              S Offline
              Stephen Hewitt
              wrote on last edited by
              #6

              siddharthsan wrote:

              LoadLibrary((LPCWSTR)"library.dll"))

              This is wrong. If you get into the habbit of using static_cast instead of C-style casts this kind of mistake will produce compiler errors instead of runtime errors.

              Steve

              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