Reference User32.lib
-
I'm trying to learn c++ and I just spent some time trying to use GetWindowText(). I was getting a linker error for unresolved token LNK2028, LNK2019. I finally added "C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Lib\User32.lib" path to Project->Properties->Linker->Input and it worked. But I have two questions for anyone who may know so that I may understand a little better. And maybe someone else can use this later, too. .NET 2008 C++, WinXP Home 1) Why did I have to that? I kept telling myself the dll was already referenced and I had the "windows.h" #include going on. Everything looked correct (as far as my understanding goes (not far)). The code is in a normal CLR project, .NET Form button_click (so it must be using User32.dll already, right?). If you check the Linker->Input Additional Dependencies it shows User32.lib in "Inherited Values" along with all of the other Windows libraries. So I assumed I didn't have to add it. 2) It may have worked but did I do it 'right'? I ran a search on my drive for user32.lib (I expected it in C:\WINDOWS somewhere but it was in the path listed above. Should I move it? There are others in "C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib" and the like. Thanks.
-
I'm trying to learn c++ and I just spent some time trying to use GetWindowText(). I was getting a linker error for unresolved token LNK2028, LNK2019. I finally added "C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Lib\User32.lib" path to Project->Properties->Linker->Input and it worked. But I have two questions for anyone who may know so that I may understand a little better. And maybe someone else can use this later, too. .NET 2008 C++, WinXP Home 1) Why did I have to that? I kept telling myself the dll was already referenced and I had the "windows.h" #include going on. Everything looked correct (as far as my understanding goes (not far)). The code is in a normal CLR project, .NET Form button_click (so it must be using User32.dll already, right?). If you check the Linker->Input Additional Dependencies it shows User32.lib in "Inherited Values" along with all of the other Windows libraries. So I assumed I didn't have to add it. 2) It may have worked but did I do it 'right'? I ran a search on my drive for user32.lib (I expected it in C:\WINDOWS somewhere but it was in the path listed above. Should I move it? There are others in "C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib" and the like. Thanks.
thenutz72 wrote:
Why did I have to that? I kept telling myself the dll was already referenced and I had the "windows.h" #include going on.
windows.h has nothing to do with the linker. It's the import library you were missing that the linker needed.
thenutz72 wrote:
The code is in a normal CLR project, .NET Form button_click (so it must be using User32.dll already, right?).
No. The .NET framework may use user32.dll internally but that has nothing to do with your project.
thenutz72 wrote:
It may have worked but did I do it 'right'?
Not necessarily. If you're using native code from a managed class' code, the you would use platform invoke: Using Explicit PInvoke in C++ (DllImport Attribute)[^] You shouldn't be mixing paths to different SDKs. If you're using the Visual Studio IDE for your project, then use its directories settings to configure paths to the ONE SDK you want to use. Then you don't need paths in all your project configurations unless you need to override something. Learning C++/CLI is a pretty big undertaking for a beginner in C++... Are you sure you don't want to get familiar with the C++ language before adding the complexity of the managed world? All your questions are fundamentals you should know :)
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
thenutz72 wrote:
Why did I have to that? I kept telling myself the dll was already referenced and I had the "windows.h" #include going on.
windows.h has nothing to do with the linker. It's the import library you were missing that the linker needed.
thenutz72 wrote:
The code is in a normal CLR project, .NET Form button_click (so it must be using User32.dll already, right?).
No. The .NET framework may use user32.dll internally but that has nothing to do with your project.
thenutz72 wrote:
It may have worked but did I do it 'right'?
Not necessarily. If you're using native code from a managed class' code, the you would use platform invoke: Using Explicit PInvoke in C++ (DllImport Attribute)[^] You shouldn't be mixing paths to different SDKs. If you're using the Visual Studio IDE for your project, then use its directories settings to configure paths to the ONE SDK you want to use. Then you don't need paths in all your project configurations unless you need to override something. Learning C++/CLI is a pretty big undertaking for a beginner in C++... Are you sure you don't want to get familiar with the C++ language before adding the complexity of the managed world? All your questions are fundamentals you should know :)
Mark Salsbery Microsoft MVP - Visual C++ :java: