Linker problem with PSDK

Hi All,

I am by no means an experienced programmer, but have taken interrest in C++. I have tried to create a program that should remote control two or more other applications. I am trying to use FindWindow() to get me the handles of the desired applications.
At first I had some (trivial) problems with the LPCTSTR, since I am not that good with pointers. If someone can find it in their hearts to explain a little pointer practices for me, I would appreciate it.
Well I managed to compile without getting any compiler errors, but now I get some linker errors that I do not know how to overcome.

RemoteELS.obj: error LNK2028: unresolved token (0A00000E) "extern "C" struct HWND__ * __stdcall FindWindowW(wchar_t const *,wchar_t const *)" ( FindWindowW@@$$J18YGPAUHWND__@@PB_W0@Z) referenced in function "private: void __clrcall RemoteELS::Form1::Form1_Initialized(class System::Object ^,class System::EventArgs ^)" ( Form1_Initialized@Form1@RemoteELS@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)

RemoteELS.obj : error LNK2019: unresolved external symbol "extern "C" struct HWND__ * __stdcall FindWindowW(wchar_t const *,wchar_t const *)" ( FindWindowW@@$$J18YGPAUHWND__@@PB_W0@Z) referenced in function "private: void __clrcall RemoteELS::Form1::Form1_Initialized(class System::Object ^,class System::EventArgs ^)" ( Form1_Initialized@Form1@RemoteELS@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)

What am I doing wrong please
Is it because my program is C++ and not C

Thanks in advance.




Answer this question

Linker problem with PSDK

  • Ujjwal Shrestha

    Can you please post the error you are seeing with a small stand alone sample reproducing the issue

    Thanks,
      Ayman Shoukry
      VC++ Team

  • gmpdx

    Hi Again,

    I managed to fix the problem by adding user32.lib in the additional dependancies.
    I now just need to understand the LPCTSTR problem I have.

    I wish to use a variable as a placeholder of the window name and pass it to FindWindow like this:

    if (hwnd_app = FindWindow(NULL, LPCTSTR(m_strAppName)))

    So far I have managed to assign a value to m_str_AppName at the initialisation like this:

    char m_strAppName[255] = "Application";

    but if I try to reassign it in the code like this:

    m_str AppName = "Something_Else";

    I get a conversion errer of the compiler.

    As I stated earlier, I am new to programming, and what I do program I do seldomly. How can I handle this neatly please

    Thanks.



  • Matt Hollingsworth

    I assume you have Visual C++ Express...

    You probably missed a step when you installed the PSDK, and thus the Platform SDK wasn't installed properly. The complete install process is located in http://msdn.microsoft.com/vstudio/express/visualc/usingpsdk/default.aspx (If you forget to perform step 4, you'll get linker errors such as the one you mentioned).

    instead of doing:

    char m_strApplicationName[255]="Application";
    m_strApplicationName = "Something Else";
    if(hwnd_app = FindWindow(NULL, LPCTSTR(m_strApplicationName)))

    try:

    std::string m_strApplicationName="Application";
    m_strApplicationName = "Something Else";
    if(hwnd_app = FindWindow(NULL, m_strApplicationName.c_str()))

    (also make sure you #include<string> at the top of your file).


  • Daniel F.

    Just in case you are wondering why you need to do all these weird things for strings, there is no native handling of a string type in C/C++. There are utility functions written for it, and also as was pointed out, the string class in the stl.
    What method you use to handle strings is up to you, but learning how to handle them is a good idea.
    Another problem which you seemed to have mentioned is the use of tchar functions and types. The important thing to remember about these is they are not types on their own, they are aliases for other types depending on if you have Unicode set or not. With Unicode set LPTSTR = LPWSTR = wchar_t*. When Unicode is not set, LPTSTR = LPSTR = char*.
    Some things which you may find helpful to look at.

    CRT string routines.
    http://msdn.microsoft.com/library/en-us/vclib/html/_crt_string_manipulation.asp

    CRT overview.
    http://msdn.microsoft.com/library/en-us/vclib/html/vcrefRunTimeLibraryReference.asp

    STL string.
    http://msdn.microsoft.com/library/en-us/vcstdlib/html/vclrf_string_header.asp

    STL overview.
    http://msdn.microsoft.com/library/en-us/vcstdlib/html/vcoriStandardCLibraryReference.asp



  • Emile Bosch

    This is a C# forum. Perhaps you should consider posting to the C++ forum instead.

    You can use the CRT strncpy function or the Windows API lstrcpyn to change the value of m_strAppName.



  • Linker problem with PSDK