0

After some struggling with an app that displays the time in a label when a button is pressed, it have finally come down to a linker error.

The line of code wich is causing this is:

_wstrdate(dateStr);

The faults is:

error LNK2019: unresolved external symbol _wstrdate referenced in function "long __cdecl WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YAJPAUHWND__@@IIJ@Z)
fatal error LNK1120: 1 unresolved externals

I was told to post my WNDPROC & linker settings here:

  LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;

static HWND hButton;
static HWND hLabel;
static SHACTIVATEINFO s_sai;

switch (message) 
{
    case WM_COMMAND:
        wmId    = LOWORD(wParam); 
        wmEvent = HIWORD(wParam); 
        // Parse the menu selections:
        switch (wmId)
        {
            case IDM_HELP_ABOUT:
                DialogBox(g_hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, About);
                break;
 #ifdef WIN32_PLATFORM_PSPC
            case IDM_OK:
                SendMessage (hWnd, WM_CLOSE, 0, 0);             
                break;

            case 1001:
            {



                _wstrdate(dateStr);

                SetDlgItemTextW(hWnd, 1003, dateStr);


                break;
            }

#endif // WIN32_PLATFORM_PSPC
            default:
                return DefWindowProc(hWnd, message, wParam, lParam);
        }
        break;
    case WM_CREATE:
#ifdef SHELL_AYGSHELL
        SHMENUBARINFO mbi;

        memset(&mbi, 0, sizeof(SHMENUBARINFO));
        mbi.cbSize     = sizeof(SHMENUBARINFO);
        mbi.hwndParent = hWnd;
        mbi.nToolBarId = IDR_MENU;
        mbi.hInstRes   = g_hInst;

        hButton = CreateWindow( L"button",L"Time",
            WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON,
            100,200,
            50,20,
            hWnd, (HMENU) MEDDELANDEBUTTON_ID,
             NULL, NULL);



        hLabel = CreateWindowW(L"STATIC",L"Time",
        WS_VISIBLE | WS_CHILD | SS_RIGHT,
        10,200,75,35,hWnd, (HMENU)1003, NULL, NULL);





        if (!SHCreateMenuBar(&mbi)) 
        {
            g_hWndMenuBar = NULL;
        }
        else
        {
            g_hWndMenuBar = mbi.hwndMB;
        }

        // Initialize the shell activate info structure
        memset(&s_sai, 0, sizeof (s_sai));
        s_sai.cbSize = sizeof (s_sai);
#endif // SHELL_AYGSHELL
        break;
    case WM_PAINT:
        hdc = BeginPaint(hWnd, &ps);

        // TODO: Add any drawing code here...

        EndPaint(hWnd, &ps);
        break;
    case WM_DESTROY:
 #ifdef SHELL_AYGSHELL
        CommandBar_Destroy(g_hWndMenuBar);
 #endif // SHELL_AYGSHELL
        PostQuitMessage(0);
        break;

    case WM_ACTIVATE:
        // Notify shell of our activate message
        SHHandleWMActivate(hWnd, wParam, lParam, &s_sai, FALSE);
        break;
    case WM_SETTINGCHANGE:
        SHHandleWMSettingChange(hWnd, wParam, lParam, &s_sai);
        break;

    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}

Also here is my linker options: (Standard visualstudio 2008)

/OUT:"Pocket PC 2003 (ARMV4)  \Debug/c++pocketpc.exe" /INCREMENTAL /NOLOGO /MANIFEST:NO /NODEFAULTLIB:"oldnames.lib" /DEBUG /PDB:"Pocket PC 2003 (ARMV4)\Debug/c++pocketpc.pdb" /STACK:65536,4096 /DYNAMICBASE:NO /ERRORREPORT:PROMPT coredll.lib corelibc.lib ole32.lib oleaut32.lib uuid.lib commctrl.lib
4

1 回答 1

0

Control.WinProc上的 Microsoft 页面,

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

所以,你在那里。

但是,在.NET Framework Security下,我看到

  • SecurityPermission 用于继承类以调用非托管代码。关联枚举:SecurityPermissionFlag.UnmanagedCode。

  • 直接调用者调用非托管代码的 SecurityPermission。关联枚举:SecurityPermissionFlag.UnmanagedCode。

因此,看起来您可能必须将代码包装在不安全的块中。我认为你已经这样做了。

我在_wstrdate上找到的信息在代码示例中有这个:

// 注意:_strdate 已弃用;考虑改用 _strdate_s

.NET Framework Equivalent部分提供了System::DateTime::Parse的链接,因此您可以通过尝试获得好的结果。

希望这可以帮助。

于 2013-08-15T14:32:47.463 回答