首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >链接器错误,未定义引用

链接器错误,未定义引用
EN

Stack Overflow用户
提问于 2015-01-20 01:56:55
回答 1查看 369关注 0票数 0

我是一个绝对的初学者。这是我的第一个C++代码。取自Dev C++中的默认项目、youtube教程和一些直觉,我想出了下面的简单代码。我知道答案会很简单。我似乎不能把其他帖子的答案粘贴在一起来修复我的问题。非常感谢您提供的任何帮助!

我收到“未定义的对CreateProcessWithLogonW的引用”错误。

代码语言:javascript
复制
#include <windows.h>


/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

HWND textfield;


/* Make the class name into a global variable */
char szClassName[ ] = "WindowsApp";

int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)

{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */

/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);

/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default color as the background of the window */
wincl.hbrBackground = GetSysColorBrush (COLOR_3DFACE);

/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;

/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"Files open on Mars",/* Title Text */
WS_SYSMENU, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
444, /* The programs width */
175, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);

/* Make the window visible on the screen */
ShowWindow (hwnd, nFunsterStil);

/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}

/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}


/* This function is called by the Windows function DispatchMessage() */

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) /* handle the messages */
{

case WM_CREATE:

CreateWindow(TEXT("button"), TEXT("Open files"),
WS_VISIBLE | WS_CHILD,
10,10,80,25,
hwnd, (HMENU) 1, NULL, NULL
);

textfield = CreateWindow("STATIC",
"Please click the button to retrieve a list of open files on server",
WS_VISIBLE | WS_CHILD,
10,50,400,25, hwnd, NULL, NULL, NULL); 

textfield = CreateWindow("STATIC",
"Message at bottom of box",
WS_VISIBLE | WS_CHILD,
10,120,400,25, hwnd, NULL, NULL, NULL); 

break;

case WM_COMMAND:

if (LOWORD(wParam) == 1) {


CreateProcessWithLogonW(L"me", L"company", L"xxxxxx", 0, 0, L"c:\\files.cmd", 0, NULL, NULL, NULL, NULL); 
MessageBox(hwnd, "A text file with all of the open files has been placed on your desktop", "Open Files", MB_OK | MB_ICONINFORMATION);

}



break;

case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}

return 0;
}
EN

回答 1

Stack Overflow用户

发布于 2015-01-20 01:59:04

根据documentationCreateProcessWithLogonW是在Advapi32.lib中定义的。您需要将该库传递给链接器。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28030797

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档