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. Error in runtime Dll linking?

Error in runtime Dll linking?

Scheduled Pinned Locked Moved C / C++ / MFC
questiontestingbeta-testinghelp
6 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.
  • M Offline
    M Offline
    mvworld
    wrote on last edited by
    #1

    Hi, I have been trying to use run time linking with Dll files. I am new to Windows programming, so I am confused what is causing the error in my program. I am trying to use run time linking to change the Window Title of a Console widow. Here is the code: #include typedef BOOL (WINAPI *LPFNDLLFUNC) (HINSTANCE hInstance, char *dwText); void main() { HINSTANCE hLibrary; LPFNDLLFUNC lpfnDllFunc; BOOL RetVal; char dwString[] = "Changed Text"; HWND hwnd; char pszWindowTitle[40]; GetConsoleTitle(pszWindowTitle, 40); hwnd = FindWindow(NULL, pszWindowTitle); hLibrary = LoadLibrary("USER32.DLL"); lpfnDllFunc = (LPFNDLLFUNC) GetProcAddress(hLibrary, "SetWindowText"); RetVal = lpfnDllFunc(hLibrary, dwString); } It compiles and links fine, but it performs an illegal operation on running it. On debugging I get the following message: Unhandeled exception in Testing.exe:OxC0000005:Access Violation Any ideas?

    M M L 3 Replies Last reply
    0
    • M mvworld

      Hi, I have been trying to use run time linking with Dll files. I am new to Windows programming, so I am confused what is causing the error in my program. I am trying to use run time linking to change the Window Title of a Console widow. Here is the code: #include typedef BOOL (WINAPI *LPFNDLLFUNC) (HINSTANCE hInstance, char *dwText); void main() { HINSTANCE hLibrary; LPFNDLLFUNC lpfnDllFunc; BOOL RetVal; char dwString[] = "Changed Text"; HWND hwnd; char pszWindowTitle[40]; GetConsoleTitle(pszWindowTitle, 40); hwnd = FindWindow(NULL, pszWindowTitle); hLibrary = LoadLibrary("USER32.DLL"); lpfnDllFunc = (LPFNDLLFUNC) GetProcAddress(hLibrary, "SetWindowText"); RetVal = lpfnDllFunc(hLibrary, dwString); } It compiles and links fine, but it performs an illegal operation on running it. On debugging I get the following message: Unhandeled exception in Testing.exe:OxC0000005:Access Violation Any ideas?

      M Offline
      M Offline
      Masaaki Onishi
      wrote on last edited by
      #2

      Hello, the codegurus around the world;) First of all, I don't know the exact answer, but have you ever written C or C++ code?:confused: >> I am new to Windows programming. So, you know C? I mean, why don't you use if-else statement to check if the function returns the right value. 1) Check if FindWindow works fine? 2) If 1) works, go to 3) 3) Check if LoadLibrary works fine? 4) If 3) works, go to 4) 5) Check if GetProcAddress works fine? 6) If 5) works, go t 7) 7) Try to use SetWidnowText(...) I think that any programmer needs this kind of approaches even though we use Java or C++. Anyway, I think that SetWindowText's first arguement passes HWND, not HINSTANCE?:confused: Have a nice day! -Masaaki Onishi-

      1 Reply Last reply
      0
      • M mvworld

        Hi, I have been trying to use run time linking with Dll files. I am new to Windows programming, so I am confused what is causing the error in my program. I am trying to use run time linking to change the Window Title of a Console widow. Here is the code: #include typedef BOOL (WINAPI *LPFNDLLFUNC) (HINSTANCE hInstance, char *dwText); void main() { HINSTANCE hLibrary; LPFNDLLFUNC lpfnDllFunc; BOOL RetVal; char dwString[] = "Changed Text"; HWND hwnd; char pszWindowTitle[40]; GetConsoleTitle(pszWindowTitle, 40); hwnd = FindWindow(NULL, pszWindowTitle); hLibrary = LoadLibrary("USER32.DLL"); lpfnDllFunc = (LPFNDLLFUNC) GetProcAddress(hLibrary, "SetWindowText"); RetVal = lpfnDllFunc(hLibrary, dwString); } It compiles and links fine, but it performs an illegal operation on running it. On debugging I get the following message: Unhandeled exception in Testing.exe:OxC0000005:Access Violation Any ideas?

        M Offline
        M Offline
        Michael Dunn
        wrote on last edited by
        #3

        Have you traced through the code yet? You'll see that lpfnDllFunc is NULL. That's because there is no function "SetWindowText". There are "SetWindowTextA" and "SetWindowTextW" for ANSI and Unicode, respectively. Your code is using plain chars, so use the ANSI version. --Mike-- http://home.inreach.com/mdunn/ The Signature, back by popular demand: Buffy. Pajamas.

        M 1 Reply Last reply
        0
        • M Michael Dunn

          Have you traced through the code yet? You'll see that lpfnDllFunc is NULL. That's because there is no function "SetWindowText". There are "SetWindowTextA" and "SetWindowTextW" for ANSI and Unicode, respectively. Your code is using plain chars, so use the ANSI version. --Mike-- http://home.inreach.com/mdunn/ The Signature, back by popular demand: Buffy. Pajamas.

          M Offline
          M Offline
          mvworld
          wrote on last edited by
          #4

          Hi mate, Yeah I took note of it, just careless mistake I suppose. Thanks a ton though :)

          1 Reply Last reply
          0
          • M mvworld

            Hi, I have been trying to use run time linking with Dll files. I am new to Windows programming, so I am confused what is causing the error in my program. I am trying to use run time linking to change the Window Title of a Console widow. Here is the code: #include typedef BOOL (WINAPI *LPFNDLLFUNC) (HINSTANCE hInstance, char *dwText); void main() { HINSTANCE hLibrary; LPFNDLLFUNC lpfnDllFunc; BOOL RetVal; char dwString[] = "Changed Text"; HWND hwnd; char pszWindowTitle[40]; GetConsoleTitle(pszWindowTitle, 40); hwnd = FindWindow(NULL, pszWindowTitle); hLibrary = LoadLibrary("USER32.DLL"); lpfnDllFunc = (LPFNDLLFUNC) GetProcAddress(hLibrary, "SetWindowText"); RetVal = lpfnDllFunc(hLibrary, dwString); } It compiles and links fine, but it performs an illegal operation on running it. On debugging I get the following message: Unhandeled exception in Testing.exe:OxC0000005:Access Violation Any ideas?

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            FindWindow(A/W) and SetWindowText(A/W) both lives in user32.dll. If you are using FindWindow using static link, why do you need runtime linking for SetWindowText? :confused:

            M 1 Reply Last reply
            0
            • L Lost User

              FindWindow(A/W) and SetWindowText(A/W) both lives in user32.dll. If you are using FindWindow using static link, why do you need runtime linking for SetWindowText? :confused:

              M Offline
              M Offline
              mvworld
              wrote on last edited by
              #6

              This problem is a part of a larger study problem I have for my college project. I am basically experimenting with all the calling conventions etc...and this will finally be used in code for XEmacs, which is a unix originated text editor. :)

              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